diff options
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/cvs.py')
-rw-r--r-- | bitbake-dev/lib/bb/fetch/cvs.py | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/fetch/cvs.py b/bitbake-dev/lib/bb/fetch/cvs.py new file mode 100644 index 0000000000..c4ccf4303f --- /dev/null +++ b/bitbake-dev/lib/bb/fetch/cvs.py | |||
@@ -0,0 +1,178 @@ | |||
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, re | ||
30 | import bb | ||
31 | from bb import data | ||
32 | from bb.fetch import Fetch | ||
33 | from bb.fetch import FetchError | ||
34 | from bb.fetch import MissingParameterError | ||
35 | |||
36 | class Cvs(Fetch): | ||
37 | """ | ||
38 | Class to fetch a module or modules from cvs repositories | ||
39 | """ | ||
40 | def supports(self, url, ud, d): | ||
41 | """ | ||
42 | Check to see if a given url can be fetched with cvs. | ||
43 | """ | ||
44 | return ud.type in ['cvs', 'pserver'] | ||
45 | |||
46 | def localpath(self, url, ud, d): | ||
47 | if not "module" in ud.parm: | ||
48 | raise MissingParameterError("cvs method needs a 'module' parameter") | ||
49 | ud.module = ud.parm["module"] | ||
50 | |||
51 | ud.tag = "" | ||
52 | if 'tag' in ud.parm: | ||
53 | ud.tag = ud.parm['tag'] | ||
54 | |||
55 | # Override the default date in certain cases | ||
56 | if 'date' in ud.parm: | ||
57 | ud.date = ud.parm['date'] | ||
58 | elif ud.tag: | ||
59 | ud.date = "" | ||
60 | |||
61 | norecurse = '' | ||
62 | if 'norecurse' in ud.parm: | ||
63 | norecurse = '_norecurse' | ||
64 | |||
65 | fullpath = '' | ||
66 | if 'fullpath' in ud.parm: | ||
67 | fullpath = '_fullpath' | ||
68 | |||
69 | ud.localfile = data.expand('%s_%s_%s_%s%s%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date, norecurse, fullpath), d) | ||
70 | |||
71 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
72 | |||
73 | def forcefetch(self, url, ud, d): | ||
74 | if (ud.date == "now"): | ||
75 | return True | ||
76 | return False | ||
77 | |||
78 | def go(self, loc, ud, d): | ||
79 | |||
80 | # try to use the tarball stash | ||
81 | if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile): | ||
82 | bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping cvs checkout." % ud.localpath) | ||
83 | return | ||
84 | |||
85 | method = "pserver" | ||
86 | if "method" in ud.parm: | ||
87 | method = ud.parm["method"] | ||
88 | |||
89 | localdir = ud.module | ||
90 | if "localdir" in ud.parm: | ||
91 | localdir = ud.parm["localdir"] | ||
92 | |||
93 | cvs_port = "" | ||
94 | if "port" in ud.parm: | ||
95 | cvs_port = ud.parm["port"] | ||
96 | |||
97 | cvs_rsh = None | ||
98 | if method == "ext": | ||
99 | if "rsh" in ud.parm: | ||
100 | cvs_rsh = ud.parm["rsh"] | ||
101 | |||
102 | if method == "dir": | ||
103 | cvsroot = ud.path | ||
104 | else: | ||
105 | cvsroot = ":" + method | ||
106 | cvsproxyhost = data.getVar('CVS_PROXY_HOST', d, True) | ||
107 | if cvsproxyhost: | ||
108 | cvsroot += ";proxy=" + cvsproxyhost | ||
109 | cvsproxyport = data.getVar('CVS_PROXY_PORT', d, True) | ||
110 | if cvsproxyport: | ||
111 | cvsroot += ";proxyport=" + cvsproxyport | ||
112 | cvsroot += ":" + ud.user | ||
113 | if ud.pswd: | ||
114 | cvsroot += ":" + ud.pswd | ||
115 | cvsroot += "@" + ud.host + ":" + cvs_port + ud.path | ||
116 | |||
117 | options = [] | ||
118 | if 'norecurse' in ud.parm: | ||
119 | options.append("-l") | ||
120 | if ud.date: | ||
121 | options.append("-D \"%s UTC\"" % ud.date) | ||
122 | if ud.tag: | ||
123 | options.append("-r %s" % ud.tag) | ||
124 | |||
125 | localdata = data.createCopy(d) | ||
126 | data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata) | ||
127 | data.update_data(localdata) | ||
128 | |||
129 | data.setVar('CVSROOT', cvsroot, localdata) | ||
130 | data.setVar('CVSCOOPTS', " ".join(options), localdata) | ||
131 | data.setVar('CVSMODULE', ud.module, localdata) | ||
132 | cvscmd = data.getVar('FETCHCOMMAND', localdata, 1) | ||
133 | cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1) | ||
134 | |||
135 | if cvs_rsh: | ||
136 | cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd) | ||
137 | cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd) | ||
138 | |||
139 | # create module directory | ||
140 | bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory") | ||
141 | pkg = data.expand('${PN}', d) | ||
142 | pkgdir = os.path.join(data.expand('${CVSDIR}', localdata), pkg) | ||
143 | moddir = os.path.join(pkgdir,localdir) | ||
144 | if os.access(os.path.join(moddir,'CVS'), os.R_OK): | ||
145 | bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc) | ||
146 | # update sources there | ||
147 | os.chdir(moddir) | ||
148 | myret = os.system(cvsupdatecmd) | ||
149 | else: | ||
150 | bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc) | ||
151 | # check out sources there | ||
152 | bb.mkdirhier(pkgdir) | ||
153 | os.chdir(pkgdir) | ||
154 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % cvscmd) | ||
155 | myret = os.system(cvscmd) | ||
156 | |||
157 | if myret != 0 or not os.access(moddir, os.R_OK): | ||
158 | try: | ||
159 | os.rmdir(moddir) | ||
160 | except OSError: | ||
161 | pass | ||
162 | raise FetchError(ud.module) | ||
163 | |||
164 | # tar them up to a defined filename | ||
165 | if 'fullpath' in ud.parm: | ||
166 | os.chdir(pkgdir) | ||
167 | myret = os.system("tar -czf %s %s" % (ud.localpath, localdir)) | ||
168 | else: | ||
169 | os.chdir(moddir) | ||
170 | os.chdir('..') | ||
171 | myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(moddir))) | ||
172 | |||
173 | if myret != 0: | ||
174 | try: | ||
175 | os.unlink(ud.localpath) | ||
176 | except OSError: | ||
177 | pass | ||
178 | raise FetchError(ud.module) | ||