source: tailor/vcpx/bzr.py @ 433

Revision 433, 3.8 KB checked in by lele@…, 8 years ago (diff)

Uniquify the mechanism of computing the destination changelog
Now all targets share a similar mechanism to compute the changelog of
the committed patch, honoring the eventual encoding and skipping missing
parts.

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- bazaar-ng support
3# :Creato:   ven 20 mag 2005 08:15:02 CEST
4# :Autore:   Johan Rydberg <jrydberg@gnu.org>
5# :Licenza:  GNU General Public License
6#
7
8"""
9This module implements the backends for Bazaar-NG.
10"""
11
12__docformat__ = 'reStructuredText'
13
14from target import SyncronizableTargetWorkingDir, TargetInitializationFailure
15from shwrap import ExternalCommand
16
17BAZAAR_CMD = 'bzr'
18   
19class BzrWorkingDir(SyncronizableTargetWorkingDir):
20
21    ## SyncronizableTargetWorkingDir
22
23    def _addEntries(self, root, entries):
24        """
25        Add a sequence of entries.
26        """
27
28        cmd = [BAZAAR_CMD, "add"]
29        ExternalCommand(cwd=root, command=cmd).execute(entries)
30
31    def _commit(self,root, date, author, remark, changelog=None, entries=None):
32        """
33        Commit the changeset.
34        """
35
36        from sys import getdefaultencoding
37       
38        encoding = ExternalCommand.FORCE_ENCODING or getdefaultencoding()
39       
40        logmessage = []
41        if remark:
42            logmessage.append(remark.encode(encoding))
43        if changelog:
44            logmessage.append(changelog.encode(encoding))
45        logmessage.append('')
46        logmessage.append('Original author: %s' % author.encode(encoding))
47        logmessage.append('Date: %s' % date)
48        logmessage.append('')
49
50        cmd = [BAZAAR_CMD, "commit", "-m", '\n'.join(logmessage)]
51        if not entries:
52            entries = ['.']
53
54        ExternalCommand(cwd=root, command=cmd).execute(entries)
55       
56    def _removeEntries(self, root, entries):
57        """
58        Remove a sequence of entries.
59        """
60
61        cmd = [BAZAAR_CMD, "remove"]
62        ExternalCommand(cwd=root, command=cmd).execute(entries)
63
64    def _renameEntry(self, root, oldentry, newentry):
65        """
66        Rename an entry.
67        """
68
69        cmd = [BAZAAR_CMD, "rename"]
70        ExternalCommand(cwd=root, command=cmd).execute(old, new)
71
72    def initializeNewWorkingDir(self, root, repository, module, subdir,
73                                changeset, initial):
74        """
75        Initialize a new working directory, just extracted from
76        some other VC system, importing everything's there.
77        """
78
79        from target import AUTHOR, HOST, BOOTSTRAP_PATCHNAME, \
80             BOOTSTRAP_CHANGELOG
81
82        self._initializeWorkingDir(root, repository, module, subdir)
83        revision = changeset.revision
84        if initial:
85            author = changeset.author
86            remark = changeset.log
87            log = None
88        else:
89            author = "%s@%s" % (AUTHOR, HOST)
90            remark = BOOTSTRAP_PATCHNAME % module
91            log = BOOTSTRAP_CHANGELOG % locals()
92        self._commit(root, changeset.date, author, remark, log,
93                     entries=[subdir, '%s/...' % subdir])
94
95    def _initializeWorkingDir(self, root, repository, module, subdir):
96        """
97        Execute ``bzr init``.
98        """
99
100        from os import getenv
101        from os.path import join
102        from dualwd import IGNORED_METADIRS
103
104        cmd = [BAZAAR_CMD, "init"]
105        init = ExternalCommand(cwd=root, command=cmd)
106        init.execute()
107
108        if init.exit_status:
109            raise TargetInitializationFailure(
110                "%s returned status %s" % (str(init), init.exit_status))
111
112        # Create the .bzrignore file, that contains a glob per line,
113        # with all known VCs metadirs to be skipped.
114        ignore = open(join(root, '.hgignore'), 'w')
115        ignore.write('\n'.join(['(^|/)%s($|/)' % md
116                                for md in IGNORED_METADIRS]))
117        ignore.write('\ntailor.log\ntailor.info\n')
118        ignore.close()
119
120        SyncronizableTargetWorkingDir._initializeWorkingDir(self, root,
121                                                            repository, module,
122                                                            subdir)
Note: See TracBrowser for help on using the repository browser.