summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/fetch/bzr.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/bzr.py')
-rw-r--r--bitbake-dev/lib/bb/fetch/bzr.py154
1 files changed, 154 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/fetch/bzr.py b/bitbake-dev/lib/bb/fetch/bzr.py
new file mode 100644
index 0000000000..b23e9eef86
--- /dev/null
+++ b/bitbake-dev/lib/bb/fetch/bzr.py
@@ -0,0 +1,154 @@
1"""
2BitBake 'Fetch' implementation for bzr.
3
4"""
5
6# Copyright (C) 2007 Ross Burton
7# Copyright (C) 2007 Richard Purdie
8#
9# Classes for obtaining upstream sources for the
10# BitBake build tools.
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
26import os
27import sys
28import bb
29from bb import data
30from bb.fetch import Fetch
31from bb.fetch import FetchError
32from bb.fetch import MissingParameterError
33from bb.fetch import runfetchcmd
34
35class Bzr(Fetch):
36 def supports(self, url, ud, d):
37 return ud.type in ['bzr']
38
39 def localpath (self, url, ud, d):
40
41 # Create paths to bzr checkouts
42 relpath = ud.path
43 if relpath.startswith('/'):
44 # Remove leading slash as os.path.join can't cope
45 relpath = relpath[1:]
46 ud.pkgdir = os.path.join(data.expand('${BZRDIR}', d), ud.host, relpath)
47
48 revision = Fetch.srcrev_internal_helper(ud, d)
49 if revision is True:
50 ud.revision = self.latest_revision(url, ud, d)
51 elif revision:
52 ud.revision = revision
53
54 if not ud.revision:
55 ud.revision = self.latest_revision(url, ud, d)
56
57 ud.localfile = data.expand('bzr_%s_%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.revision), d)
58
59 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
60
61 def _buildbzrcommand(self, ud, d, command):
62 """
63 Build up an bzr commandline based on ud
64 command is "fetch", "update", "revno"
65 """
66
67 basecmd = data.expand('${FETCHCMD_bzr}', d)
68
69 proto = "http"
70 if "proto" in ud.parm:
71 proto = ud.parm["proto"]
72
73 bzrroot = ud.host + ud.path
74
75 options = []
76
77 if command is "revno":
78 bzrcmd = "%s revno %s %s://%s" % (basecmd, " ".join(options), proto, bzrroot)
79 else:
80 if ud.revision:
81 options.append("-r %s" % ud.revision)
82
83 if command is "fetch":
84 bzrcmd = "%s co %s %s://%s" % (basecmd, " ".join(options), proto, bzrroot)
85 elif command is "update":
86 bzrcmd = "%s pull %s --overwrite" % (basecmd, " ".join(options))
87 else:
88 raise FetchError("Invalid bzr command %s" % command)
89
90 return bzrcmd
91
92 def go(self, loc, ud, d):
93 """Fetch url"""
94
95 # try to use the tarball stash
96 if Fetch.try_mirror(d, ud.localfile):
97 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping bzr checkout." % ud.localpath)
98 return
99
100 if os.access(os.path.join(ud.pkgdir, os.path.basename(ud.pkgdir), '.bzr'), os.R_OK):
101 bzrcmd = self._buildbzrcommand(ud, d, "update")
102 bb.msg.debug(1, bb.msg.domain.Fetcher, "BZR Update %s" % loc)
103 os.chdir(os.path.join (ud.pkgdir, os.path.basename(ud.path)))
104 runfetchcmd(bzrcmd, d)
105 else:
106 os.system("rm -rf %s" % os.path.join(ud.pkgdir, os.path.basename(ud.pkgdir)))
107 bzrcmd = self._buildbzrcommand(ud, d, "fetch")
108 bb.msg.debug(1, bb.msg.domain.Fetcher, "BZR Checkout %s" % loc)
109 bb.mkdirhier(ud.pkgdir)
110 os.chdir(ud.pkgdir)
111 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % bzrcmd)
112 runfetchcmd(bzrcmd, d)
113
114 os.chdir(ud.pkgdir)
115 # tar them up to a defined filename
116 try:
117 runfetchcmd("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.pkgdir)), d)
118 except:
119 t, v, tb = sys.exc_info()
120 try:
121 os.unlink(ud.localpath)
122 except OSError:
123 pass
124 raise t, v, tb
125
126 def suppports_srcrev(self):
127 return True
128
129 def _revision_key(self, url, ud, d):
130 """
131 Return a unique key for the url
132 """
133 return "bzr:" + ud.pkgdir
134
135 def _latest_revision(self, url, ud, d):
136 """
137 Return the latest upstream revision number
138 """
139 bb.msg.debug(2, bb.msg.domain.Fetcher, "BZR fetcher hitting network for %s" % url)
140
141 output = runfetchcmd(self._buildbzrcommand(ud, d, "revno"), d, True)
142
143 return output.strip()
144
145 def _sortable_revision(self, url, ud, d):
146 """
147 Return a sortable revision number which in our case is the revision number
148 """
149
150 return self._build_revision(url, ud, d)
151
152 def _build_revision(self, url, ud, d):
153 return ud.revision
154