summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch/svn.py
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2007-08-03 13:40:52 +0000
committerRichard Purdie <richard@openedhand.com>2007-08-03 13:40:52 +0000
commitbfc70eb24e3ded25007811b1531673fa70b02401 (patch)
treefa4a29290d3178937fa085c147e8a51f815c6fdc /bitbake/lib/bb/fetch/svn.py
parent034bbb805be0002fe6d689abde19662868b57b2c (diff)
downloadpoky-bfc70eb24e3ded25007811b1531673fa70b02401.tar.gz
bitbake: Update along 1.8 branch
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@2345 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/lib/bb/fetch/svn.py')
-rw-r--r--bitbake/lib/bb/fetch/svn.py177
1 files changed, 118 insertions, 59 deletions
diff --git a/bitbake/lib/bb/fetch/svn.py b/bitbake/lib/bb/fetch/svn.py
index 120f4f8539..ca12efe158 100644
--- a/bitbake/lib/bb/fetch/svn.py
+++ b/bitbake/lib/bb/fetch/svn.py
@@ -1,17 +1,12 @@
1# ex:ts=4:sw=4:sts=4:et 1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- 2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3""" 3"""
4BitBake 'Fetch' implementations 4BitBake 'Fetch' implementation for svn.
5
6This implementation is for svn. It is based on the cvs implementation.
7 5
8""" 6"""
9 7
10# Copyright (C) 2004 Marcin Juszkiewicz 8# Copyright (C) 2003, 2004 Chris Larson
11# 9# Copyright (C) 2004 Marcin Juszkiewicz
12# Classes for obtaining upstream sources for the
13# BitBake build tools.
14# Copyright (C) 2003, 2004 Chris Larson
15# 10#
16# This program is free software; you can redistribute it and/or modify 11# This program is free software; you can redistribute it and/or modify
17# it under the terms of the GNU General Public License version 2 as 12# it under the terms of the GNU General Public License version 2 as
@@ -35,6 +30,7 @@ from bb import data
35from bb.fetch import Fetch 30from bb.fetch import Fetch
36from bb.fetch import FetchError 31from bb.fetch import FetchError
37from bb.fetch import MissingParameterError 32from bb.fetch import MissingParameterError
33from bb.fetch import runfetchcmd
38 34
39class Svn(Fetch): 35class Svn(Fetch):
40 """Class to fetch a module or modules from svn repositories""" 36 """Class to fetch a module or modules from svn repositories"""
@@ -47,32 +43,54 @@ class Svn(Fetch):
47 def localpath(self, url, ud, d): 43 def localpath(self, url, ud, d):
48 if not "module" in ud.parm: 44 if not "module" in ud.parm:
49 raise MissingParameterError("svn method needs a 'module' parameter") 45 raise MissingParameterError("svn method needs a 'module' parameter")
50 else:
51 ud.module = ud.parm["module"]
52 46
53 ud.revision = "" 47 ud.module = ud.parm["module"]
54 if 'rev' in ud.parm: 48
55 ud.revision = ud.parm['rev'] 49 # Create paths to svn checkouts
50 relpath = ud.path
51 if relpath.startswith('/'):
52 # Remove leading slash as os.path.join can't cope
53 relpath = relpath[1:]
54 ud.pkgdir = os.path.join(data.expand('${SVNDIR}', d), ud.host, relpath)
55 ud.moddir = os.path.join(ud.pkgdir, ud.module)
56 56
57 if ud.revision: 57 if 'rev' in ud.parm:
58 ud.date = "" 58 ud.date = ""
59 ud.revision = ud.parm['rev']
60 elif 'date' in ud.date:
61 ud.date = ud.parm['date']
62 ud.revision = ""
63 else:
64 #
65 # ***Nasty hacks***
66 # If DATE in unexpanded PV, use ud.date (which is set from SRCDATE)
67 # Will warn people to switch to SRCREV here
68 #
69 # How can we tell when a user has overriden SRCDATE?
70 # check for "get_srcdate" in unexpanded SRCREV - ugly
71 #
72 pv = data.getVar("PV", d, 0)
73 if "DATE" in pv:
74 ud.revision = ""
75 else:
76 rev = data.getVar("SRCREV", d, 0)
77 if "get_srcrev" in rev:
78 ud.revision = self.latest_revision(url, ud, d)
79 else:
80 ud.revision = rev
81 ud.date = ""
59 82
60 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d) 83 ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
61 84
62 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) 85 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
63 86
64 def forcefetch(self, url, ud, d): 87 def _buildsvncommand(self, ud, d, command):
65 if (ud.date == "now"): 88 """
66 return True 89 Build up an svn commandline based on ud
67 return False 90 command is "fetch", "update", "info"
68 91 """
69 def go(self, loc, ud, d):
70 """Fetch url"""
71 92
72 # try to use the tarball stash 93 basecmd = data.expand('${FETCHCMD_svn}', d)
73 if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
74 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath)
75 return
76 94
77 proto = "svn" 95 proto = "svn"
78 if "proto" in ud.parm: 96 if "proto" in ud.parm:
@@ -84,12 +102,8 @@ class Svn(Fetch):
84 102
85 svnroot = ud.host + ud.path 103 svnroot = ud.host + ud.path
86 104
87 # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now" 105 # either use the revision, or SRCDATE in braces,
88 options = [] 106 options = []
89 if ud.revision:
90 options.append("-r %s" % ud.revision)
91 elif ud.date != "now":
92 options.append("-r {%s}" % ud.date)
93 107
94 if ud.user: 108 if ud.user:
95 options.append("--username %s" % ud.user) 109 options.append("--username %s" % ud.user)
@@ -97,48 +111,93 @@ class Svn(Fetch):
97 if ud.pswd: 111 if ud.pswd:
98 options.append("--password %s" % ud.pswd) 112 options.append("--password %s" % ud.pswd)
99 113
100 localdata = data.createCopy(d) 114 if command is "info":
101 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata) 115 svncmd = "%s info %s %s://%s/%s/" % (basecmd, " ".join(options), proto, svnroot, ud.module)
102 data.update_data(localdata) 116 else:
103 117 if ud.revision:
104 data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, ud.module), localdata) 118 options.append("-r %s" % ud.revision)
105 data.setVar('SVNCOOPTS', " ".join(options), localdata) 119 elif ud.date:
106 data.setVar('SVNMODULE', ud.module, localdata) 120 options.append("-r {%s}" % ud.date)
107 svncmd = data.getVar('FETCHCOMMAND', localdata, 1) 121
108 svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1) 122 if command is "fetch":
123 svncmd = "%s co %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, svnroot, ud.module, ud.module)
124 elif command is "update":
125 svncmd = "%s update %s" % (basecmd, " ".join(options))
126 else:
127 raise FetchError("Invalid svn command %s" % command)
109 128
110 if svn_rsh: 129 if svn_rsh:
111 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd) 130 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
112 svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
113 131
114 pkg = data.expand('${PN}', d) 132 return svncmd
115 pkgdir = os.path.join(data.expand('${SVNDIR}', localdata), pkg) 133
116 moddir = os.path.join(pkgdir, ud.module) 134 def go(self, loc, ud, d):
117 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'") 135 """Fetch url"""
118 136
119 if os.access(os.path.join(moddir, '.svn'), os.R_OK): 137 # try to use the tarball stash
138 if Fetch.try_mirror(d, ud.localfile):
139 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath)
140 return
141
142 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + ud.moddir + "'")
143
144 if os.access(os.path.join(ud.moddir, '.svn'), os.R_OK):
145 svnupdatecmd = self._buildsvncommand(ud, d, "update")
120 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc) 146 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
121 # update sources there 147 # update sources there
122 os.chdir(moddir) 148 os.chdir(ud.moddir)
123 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupcmd) 149 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnupdatecmd)
124 myret = os.system(svnupcmd) 150 runfetchcmd(svnupdatecmd, d)
125 else: 151 else:
152 svnfetchcmd = self._buildsvncommand(ud, d, "fetch")
126 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc) 153 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
127 # check out sources there 154 # check out sources there
128 bb.mkdirhier(pkgdir) 155 bb.mkdirhier(ud.pkgdir)
129 os.chdir(pkgdir) 156 os.chdir(ud.pkgdir)
130 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svncmd) 157 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % svnfetchcmd)
131 myret = os.system(svncmd) 158 runfetchcmd(svnfetchcmd, d)
132
133 if myret != 0:
134 raise FetchError(ud.module)
135 159
136 os.chdir(pkgdir) 160 os.chdir(ud.pkgdir)
137 # tar them up to a defined filename 161 # tar them up to a defined filename
138 myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module))) 162 try:
139 if myret != 0: 163 runfetchcmd("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)), d)
164 except:
165 t, v, tb = sys.exc_info()
140 try: 166 try:
141 os.unlink(ud.localpath) 167 os.unlink(ud.localpath)
142 except OSError: 168 except OSError:
143 pass 169 pass
144 raise FetchError(ud.module) 170 raise t, v, tb
171
172 def suppports_srcrev(self):
173 return True
174
175 def _revision_key(self, url, ud, d):
176 """
177 Return a unique key for the url
178 """
179 return "svn:" + ud.moddir
180
181 def _latest_revision(self, url, ud, d):
182 """
183 Return the latest upstream revision number
184 """
185 bb.msg.debug(2, bb.msg.domain.Fetcher, "SVN fetcher hitting network for %s" % url)
186
187 output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "info"), d, True)
188
189 revision = None
190 for line in output.splitlines():
191 if "Last Changed Rev" in line:
192 revision = line.split(":")[1].strip()
193
194 return revision
195
196 def _sortable_revision(self, url, ud, d):
197 """
198 Return a sortable revision number which in our case is the revision number
199 (use the cached version to avoid network access)
200 """
201
202 return self.latest_revision(url, ud, d)
203