summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch/svn.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch/svn.py')
-rw-r--r--bitbake/lib/bb/fetch/svn.py203
1 files changed, 83 insertions, 120 deletions
diff --git a/bitbake/lib/bb/fetch/svn.py b/bitbake/lib/bb/fetch/svn.py
index d1a959371b..b95de2a79b 100644
--- a/bitbake/lib/bb/fetch/svn.py
+++ b/bitbake/lib/bb/fetch/svn.py
@@ -26,6 +26,7 @@ Based on functions from the base bb module, Copyright 2003 Holger Schurig
26""" 26"""
27 27
28import os, re 28import os, re
29import sys
29import bb 30import bb
30from bb import data 31from bb import data
31from bb.fetch import Fetch 32from bb.fetch import Fetch
@@ -34,136 +35,98 @@ from bb.fetch import MissingParameterError
34 35
35class Svn(Fetch): 36class Svn(Fetch):
36 """Class to fetch a module or modules from svn repositories""" 37 """Class to fetch a module or modules from svn repositories"""
37 def supports(url, d): 38 def supports(self, url, ud, d):
38 """Check to see if a given url can be fetched with svn.
39 Expects supplied url in list form, as outputted by bb.decodeurl().
40 """ 39 """
41 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d)) 40 Check to see if a given url can be fetched with svn.
42 return type in ['svn'] 41 """
43 supports = staticmethod(supports) 42 return ud.type in ['svn']
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 43
51 if not "module" in parm: 44 def localpath(self, url, ud, d):
45 if not "module" in ud.parm:
52 raise MissingParameterError("svn method needs a 'module' parameter") 46 raise MissingParameterError("svn method needs a 'module' parameter")
53 else: 47 else:
54 module = parm["module"] 48 ud.module = ud.parm["module"]
55 if 'rev' in parm: 49
56 revision = parm['rev'] 50 ud.revision = ""
57 else: 51 if 'rev' in ud.parm:
58 revision = "" 52 ud.revision = ud.parm['rev']
53
54 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
55
56 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
59 57
60 date = Fetch.getSRCDate(d) 58 def forcefetch(self, url, ud, d):
59 if (ud.date == "now"):
60 return True
61 return False
61 62
62 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s_%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, path.replace('/', '.'), revision, date), d)) 63 def go(self, loc, ud, d):
63 localpath = staticmethod(localpath) 64 """Fetch url"""
64 65
65 def go(self, d, urls = []): 66 # try to use the tarball stash
66 """Fetch urls""" 67 if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
67 if not urls: 68 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath)
68 urls = self.urls 69 return
70
71 proto = "svn"
72 if "proto" in ud.parm:
73 proto = ud.parm["proto"]
74
75 svn_rsh = None
76 if proto == "svn+ssh" and "rsh" in ud.parm:
77 svn_rsh = ud.parm["rsh"]
78
79 svnroot = ud.host + ud.path
80
81 # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
82 options = []
83 if ud.revision:
84 options.append("-r %s" % ud.revision)
85 elif ud.date != "now":
86 options.append("-r {%s}" % ud.date)
69 87
70 localdata = data.createCopy(d) 88 localdata = data.createCopy(d)
71 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata) 89 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
72 data.update_data(localdata) 90 data.update_data(localdata)
73 91
74 for loc in urls: 92 data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, ud.module), localdata)
75 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata)) 93 data.setVar('SVNCOOPTS', " ".join(options), localdata)
76 if not "module" in parm: 94 data.setVar('SVNMODULE', ud.module, localdata)
77 raise MissingParameterError("svn method needs a 'module' parameter") 95 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
78 else: 96 svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
79 module = parm["module"] 97
80 98 if svn_rsh:
81 dlfile = self.localpath(loc, localdata) 99 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
82 dldir = data.getVar('DL_DIR', localdata, 1) 100 svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
83# if local path contains the svn 101
84# module, consider the dir above it to be the 102 pkg = data.expand('${PN}', d)
85# download directory 103 pkgdir = os.path.join(data.expand('${SVNDIR}', localdata), pkg)
86# pos = dlfile.find(module) 104 moddir = os.path.join(pkgdir, ud.module)
87# if pos: 105 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'")
88# dldir = dlfile[:pos] 106
89# else: 107 if os.access(os.path.join(moddir, '.svn'), os.R_OK):
90# dldir = os.path.dirname(dlfile) 108 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
91 109 # update sources there
92# setup svn options 110 os.chdir(moddir)
93 options = [] 111 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd)
94 if 'rev' in parm: 112 myret = os.system(svnupcmd)
95 revision = parm['rev'] 113 else:
96 else: 114 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
97 revision = "" 115 # check out sources there
98 116 bb.mkdirhier(pkgdir)
99 date = Fetch.getSRCDate(d) 117 os.chdir(pkgdir)
100 118 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd)
101 if "proto" in parm:
102 proto = parm["proto"]
103 else:
104 proto = "svn"
105
106 svn_rsh = None
107 if proto == "svn+ssh" and "rsh" in parm:
108 svn_rsh = parm["rsh"]
109
110 tarfn = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, path.replace('/', '.'), revision, date), localdata)
111 data.setVar('TARFILES', dlfile, localdata)
112 data.setVar('TARFN', tarfn, localdata)
113
114 if Fetch.check_for_tarball(d, tarfn, dldir, date):
115 continue
116
117 olddir = os.path.abspath(os.getcwd())
118 os.chdir(data.expand(dldir, localdata))
119
120 svnroot = host + path
121
122 data.setVar('SVNROOT', svnroot, localdata)
123 data.setVar('SVNCOOPTS', " ".join(options), localdata)
124 data.setVar('SVNMODULE', module, localdata)
125 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
126 svncmd = "svn co -r {%s} %s://%s/%s" % (date, proto, svnroot, module)
127
128 if revision:
129 svncmd = "svn co -r %s %s://%s/%s" % (revision, proto, svnroot, module)
130 elif date == "now":
131 svncmd = "svn co %s://%s/%s" % (proto, svnroot, module)
132
133 if svn_rsh:
134 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
135
136# create temp directory
137 bb.debug(2, "Fetch: creating temporary directory")
138 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
139 data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvn.XXXXXX', localdata), localdata)
140 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
141 tmpfile = tmppipe.readline().strip()
142 if not tmpfile:
143 bb.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
144 raise FetchError(module)
145
146# check out sources there
147 os.chdir(tmpfile)
148 bb.note("Fetch " + loc)
149 bb.debug(1, "Running %s" % svncmd)
150 myret = os.system(svncmd) 119 myret = os.system(svncmd)
151 if myret != 0: 120
152 try: 121 if myret != 0:
153 os.rmdir(tmpfile) 122 raise FetchError(ud.module)
154 except OSError: 123
155 pass 124 os.chdir(pkgdir)
156 raise FetchError(module) 125 # tar them up to a defined filename
157 126 myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
158 os.chdir(os.path.join(tmpfile, os.path.dirname(module))) 127 if myret != 0:
159# tar them up to a defined filename 128 try:
160 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module))) 129 os.unlink(ud.localpath)
161 if myret != 0: 130 except OSError:
162 try: 131 pass
163 os.unlink(tarfn) 132 raise FetchError(ud.module)
164 except OSError:
165 pass
166# cleanup
167 os.system('rm -rf %s' % tmpfile)
168 os.chdir(olddir)
169 del localdata