source: tailor/vcpx/hg.py @ 377

Revision 377, 3.1 KB checked in by lele@…, 8 years ago (diff)

Preliminary target-only Mercurial backend

Line 
1#! /usr/bin/python
2# -*- mode: python; coding: utf-8 -*-
3# :Progetto: vcpx -- Mercurial stuff
4# :Creato:   ven 24 giu 2005 20:42:46 CEST
5# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
6# :Licenza:  GNU General Public License
7#
8
9"""
10This module implements the backends for Mercurial.
11"""
12
13__docformat__ = 'reStructuredText'
14
15from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile
16from target import SyncronizableTargetWorkingDir, TargetInitializationFailure
17
18class HgCommit(SystemCommand):
19    COMMAND = "hg commit -u %(user)s -l %(logfile)s -d '%(time)s UTC'"
20
21    def __call__(self, output=None, dry_run=False, **kwargs):
22        from time import mktime
23       
24        logmessage = kwargs.get('logmessage')
25        rontf = ReopenableNamedTemporaryFile('hg', 'tailor')
26        log = open(rontf.name, "w")
27        log.write(logmessage)
28        log.close()           
29        kwargs['logfile'] = rontf.name
30        author = kwargs.get('author')
31        kwargs['user'] = shrepr(author)
32        kwargs['time'] = mktime(kwargs.get('date').timetuple())
33       
34        return SystemCommand.__call__(self, output=output,
35                                      dry_run=dry_run, **kwargs)
36   
37
38class HgWorkingDir(SyncronizableTargetWorkingDir):
39
40    ## SyncronizableTargetWorkingDir
41
42    def _addPathnames(self, root, names):
43        """
44        Add some new filesystem objects.
45        """
46
47        c = SystemCommand(working_dir=root, command="hg add %(names)s")
48        c(names=' '.join([shrepr(n) for n in names]))
49
50    def _commit(self,root, date, author, remark, changelog=None, entries=None):
51        """
52        Commit the changeset.
53        """
54
55        c = HgCommit(working_dir=root)
56       
57        if changelog:
58            logmessage = remark + '\n\n' + changelog
59        else:
60            logmessage = remark
61           
62        if entries:
63            entries = ' '.join([shrepr(e) for e in entries])
64        else:
65            entries = '.'
66           
67        c(author=author, logmessage=logmessage, date=date, entries=entries)
68       
69    def _removePathnames(self, root, names):
70        """
71        Remove some filesystem object.
72        """
73
74        c = SystemCommand(working_dir=root, command="hg remove %(names)s")
75        c(names=' '.join([shrepr(n) for n in names]))
76
77    def _renamePathname(self, root, oldname, newname):
78        """
79        Rename a filesystem object.
80        """
81
82        c = SystemCommand(working_dir=root,
83                          command="hg copy %(old)s %(new)s")
84        c(old=shrepr(oldname), new=repr(newname))
85       
86        c = SystemCommand(working_dir=root,
87                          command="hg remove %(old)s")
88        c(old=shrepr(oldname))
89
90    def _initializeWorkingDir(self, root, repository, module, subdir):
91        """
92        Execute ``hg init``.
93        """
94
95        from os import getenv
96        from os.path import join
97       
98        c = SystemCommand(working_dir=root, command="hg init")
99        c(output=True)
100
101        if c.exit_status:
102            raise TargetInitializationFailure(
103                "'hg init' returned status %s" % c.exit_status)
104
105        c = SystemCommand(working_dir=root, command="hg addremove")
106        c()
Note: See TracBrowser for help on using the repository browser.