source: tailor/vcpx/repository.py @ 484

Revision 484, 2.9 KB checked in by lele@…, 8 years ago (diff)

Force the svn module to start with a slash

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Configuration details about known repository kinds
3# :Creato:   gio 04 ago 2005 13:32:55 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7
8"""
9This module holds a simple abstraction of what a repository is for
10Tailor purposes.
11"""
12
13__docformat__ = 'reStructuredText'
14
15class Repository(object):
16    """
17    Collector for the configuration of a single repository.
18    """
19
20    def __init__(self, name, kind, config, which):
21        self.name = name
22        self.kind = kind
23        self._load(config, which)
24
25    def __str__(self):
26        return "%s repository at %s" % (self.kind, self.repository)
27
28    def _load(self, config, which):
29        """
30        Load the configuration for this repository.
31
32        The two main and mandatory attributes, ``repository`` and ``module``
33        can be specified either on the specific slot in the config file, or
34        as ``source-repository`` (or ``target-repository``) in its [DEFAULT]
35        section.
36        """
37
38        from os.path import split
39
40        self.repository = config.get(self.name, 'repository') or \
41                          config.get(self.name, '%s-repository' % which)
42        self.module = config.get(self.name, 'module') or \
43                      config.get(self.name, '%s-module' % which)
44        if not self.module:
45            self.module = split(self.repository)[1]
46
47    def workingDir(self):
48        """
49        Return an instance of the specific WorkingDir for this kind of
50        repository.
51        """
52
53        wdname = self.kind.capitalize() + 'WorkingDir'
54        modname = 'vcpx.' + self.kind
55        try:
56            wdmod = __import__(modname, globals(), locals(), [wdname])
57            workingdir = getattr(wdmod, wdname)
58        except (AttributeError, ImportError):
59            raise InvocationError("Unhandled source VCS kind: " + self.kind)
60        return workingdir()
61
62
63class ArxRepository(Repository):
64    METADIR = '_arx'
65
66class BzrRepository(Repository):
67    METADIR = '.bzr'
68
69
70class CdvRepository(Repository):
71    METADIR = '.cdv'
72
73
74class CvsRepository(Repository):
75    METADIR = 'CVS'
76
77
78class CvspsRepository(CvsRepository):
79    pass
80
81
82class DarcsRepository(Repository):
83    METADIR = '_darcs'
84
85
86class HgRepository(Repository):
87    METADIR = '.hg'
88
89
90class MonotoneRepository(Repository):
91    METADIR = 'MT'
92
93    def _load(self, config, which):
94        Repository._load(self, config, which)
95        self.passphrase = config.get(self.name, 'passphrase')
96
97
98class SvnRepository(Repository):
99    METADIR = '.svn'
100
101    def _load(self, config, which):
102        Repository._load(self, config, which)
103        self.use_propset = config.get(self.name, 'use-propset', False)
104        if not self.module.startswith('/'):
105            self.module = '/' + self.module
106
107    def workingDir(self):
108        wd = Repository.workingDir(self)
109        wd.USE_PROPSET = self.use_propset
110        return wd
Note: See TracBrowser for help on using the repository browser.