~ubuntu-branches/ubuntu/natty/jhbuild/natty

« back to all changes in this revision

Viewing changes to jhbuild/versioncontrol/bzr.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort, Loic Minier, Emilio Pozuelo Monfort
  • Date: 2009-11-09 20:28:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091109202848-m9ec7dmzptqtchtj
Tags: 2.28.0-1
[ Loic Minier ]
* Cleanups.
* Ship scripts.
* Don't set GNOME_MODULE as it equals the name of the source package.

[ Emilio Pozuelo Monfort ]
* New upstream release. Closes: #524504.
  - Use 'git rev-parse' rather than 'git-rev-parse'. Closes: #544642.
* Ship install-check. Closes: #441008.
* Uploaders list regenerated. Closes: #523542, #554071.
* debian/control.in,
  debian/rules:
  - Stop shipping a copy of subprocess.py. Require python >= 2.4.
  - Switch to python-support.
* debian/control.in:
  - Bump Standards-Version to 3.8.3, no changes needed.
  - Build depend on intltool >= 0.35.0.
  - Build depend on pkg-config, gnome-doc-utils and rarian-compat to build
    the documentation.
  - Make jhbuild arch any since install-check is a binary. Depend on
    ${shlibs:Depends}.
  - Recommend, and not suggest, git-core. Also recommend mercurial.
* debian/watch:
  - Added.
* debian/patches/01_import_from_pkgdatadir.patch:
  - Added, import jhbuild from pkgdatadir if everything else fails.
    This way we can ship the jhbuild private modules in /usr/sharejhbuild.
* debian/jhbuild.docs:
  - Removed, the necessary docs are now installed by the upstream Makefile.
* debian/rules:
  - Include autotools.mk and gnome.mk.
  - Remove all the manual build process, autotools.mk does everything now.
  - Install the jhbuild modules in /usr/share/jhbuild.
* debian/install:
  - Install the modulesets and patches from here since the upstream build
    system doesn't install them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import errno
25
25
import urlparse
26
26
 
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
29
31
 
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')
36
48
 
37
49
 
38
50
class BzrRepository(Repository):
39
51
    """A class representing a Bzr repository.
40
52
 
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.
43
 
 
44
53
    It can be a parent of a number of Bzr repositories or branches.
45
54
    """
46
55
 
47
 
    init_xml_attrs = ['href']
 
56
    init_xml_attrs = ['href', 'trunk-template', 'branches-template']
48
57
 
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)
53
 
 
54
 
    branch_xml_attrs = ['module', 'checkoutdir']
55
 
 
56
 
    def branch(self, name, module=None, checkoutdir=None):
 
62
        self.trunk_template = trunk_template
 
63
        self.branches_template = branches_template
 
64
 
 
65
    branch_xml_attrs = ['module', 'checkoutdir', 'revision', 'tag']
 
66
 
 
67
    def branch(self, name, module=None, checkoutdir=None, revision=None, tag=None):
 
68
        module_href = None
57
69
        if name in self.config.branches:
58
 
            module = self.config.branches[module]
 
70
            module_href = self.config.branches[name]
 
71
            if not module_href:
 
72
                raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
 
73
 
 
74
        if module is None:
 
75
            module = name
 
76
 
 
77
        if revision and not revision.isdigit():
 
78
            template = urlparse.urljoin(self.href, self.branches_template)
59
79
        else:
60
 
            if module is None:
61
 
                module = name
62
 
            module = urlparse.urljoin(self.href, module)
63
 
        return BzrBranch(self, module, checkoutdir)
 
80
            template = urlparse.urljoin(self.href, self.trunk_template)
 
81
 
 
82
        if not module_href:
 
83
            module_href = template % {
 
84
                'module': module,
 
85
                'revision': revision,
 
86
                'branch': revision,
 
87
                'tag': tag
 
88
            }
 
89
 
 
90
        if checkoutdir is None:
 
91
            checkoutdir = name
 
92
 
 
93
        return BzrBranch(self, module_href, checkoutdir, tag)
64
94
 
65
95
 
66
96
class BzrBranch(Branch):
67
 
    """A class representing a Darcs branch."""
 
97
    """A class representing a Bazaar branch."""
68
98
 
69
 
    def __init__(self, repository, module, checkoutdir):
70
 
        self.repository = repository
71
 
        self.config = repository.config
72
 
        self.module = module
73
 
        self.checkoutdir = checkoutdir
 
99
    def __init__(self, repository, module_href, checkoutdir, tag):
 
100
        Branch.__init__(self, repository, module_href, checkoutdir)
 
101
        self.tag = tag
74
102
 
75
103
    def srcdir(self):
76
104
        if self.checkoutdir:
77
 
            return os.path.join(self.config.checkoutroot, self.checkoutdir)
 
105
            return os.path.join(self.checkoutroot, self.checkoutdir)
78
106
        else:
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)
82
110
 
84
112
        return None
85
113
    branchname = property(branchname)
86
114
 
 
115
    def exists(self):
 
116
        try:
 
117
            get_output(['bzr', 'ls', self.module])
 
118
            return True
 
119
        except:
 
120
            return False
 
121
 
87
122
    def _checkout(self, buildscript):
88
123
        cmd = ['bzr', 'branch', self.module]
89
124
        if self.checkoutdir:
90
125
            cmd.append(self.checkoutdir)
91
126
 
 
127
        if self.tag:
 
128
            cmd.append('-rtag:%s' % self.tag)
 
129
 
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'))
94
132
 
95
 
        buildscript.execute(cmd, 'bzr', cwd=self.config.checkoutroot)
 
133
        buildscript.execute(cmd, 'bzr', cwd=self.checkoutroot)
96
134
 
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']
101
139
        if overwrite:
102
140
            cmd.append('--overwrite')
 
141
        if self.tag:
 
142
            cmd.append('-rtag:%s' % self.tag)
103
143
        cmd.append(self.module)
104
144
        buildscript.execute(cmd, 'bzr', cwd=self.srcdir)
105
145
 
106
146
    def checkout(self, buildscript):
107
 
        if os.path.exists(self.srcdir):
108
 
            self._update(buildscript)
109
 
        else:
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)
111
150
 
112
 
    def force_checkout(self, buildscript):
113
 
        if os.path.exists(self.srcdir):
114
 
            self._update(buildscript, overwrite=True)
115
 
        else:
116
 
            self._checkout(buildscript)
 
151
    def tree_id(self):
 
152
        if not os.path.exists(self.srcdir):
 
153
            return None
 
154
        output = get_output(['bzr', 'revno'], cwd = self.srcdir)
 
155
        return output.strip()
117
156
 
118
157
 
119
158
register_repo_type('bzr', BzrRepository)