diff options
author | Yu Ke <ke.yu@intel.com> | 2011-01-10 14:23:36 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-01-10 14:23:36 +0000 |
commit | 4dccd92439f3b21056c53f2317249228067defe6 (patch) | |
tree | b5507598213381b870f53b3f816102b0b2899b86 /bitbake/lib/bb/fetch2/cvs.py | |
parent | f46cdcbbae0ac3cbce423d262358e670add6065e (diff) | |
download | poky-4dccd92439f3b21056c53f2317249228067defe6.tar.gz |
bitbake: copy bb.fetch to bb.fetch2 as initial code base for fetcher overhaul
Signed-off-by: Yu Ke <ke.yu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/cvs.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/cvs.py | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/cvs.py b/bitbake/lib/bb/fetch2/cvs.py new file mode 100644 index 0000000000..0edb794b04 --- /dev/null +++ b/bitbake/lib/bb/fetch2/cvs.py | |||
@@ -0,0 +1,172 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | """ | ||
4 | BitBake 'Fetch' implementations | ||
5 | |||
6 | Classes for obtaining upstream sources for the | ||
7 | BitBake build tools. | ||
8 | |||
9 | """ | ||
10 | |||
11 | # Copyright (C) 2003, 2004 Chris Larson | ||
12 | # | ||
13 | # This program is free software; you can redistribute it and/or modify | ||
14 | # it under the terms of the GNU General Public License version 2 as | ||
15 | # published by the Free Software Foundation. | ||
16 | # | ||
17 | # This program is distributed in the hope that it will be useful, | ||
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | # GNU General Public License for more details. | ||
21 | # | ||
22 | # You should have received a copy of the GNU General Public License along | ||
23 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
24 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
25 | # | ||
26 | #Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
27 | # | ||
28 | |||
29 | import os | ||
30 | import logging | ||
31 | import bb | ||
32 | from bb import data | ||
33 | from bb.fetch import Fetch, FetchError, MissingParameterError, logger | ||
34 | |||
35 | class Cvs(Fetch): | ||
36 | """ | ||
37 | Class to fetch a module or modules from cvs repositories | ||
38 | """ | ||
39 | def supports(self, url, ud, d): | ||
40 | """ | ||
41 | Check to see if a given url can be fetched with cvs. | ||
42 | """ | ||
43 | return ud.type in ['cvs'] | ||
44 | |||
45 | def localpath(self, url, ud, d): | ||
46 | if not "module" in ud.parm: | ||
47 | raise MissingParameterError("cvs method needs a 'module' parameter") | ||
48 | ud.module = ud.parm["module"] | ||
49 | |||
50 | ud.tag = ud.parm.get('tag', "") | ||
51 | |||
52 | # Override the default date in certain cases | ||
53 | if 'date' in ud.parm: | ||
54 | ud.date = ud.parm['date'] | ||
55 | elif ud.tag: | ||
56 | ud.date = "" | ||
57 | |||
58 | norecurse = '' | ||
59 | if 'norecurse' in ud.parm: | ||
60 | norecurse = '_norecurse' | ||
61 | |||
62 | fullpath = '' | ||
63 | if 'fullpath' in ud.parm: | ||
64 | fullpath = '_fullpath' | ||
65 | |||
66 | ud.localfile = data.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath), d) | ||
67 | |||
68 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
69 | |||
70 | def forcefetch(self, url, ud, d): | ||
71 | if (ud.date == "now"): | ||
72 | return True | ||
73 | return False | ||
74 | |||
75 | def go(self, loc, ud, d): | ||
76 | |||
77 | method = ud.parm.get('method', 'pserver') | ||
78 | localdir = ud.parm.get('localdir', ud.module) | ||
79 | cvs_port = ud.parm.get('port', '') | ||
80 | |||
81 | cvs_rsh = None | ||
82 | if method == "ext": | ||
83 | if "rsh" in ud.parm: | ||
84 | cvs_rsh = ud.parm["rsh"] | ||
85 | |||
86 | if method == "dir": | ||
87 | cvsroot = ud.path | ||
88 | else: | ||
89 | cvsroot = ":" + method | ||
90 | cvsproxyhost = data.getVar('CVS_PROXY_HOST', d, True) | ||
91 | if cvsproxyhost: | ||
92 | cvsroot += ";proxy=" + cvsproxyhost | ||
93 | cvsproxyport = data.getVar('CVS_PROXY_PORT', d, True) | ||
94 | if cvsproxyport: | ||
95 | cvsroot += ";proxyport=" + cvsproxyport | ||
96 | cvsroot += ":" + ud.user | ||
97 | if ud.pswd: | ||
98 | cvsroot += ":" + ud.pswd | ||
99 | cvsroot += "@" + ud.host + ":" + cvs_port + ud.path | ||
100 | |||
101 | options = [] | ||
102 | if 'norecurse' in ud.parm: | ||
103 | options.append("-l") | ||
104 | if ud.date: | ||
105 | # treat YYYYMMDDHHMM specially for CVS | ||
106 | if len(ud.date) == 12: | ||
107 | options.append("-D \"%s %s:%s UTC\"" % (ud.date[0:8], ud.date[8:10], ud.date[10:12])) | ||
108 | else: | ||
109 | options.append("-D \"%s UTC\"" % ud.date) | ||
110 | if ud.tag: | ||
111 | options.append("-r %s" % ud.tag) | ||
112 | |||
113 | localdata = data.createCopy(d) | ||
114 | data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata) | ||
115 | data.update_data(localdata) | ||
116 | |||
117 | data.setVar('CVSROOT', cvsroot, localdata) | ||
118 | data.setVar('CVSCOOPTS', " ".join(options), localdata) | ||
119 | data.setVar('CVSMODULE', ud.module, localdata) | ||
120 | cvscmd = data.getVar('FETCHCOMMAND', localdata, 1) | ||
121 | cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1) | ||
122 | |||
123 | if cvs_rsh: | ||
124 | cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd) | ||
125 | cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd) | ||
126 | |||
127 | # create module directory | ||
128 | logger.debug(2, "Fetch: checking for module directory") | ||
129 | pkg = data.expand('${PN}', d) | ||
130 | pkgdir = os.path.join(data.expand('${CVSDIR}', localdata), pkg) | ||
131 | moddir = os.path.join(pkgdir, localdir) | ||
132 | if os.access(os.path.join(moddir, 'CVS'), os.R_OK): | ||
133 | logger.info("Update " + loc) | ||
134 | # update sources there | ||
135 | os.chdir(moddir) | ||
136 | myret = os.system(cvsupdatecmd) | ||
137 | else: | ||
138 | logger.info("Fetch " + loc) | ||
139 | # check out sources there | ||
140 | bb.mkdirhier(pkgdir) | ||
141 | os.chdir(pkgdir) | ||
142 | logger.debug(1, "Running %s", cvscmd) | ||
143 | myret = os.system(cvscmd) | ||
144 | |||
145 | if myret != 0 or not os.access(moddir, os.R_OK): | ||
146 | try: | ||
147 | os.rmdir(moddir) | ||
148 | except OSError: | ||
149 | pass | ||
150 | raise FetchError(ud.module) | ||
151 | |||
152 | scmdata = ud.parm.get("scmdata", "") | ||
153 | if scmdata == "keep": | ||
154 | tar_flags = "" | ||
155 | else: | ||
156 | tar_flags = "--exclude 'CVS'" | ||
157 | |||
158 | # tar them up to a defined filename | ||
159 | if 'fullpath' in ud.parm: | ||
160 | os.chdir(pkgdir) | ||
161 | myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, localdir)) | ||
162 | else: | ||
163 | os.chdir(moddir) | ||
164 | os.chdir('..') | ||
165 | myret = os.system("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.basename(moddir))) | ||
166 | |||
167 | if myret != 0: | ||
168 | try: | ||
169 | os.unlink(ud.localpath) | ||
170 | except OSError: | ||
171 | pass | ||
172 | raise FetchError(ud.module) | ||