source: tailor/vcpx/cdv.py @ 380

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

Do not suggest every source is a script by itself

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Codeville details
3# :Creato:   gio 05 mag 2005 23:47:45 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7
8"""
9This module implements the backends for Codeville.
10"""
11
12__docformat__ = 'reStructuredText'
13
14from shwrap import SystemCommand, shrepr
15from target import SyncronizableTargetWorkingDir, TargetInitializationFailure
16
17class CdvCommit(SystemCommand):
18    COMMAND = "cdv -u %(user)s commit -m %(comment)s -D '%(time)s' %(entries)s"
19
20    def __call__(self, output=None, dry_run=False, **kwargs):
21        logmessage = kwargs.get('logmessage')
22        kwargs['comment'] = shrepr(logmessage)
23        author = kwargs.get('author')
24        kwargs['user'] = shrepr(author)
25        kwargs['time'] = kwargs.get('date').strftime('%Y/%m/%d %H:%M:%S UTC')
26       
27        return SystemCommand.__call__(self, output=output,
28                                      dry_run=dry_run, **kwargs)
29   
30
31class CdvWorkingDir(SyncronizableTargetWorkingDir):
32
33    ## SyncronizableTargetWorkingDir
34
35    def _addPathnames(self, root, names):
36        """
37        Add some new filesystem objects.
38        """
39
40        c = SystemCommand(working_dir=root, command="cdv add %(names)s")
41        c(names=' '.join([shrepr(n) for n in names]))
42
43    def _commit(self,root, date, author, remark, changelog=None, entries=None):
44        """
45        Commit the changeset.
46        """
47
48        c = CdvCommit(working_dir=root)
49       
50        if changelog:
51            logmessage = remark + '\n\n' + changelog
52        else:
53            logmessage = remark
54           
55        if entries:
56            entries = ' '.join([shrepr(e) for e in entries])
57        else:
58            entries = '.'
59           
60        c(author=author, logmessage=logmessage, date=date, entries=entries)
61       
62    def _removePathnames(self, root, names):
63        """
64        Remove some filesystem object.
65        """
66
67        c = SystemCommand(working_dir=root, command="cdv remove %(names)s")
68        c(names=' '.join([shrepr(n) for n in names]))
69
70    def _renamePathname(self, root, oldname, newname):
71        """
72        Rename a filesystem object.
73        """
74
75        c = SystemCommand(working_dir=root,
76                          command="cdv rename %(old)s %(new)s")
77        c(old=shrepr(oldname), new=repr(newname))
78
79    def initializeNewWorkingDir(self, root, repository, module, subdir, revision):
80        """
81        Initialize a new working directory, just extracted from
82        some other VC system, importing everything's there.
83        """
84
85        from datetime import datetime
86        from target import AUTHOR, HOST, BOOTSTRAP_PATCHNAME, \
87             BOOTSTRAP_CHANGELOG
88       
89        now = datetime.now()
90        self._initializeWorkingDir(root, repository, module, subdir)
91        self._commit(root, now, '%s@%s' % (AUTHOR, HOST),
92                     BOOTSTRAP_PATCHNAME % module,
93                     BOOTSTRAP_CHANGELOG % locals(),
94                     entries=[subdir, '%s/...' % subdir])
95
96    def _initializeWorkingDir(self, root, repository, module, subdir):
97        """
98        Execute ``cdv init``.
99        """
100
101        from os import getenv
102        from os.path import join
103       
104        c = SystemCommand(working_dir=root, command="cdv init")
105        c(output=True)
106
107        if c.exit_status:
108            raise TargetInitializationFailure(
109                "'cdv init' returned status %s" % c.exit_status)
110
111        c = SystemCommand(working_dir=root, command="cdv set user %(user)s")
112        c(user=getenv('CDV_USER') or getenv('LOGNAME'))
113       
114        SyncronizableTargetWorkingDir._initializeWorkingDir(self, root,
115                                                            repository, module,
116                                                            subdir)
Note: See TracBrowser for help on using the repository browser.