27
from jhbuild.errors import FatalError
27
from jhbuild.errors import FatalError, CommandError
28
from jhbuild.utils.cmds import get_output
28
29
from jhbuild.versioncontrol import Repository, Branch, register_repo_type
30
from jhbuild.commands.sanitycheck import inpath
30
# Make sure that the urlparse module considers sftp://
32
# Make sure that the urlparse module considers bzr://, bzr+ssh://, sftp:// and lp:
31
33
# scheme to be netloc aware and set to allow relative URIs.
34
if 'bzr' not in urlparse.uses_netloc:
35
urlparse.uses_netloc.append('bzr')
36
if 'bzr' not in urlparse.uses_relative:
37
urlparse.uses_relative.append('bzr')
38
if 'bzr+ssh' not in urlparse.uses_netloc:
39
urlparse.uses_netloc.append('bzr+ssh')
40
if 'bzr+ssh' not in urlparse.uses_relative:
41
urlparse.uses_relative.append('bzr+ssh')
32
42
if 'sftp' not in urlparse.uses_netloc:
33
43
urlparse.uses_netloc.append('sftp')
34
44
if 'sftp' not in urlparse.uses_relative:
35
45
urlparse.uses_relative.append('sftp')
46
if 'lp' not in urlparse.uses_relative:
47
urlparse.uses_relative.append('lp')
38
50
class BzrRepository(Repository):
39
51
"""A class representing a Bzr repository.
41
Note that this is just the parent directory for a bunch of darcs
42
branches, making it easy to switch to a mirror URI.
44
53
It can be a parent of a number of Bzr repositories or branches.
47
init_xml_attrs = ['href']
56
init_xml_attrs = ['href', 'trunk-template', 'branches-template']
49
def __init__(self, config, name, href):
58
def __init__(self, config, name, href, trunk_template='%(module)s', branches_template=''):
50
59
Repository.__init__(self, config, name)
51
60
# allow user to adjust location of branch.
52
61
self.href = config.repos.get(name, href)
54
branch_xml_attrs = ['module', 'checkoutdir']
56
def branch(self, name, module=None, checkoutdir=None):
62
self.trunk_template = trunk_template
63
self.branches_template = branches_template
65
branch_xml_attrs = ['module', 'checkoutdir', 'revision', 'tag']
67
def branch(self, name, module=None, checkoutdir=None, revision=None, tag=None):
57
69
if name in self.config.branches:
58
module = self.config.branches[module]
70
module_href = self.config.branches[name]
72
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
77
if revision and not revision.isdigit():
78
template = urlparse.urljoin(self.href, self.branches_template)
62
module = urlparse.urljoin(self.href, module)
63
return BzrBranch(self, module, checkoutdir)
80
template = urlparse.urljoin(self.href, self.trunk_template)
83
module_href = template % {
90
if checkoutdir is None:
93
return BzrBranch(self, module_href, checkoutdir, tag)
66
96
class BzrBranch(Branch):
67
"""A class representing a Darcs branch."""
97
"""A class representing a Bazaar branch."""
69
def __init__(self, repository, module, checkoutdir):
70
self.repository = repository
71
self.config = repository.config
73
self.checkoutdir = checkoutdir
99
def __init__(self, repository, module_href, checkoutdir, tag):
100
Branch.__init__(self, repository, module_href, checkoutdir)
76
104
if self.checkoutdir:
77
return os.path.join(self.config.checkoutroot, self.checkoutdir)
105
return os.path.join(self.checkoutroot, self.checkoutdir)
79
return os.path.join(self.config.checkoutroot,
107
return os.path.join(self.checkoutroot,
80
108
os.path.basename(self.module))
81
109
srcdir = property(srcdir)
85
113
branchname = property(branchname)
117
get_output(['bzr', 'ls', self.module])
87
122
def _checkout(self, buildscript):
88
123
cmd = ['bzr', 'branch', self.module]
89
124
if self.checkoutdir:
90
125
cmd.append(self.checkoutdir)
128
cmd.append('-rtag:%s' % self.tag)
92
130
if self.config.sticky_date:
93
raise FatalError('date based checkout not yet supported\n')
131
raise FatalError(_('date based checkout not yet supported\n'))
95
buildscript.execute(cmd, 'bzr', cwd=self.config.checkoutroot)
133
buildscript.execute(cmd, 'bzr', cwd=self.checkoutroot)
97
135
def _update(self, buildscript, overwrite=False):
98
136
if self.config.sticky_date:
99
raise FatalError('date based checkout not yet supported\n')
137
raise FatalError(_('date based checkout not yet supported\n'))
100
138
cmd = ['bzr', 'pull']
102
140
cmd.append('--overwrite')
142
cmd.append('-rtag:%s' % self.tag)
103
143
cmd.append(self.module)
104
144
buildscript.execute(cmd, 'bzr', cwd=self.srcdir)
106
146
def checkout(self, buildscript):
107
if os.path.exists(self.srcdir):
108
self._update(buildscript)
110
self._checkout(buildscript)
147
if not inpath('bzr', os.environ['PATH'].split(os.pathsep)):
148
raise CommandError(_('%s not found') % 'bzr')
149
Branch.checkout(self, buildscript)
112
def force_checkout(self, buildscript):
113
if os.path.exists(self.srcdir):
114
self._update(buildscript, overwrite=True)
116
self._checkout(buildscript)
152
if not os.path.exists(self.srcdir):
154
output = get_output(['bzr', 'revno'], cwd = self.srcdir)
155
return output.strip()
119
158
register_repo_type('bzr', BzrRepository)