| 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 | """ |
|---|
| 9 | This module holds a simple abstraction of what a repository is for |
|---|
| 10 | Tailor purposes. |
|---|
| 11 | """ |
|---|
| 12 | |
|---|
| 13 | __docformat__ = 'reStructuredText' |
|---|
| 14 | |
|---|
| 15 | class 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 | |
|---|
| 63 | class ArxRepository(Repository): |
|---|
| 64 | METADIR = '_arx' |
|---|
| 65 | |
|---|
| 66 | class BzrRepository(Repository): |
|---|
| 67 | METADIR = '.bzr' |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | class CdvRepository(Repository): |
|---|
| 71 | METADIR = '.cdv' |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | class CvsRepository(Repository): |
|---|
| 75 | METADIR = 'CVS' |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | class CvspsRepository(CvsRepository): |
|---|
| 79 | pass |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | class DarcsRepository(Repository): |
|---|
| 83 | METADIR = '_darcs' |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | class HgRepository(Repository): |
|---|
| 87 | METADIR = '.hg' |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | class 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 | |
|---|
| 98 | class 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 | |
|---|
| 105 | def workingDir(self): |
|---|
| 106 | wd = Repository.workingDir(self) |
|---|
| 107 | wd.USE_PROPSET = self.use_propset |
|---|
| 108 | return wd |
|---|