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