source: tailor/vcpx/monotone.py @ 450

Revision 450, 3.4 KB checked in by lele@…, 8 years ago (diff)

M-x whitespace-cleanup

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Monotone details
3# :Creato:   Tue Apr 12 01:28:10 CEST 2005
4# :Autore:   Markus Schiltknecht <markus@bluegap.ch>
5# :Licenza:  GNU General Public License
6#
7
8"""
9This module contains supporting classes for Monotone.
10"""
11
12__docformat__ = 'reStructuredText'
13
14from shwrap import ExternalCommand, PIPE, ReopenableNamedTemporaryFile
15from source import UpdatableSourceWorkingDir, \
16     ChangesetApplicationFailure, GetUpstreamChangesetsFailure
17from target import SyncronizableTargetWorkingDir, TargetInitializationFailure
18from sys import stderr
19
20MONOTONE_CMD = "monotone"
21
22class MonotoneWorkingDir(SyncronizableTargetWorkingDir):
23
24    ## SyncronizableTargetWorkingDir
25
26    def _addPathnames(self, root, names):
27        """
28        Add some new filesystem objects.
29        """
30
31        cmd = [MONOTONE_CMD, "add"]
32        add = ExternalCommand(cwd=root, command=cmd)
33        add.execute(names)
34
35    def _commit(self,root, date, author, remark, changelog=None, entries=None):
36        """
37        Commit the changeset.
38        """
39
40        from sys import getdefaultencoding
41
42        encoding = ExternalCommand.FORCE_ENCODING or getdefaultencoding()
43
44        logmessage = []
45        if remark:
46            logmessage.append(remark.encode(encoding))
47        if changelog:
48            logmessage.append('')
49            logmessage.append(changelog.encode(encoding))
50        logmessage.append('')
51
52        rontf = ReopenableNamedTemporaryFile('mtn', 'tailor')
53        log = open(rontf.name, "w")
54        log.write('\n'.join(logmessage))
55        log.close()
56
57        cmd = [MONOTONE_CMD, "commit", "--author", author,
58               "--date", date.isoformat(),
59               "--message-file", rontf.name]
60        commit = ExternalCommit(cwd=root, command=cmd)
61
62        if not entries:
63            entries = ['.']
64
65        output = commit.execute(entries, stdout=PIPE)
66
67        # monotone complaints if there are no changes from the last commit.
68        # we ignore those errors ...
69        if commit.exit_status:
70            text = output.read()
71            if text.find("monotone: misuse: no changes to commit") == -1:
72                stderr.write(text)
73                raise TargetInitializationFailure(
74                    "%s returned status %s" % (str(commit),commit.exit_status))
75            else:
76                stderr.write("No changes to commit - changeset ignored\n")
77
78    def _removePathnames(self, root, names):
79        """
80        Remove some filesystem object.
81        """
82
83        cmd = [MONOTONE_CMD, "drop"]
84        drop = ExternalCommand(cwd=root, command=cmd)
85        drop.execute(names)
86
87    def _renamePathname(self, root, oldname, newname):
88        """
89        Rename a filesystem object.
90        """
91
92        cmd = [MONOTONE_CMD, "rename"]
93        rename = ExternalCommand(cwd=root, command=cmd)
94        rename.execute(oldname, newname)
95
96    def _initializeWorkingDir(self, root, repository, module, subdir):
97        """
98        Setup the monotone working copy
99
100        The user must setup a monotone working directory himself. Then
101        we simply use 'monotone commit', without having to specify a database
102        file or branch. Monotone looks up the database and branch in it's MT
103        directory.
104        """
105
106        from os.path import exists, join
107
108        if not exists(join(root, 'MT')):
109            raise TargetInitializationFailure("Please setup '%s' as a monotone working directory" % root)
110
111        self._addPathnames(root, [subdir])
Note: See TracBrowser for help on using the repository browser.