source: tailor/vcpx/arx.py @ 527

Revision 527, 2.8 KB checked in by lele@…, 8 years ago (diff)

Big API change, reducing arguments in favour of instance attributes
This is a big and subtle change that brings nothing in term of
functionality but make it a lot easier maintaining and extending
tailor as a whole.

Basically, 'root' and 'subdir' arguments are gone replaced by a
self.basedir, computed from the configuration; instead of 'logger',
the code uses two new methods, log_info() and log_error() on most
objects. Other arguments are derived from the configuration objects
that hang around.

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- ArX stuff
3# :Creato:   ven 24 giu 2005 20:42:46 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7# Modified 2005 by Walter Landry for ArX
8
9"""
10This module implements the backends for ArX.
11"""
12
13__docformat__ = 'reStructuredText'
14
15from shwrap import ExternalCommand, PIPE, ReopenableNamedTemporaryFile
16from target import SyncronizableTargetWorkingDir, TargetInitializationFailure
17
18class ArxWorkingDir(SyncronizableTargetWorkingDir):
19
20    ## SyncronizableTargetWorkingDir
21
22    def _addPathnames(self, names):
23        """
24        Add some new filesystem objects.
25        """
26
27        cmd = [self.repository.ARX_CMD, "add"]
28        ExternalCommand(cwd=self.basedir, command=cmd).execute(names)
29
30    def _commit(self, date, author, patchname, changelog=None, entries=None):
31        """
32        Commit the changeset.
33        """
34
35        from time import mktime
36        from sys import getdefaultencoding
37
38        encoding = ExternalCommand.FORCE_ENCODING or getdefaultencoding()
39
40        logmessage = ""
41        if patchname:
42            logmessage=patchname.encode(encoding)
43        if changelog:
44            if logmessage!="":
45                logmessage+="\n\n"+changelog.encode(encoding)
46            else:
47                logmessage=changelog.encode(encoding)
48
49        if logmessage=="":
50            logmessage=" "
51
52        cmd = [self.repository.ARX_CMD, "commit", "-s", logmessage,
53               "--author", author,
54               "--date", date.isoformat()]
55        c = ExternalCommand(cwd=self.basedir, command=cmd)
56        c.execute()
57
58    def _removePathnames(self, names):
59        """
60        Remove some filesystem object.
61        """
62
63        cmd = [self.repository.ARX_CMD, "rm"]
64        ExternalCommand(cwd=self.basedir, command=cmd).execute(names)
65
66    def _renamePathname(self, oldname, newname):
67        """
68        Rename a filesystem object.
69        """
70
71        cmd = [self.repository.ARX_CMD, "copy"]
72        rename = ExternalCommand(cwd=self.basedir, command=cmd)
73        rename.execute(oldname, newname)
74
75    def _initializeWorkingDir(self):
76        """
77        Setup the ArX working copy
78
79        The user must setup a ArX working directory himself. Then
80        we simply use 'arx commit', without having to specify an archive
81        or branch. ArX looks up the archive and branch in it's _arx
82        directory.
83        """
84
85        from os.path import exists, join
86        from dircache import listdir
87        from dualwd import IGNORED_METADIRS
88        from os import walk
89
90        if not exists(join(self.basedir, '_arx')):
91            raise TargetInitializationFailure("Please setup '%s' as an ArX working directory" % self.basedir)
92
93        SyncronizableTargetWorkingDir._initializeWorkingDir(self)
Note: See TracBrowser for help on using the repository browser.