summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch/cvs.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch/cvs.py')
-rw-r--r--bitbake/lib/bb/fetch/cvs.py214
1 files changed, 214 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch/cvs.py b/bitbake/lib/bb/fetch/cvs.py
new file mode 100644
index 0000000000..461a2f50f9
--- /dev/null
+++ b/bitbake/lib/bb/fetch/cvs.py
@@ -0,0 +1,214 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31from bb.fetch import Fetch
32from bb.fetch import FetchError
33from bb.fetch import MissingParameterError
34
35class Cvs(Fetch):
36 """Class to fetch a module or modules from cvs repositories"""
37 def supports(url, d):
38 """Check to see if a given url can be fetched with cvs.
39 Expects supplied url in list form, as outputted by bb.decodeurl().
40 """
41 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
42 return type in ['cvs', 'pserver']
43 supports = staticmethod(supports)
44
45 def localpath(url, d):
46 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
47 if "localpath" in parm:
48# if user overrides local path, use it.
49 return parm["localpath"]
50
51 if not "module" in parm:
52 raise MissingParameterError("cvs method needs a 'module' parameter")
53 else:
54 module = parm["module"]
55 if 'tag' in parm:
56 tag = parm['tag']
57 else:
58 tag = ""
59 if 'date' in parm:
60 date = parm['date']
61 else:
62 if not tag:
63 date = Fetch.getSRCDate(d)
64 else:
65 date = ""
66
67 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, tag, date), d))
68 localpath = staticmethod(localpath)
69
70 def go(self, d, urls = []):
71 """Fetch urls"""
72 if not urls:
73 urls = self.urls
74
75 localdata = data.createCopy(d)
76 data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
77 data.update_data(localdata)
78
79 for loc in urls:
80 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata))
81 if not "module" in parm:
82 raise MissingParameterError("cvs method needs a 'module' parameter")
83 else:
84 module = parm["module"]
85
86 dlfile = self.localpath(loc, localdata)
87 dldir = data.getVar('DL_DIR', localdata, 1)
88# if local path contains the cvs
89# module, consider the dir above it to be the
90# download directory
91# pos = dlfile.find(module)
92# if pos:
93# dldir = dlfile[:pos]
94# else:
95# dldir = os.path.dirname(dlfile)
96
97# setup cvs options
98 options = []
99 if 'tag' in parm:
100 tag = parm['tag']
101 else:
102 tag = ""
103
104 if 'date' in parm:
105 date = parm['date']
106 else:
107 if not tag:
108 date = Fetch.getSRCDate(d)
109 else:
110 date = ""
111
112 if "method" in parm:
113 method = parm["method"]
114 else:
115 method = "pserver"
116
117 if "localdir" in parm:
118 localdir = parm["localdir"]
119 else:
120 localdir = module
121
122 cvs_rsh = None
123 if method == "ext":
124 if "rsh" in parm:
125 cvs_rsh = parm["rsh"]
126
127 tarfn = data.expand('%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, tag, date), localdata)
128 data.setVar('TARFILES', dlfile, localdata)
129 data.setVar('TARFN', tarfn, localdata)
130
131 dl = os.path.join(dldir, tarfn)
132 if os.access(dl, os.R_OK):
133 bb.debug(1, "%s already exists, skipping cvs checkout." % tarfn)
134 continue
135
136 pn = data.getVar('PN', d, 1)
137 cvs_tarball_stash = None
138 if pn:
139 cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH_%s' % pn, d, 1)
140 if cvs_tarball_stash == None:
141 cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH', d, 1)
142 if cvs_tarball_stash:
143 fetchcmd = data.getVar("FETCHCOMMAND_wget", d, 1)
144 uri = cvs_tarball_stash + tarfn
145 bb.note("fetch " + uri)
146 fetchcmd = fetchcmd.replace("${URI}", uri)
147 ret = os.system(fetchcmd)
148 if ret == 0:
149 bb.note("Fetched %s from tarball stash, skipping checkout" % tarfn)
150 continue
151
152 if date:
153 options.append("-D %s" % date)
154 if tag:
155 options.append("-r %s" % tag)
156
157 olddir = os.path.abspath(os.getcwd())
158 os.chdir(data.expand(dldir, localdata))
159
160# setup cvsroot
161 if method == "dir":
162 cvsroot = path
163 else:
164 cvsroot = ":" + method + ":" + user
165 if pswd:
166 cvsroot += ":" + pswd
167 cvsroot += "@" + host + ":" + path
168
169 data.setVar('CVSROOT', cvsroot, localdata)
170 data.setVar('CVSCOOPTS', " ".join(options), localdata)
171 data.setVar('CVSMODULE', module, localdata)
172 cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
173 cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
174
175 if cvs_rsh:
176 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
177 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
178
179# create module directory
180 bb.debug(2, "Fetch: checking for module directory")
181 pkg=data.expand('${PN}', d)
182 pkgdir=os.path.join(data.expand('${CVSDIR}', localdata), pkg)
183 moddir=os.path.join(pkgdir,localdir)
184 if os.access(os.path.join(moddir,'CVS'), os.R_OK):
185 bb.note("Update " + loc)
186# update sources there
187 os.chdir(moddir)
188 myret = os.system(cvsupdatecmd)
189 else:
190 bb.note("Fetch " + loc)
191# check out sources there
192 bb.mkdirhier(pkgdir)
193 os.chdir(pkgdir)
194 bb.debug(1, "Running %s" % cvscmd)
195 myret = os.system(cvscmd)
196
197 if myret != 0:
198 try:
199 os.rmdir(moddir)
200 except OSError:
201 pass
202 raise FetchError(module)
203
204 os.chdir(moddir)
205 os.chdir('..')
206# tar them up to a defined filename
207 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(moddir)))
208 if myret != 0:
209 try:
210 os.unlink(tarfn)
211 except OSError:
212 pass
213 os.chdir(olddir)
214 del localdata