| 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 | REPO_DESCRIPTION = """\ |
|---|
| 16 | Repository: %s |
|---|
| 17 | Kind: %s""" |
|---|
| 18 | |
|---|
| 19 | class Repository(object): |
|---|
| 20 | """ |
|---|
| 21 | Collector for the configuration of a single repository. |
|---|
| 22 | """ |
|---|
| 23 | METADIR = None |
|---|
| 24 | EXTRA_METADIRS = [] |
|---|
| 25 | |
|---|
| 26 | def __init__(self, name, kind, project, which): |
|---|
| 27 | self.name = name |
|---|
| 28 | self.kind = kind |
|---|
| 29 | self.project = project |
|---|
| 30 | self._load(project.config, which) |
|---|
| 31 | |
|---|
| 32 | def __str__(self): |
|---|
| 33 | |
|---|
| 34 | s = REPO_DESCRIPTION % (self.repository, self.kind) |
|---|
| 35 | if self.module: |
|---|
| 36 | s += "\n Module: %s" % self.module |
|---|
| 37 | return s |
|---|
| 38 | |
|---|
| 39 | def _load(self, config, which): |
|---|
| 40 | """ |
|---|
| 41 | Load the configuration for this repository. |
|---|
| 42 | |
|---|
| 43 | The two main and mandatory attributes, ``repository`` and ``module`` |
|---|
| 44 | can be specified either on the specific slot in the config file, or |
|---|
| 45 | as ``source-repository`` (or ``target-repository``) in its [DEFAULT] |
|---|
| 46 | section. |
|---|
| 47 | |
|---|
| 48 | If the configuration does not specify a specific ``root-directory`` |
|---|
| 49 | take the one from the project. |
|---|
| 50 | """ |
|---|
| 51 | |
|---|
| 52 | from os.path import split, expanduser |
|---|
| 53 | |
|---|
| 54 | self.repository = config.get(self.name, 'repository') or \ |
|---|
| 55 | config.get(self.name, '%s-repository' % which) |
|---|
| 56 | if self.repository: |
|---|
| 57 | self.repository = expanduser(self.repository) |
|---|
| 58 | self.module = config.get(self.name, 'module') or \ |
|---|
| 59 | config.get(self.name, '%s-module' % which) |
|---|
| 60 | self.rootdir = config.get(self.name, 'root-directory', |
|---|
| 61 | vars={'root-directory': self.project.rootdir}) |
|---|
| 62 | self.subdir = config.get(self.name, 'subdir', |
|---|
| 63 | vars={'subdir': self.project.subdir}) |
|---|
| 64 | |
|---|
| 65 | def _validateConfiguration(self): |
|---|
| 66 | """ |
|---|
| 67 | Validate the configuration, possibly altering/completing it. |
|---|
| 68 | """ |
|---|
| 69 | |
|---|
| 70 | def log_info(self, what): |
|---|
| 71 | """ |
|---|
| 72 | Print some info on the log and, in verbose mode, to stdout as well. |
|---|
| 73 | """ |
|---|
| 74 | |
|---|
| 75 | self.project.log_info(what) |
|---|
| 76 | |
|---|
| 77 | def log_error(self, what, exc=False): |
|---|
| 78 | """ |
|---|
| 79 | Print an error message, possibly with an exception traceback, |
|---|
| 80 | to the log and to stdout as well. |
|---|
| 81 | """ |
|---|
| 82 | |
|---|
| 83 | self.project.log_error(what, exc) |
|---|
| 84 | |
|---|
| 85 | def workingDir(self): |
|---|
| 86 | """ |
|---|
| 87 | Return an instance of the specific WorkingDir for this kind of |
|---|
| 88 | repository. |
|---|
| 89 | """ |
|---|
| 90 | |
|---|
| 91 | from source import InvocationError |
|---|
| 92 | |
|---|
| 93 | self._validateConfiguration() |
|---|
| 94 | |
|---|
| 95 | wdname = self.kind.capitalize() + 'WorkingDir' |
|---|
| 96 | modname = 'vcpx.' + self.kind |
|---|
| 97 | try: |
|---|
| 98 | wdmod = __import__(modname, globals(), locals(), [wdname]) |
|---|
| 99 | workingdir = getattr(wdmod, wdname) |
|---|
| 100 | except (AttributeError, ImportError): |
|---|
| 101 | raise InvocationError("Unhandled source VCS kind: " + self.kind) |
|---|
| 102 | |
|---|
| 103 | return workingdir(self) |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | class ArxRepository(Repository): |
|---|
| 107 | METADIR = '_arx' |
|---|
| 108 | ARX_CMD = "arx" |
|---|
| 109 | |
|---|
| 110 | def _load(self, config, which): |
|---|
| 111 | Repository._load(self, config, which) |
|---|
| 112 | self.ARX_CMD = config.get(self.name, 'arx-command', self.ARX_CMD) |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | class BazRepository(Repository): |
|---|
| 116 | METADIR = '{arch}' |
|---|
| 117 | BAZ_CMD = "baz" |
|---|
| 118 | |
|---|
| 119 | def _load(self, config, which): |
|---|
| 120 | Repository._load(self, config, which) |
|---|
| 121 | self.BAZ_CMD = config.get(self.name, 'baz-command', self.BAZ_CMD) |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | class BzrRepository(Repository): |
|---|
| 125 | METADIR = '.bzr' |
|---|
| 126 | BZR_CMD = 'bzr' |
|---|
| 127 | |
|---|
| 128 | def _load(self, config, which): |
|---|
| 129 | Repository._load(self, config, which) |
|---|
| 130 | self.BZR_CMD = config.get(self.name, 'bzr-command', self.BZR_CMD) |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | class BzrngRepository(Repository): |
|---|
| 134 | METADIR = '.bzr' |
|---|
| 135 | |
|---|
| 136 | def _load(self, config, which): |
|---|
| 137 | Repository._load(self, config, which) |
|---|
| 138 | ppath = config.get(self.name, 'python-path') |
|---|
| 139 | if ppath: |
|---|
| 140 | from sys import path |
|---|
| 141 | |
|---|
| 142 | if ppath not in path: |
|---|
| 143 | path.insert(0, ppath) |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | class CdvRepository(Repository): |
|---|
| 147 | METADIR = '.cdv' |
|---|
| 148 | CDV_CMD = 'cdv' |
|---|
| 149 | |
|---|
| 150 | def _load(self, config, which): |
|---|
| 151 | Repository._load(self, config, which) |
|---|
| 152 | self.CDV_CMD = config.get(self.name, 'cdv-command', self.CDV_CMD) |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | class CgRepository(Repository): |
|---|
| 156 | METADIR = '.git' |
|---|
| 157 | CG_CMD = 'cg' |
|---|
| 158 | |
|---|
| 159 | def _load(self, config, which): |
|---|
| 160 | Repository._load(self, config, which) |
|---|
| 161 | self.CG_CMD = config.get(self.name, 'cg-command', self.CG_CMD) |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | class CvsRepository(Repository): |
|---|
| 165 | METADIR = 'CVS' |
|---|
| 166 | CVS_CMD = 'cvs' |
|---|
| 167 | |
|---|
| 168 | def _load(self, config, which): |
|---|
| 169 | Repository._load(self, config, which) |
|---|
| 170 | self.CVS_CMD = config.get(self.name, 'cvs-command', self.CVS_CMD) |
|---|
| 171 | self.tag_entries = config.get(self.name, 'tag-entries', 'True') |
|---|
| 172 | |
|---|
| 173 | def _validateConfiguration(self): |
|---|
| 174 | from os.path import split |
|---|
| 175 | from config import ConfigurationError |
|---|
| 176 | |
|---|
| 177 | if not self.module and self.repository: |
|---|
| 178 | self.module = split(self.repository)[1] |
|---|
| 179 | |
|---|
| 180 | if not self.module: |
|---|
| 181 | raise ConfigurationError("Must specify a repository and maybe " |
|---|
| 182 | "a module also") |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | class CvspsRepository(CvsRepository): |
|---|
| 186 | CVSPS_CMD = 'cvsps' |
|---|
| 187 | |
|---|
| 188 | def _load(self, config, which): |
|---|
| 189 | CvsRepository._load(self, config, which) |
|---|
| 190 | self.CVSPS_CMD = config.get(self.name, 'cvsps-command', self.CVSPS_CMD) |
|---|
| 191 | self.tag_entries = config.get(self.name, 'tag-entries', 'True') |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | class DarcsRepository(Repository): |
|---|
| 195 | METADIR = '_darcs' |
|---|
| 196 | DARCS_CMD = 'darcs' |
|---|
| 197 | |
|---|
| 198 | def _load(self, config, which): |
|---|
| 199 | Repository._load(self, config, which) |
|---|
| 200 | self.DARCS_CMD = config.get(self.name, 'darcs-command', self.DARCS_CMD) |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | class HgRepository(Repository): |
|---|
| 204 | METADIR = '.hg' |
|---|
| 205 | HG_CMD = "hg" |
|---|
| 206 | |
|---|
| 207 | def _load(self, config, which): |
|---|
| 208 | Repository._load(self, config, which) |
|---|
| 209 | self.HG_CMD = config.get(self.name, 'hg-command', self.HG_CMD) |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | class MonotoneRepository(Repository): |
|---|
| 213 | METADIR = 'MT' |
|---|
| 214 | MONOTONE_CMD = "monotone" |
|---|
| 215 | |
|---|
| 216 | def _load(self, config, which): |
|---|
| 217 | Repository._load(self, config, which) |
|---|
| 218 | self.MONOTONE_CMD = config.get(self.name, |
|---|
| 219 | 'monotone-command', self.MONOTONE_CMD) |
|---|
| 220 | self.keyid = config.get(self.name, 'keyid') |
|---|
| 221 | self.passphrase = config.get(self.name, 'passphrase') |
|---|
| 222 | self.keyfile = config.get(self.name, 'keyfile') |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | class SvnRepository(Repository): |
|---|
| 226 | METADIR = '.svn' |
|---|
| 227 | SVN_CMD = "svn" |
|---|
| 228 | SVNADMIN_CMD = "svnadmin" |
|---|
| 229 | |
|---|
| 230 | def _load(self, config, which): |
|---|
| 231 | Repository._load(self, config, which) |
|---|
| 232 | self.SVN_CMD = config.get(self.name, 'svn-command', self.SVN_CMD) |
|---|
| 233 | self.SVNADMIN_CMD = config.get(self.name, |
|---|
| 234 | 'svnadmin-command', self.SVNADMIN_CMD) |
|---|
| 235 | self.use_propset = config.get(self.name, 'use-propset', False) |
|---|
| 236 | |
|---|
| 237 | def _validateConfiguration(self): |
|---|
| 238 | if not self.module: |
|---|
| 239 | raise ConfigurationError("Must the path within the " |
|---|
| 240 | "Subversion repository") |
|---|
| 241 | |
|---|
| 242 | if not self.module.startswith('/'): |
|---|
| 243 | self.project.log_info("Prepending '/' to module") |
|---|
| 244 | self.module = '/' + self.module |
|---|
| 245 | |
|---|
| 246 | def workingDir(self): |
|---|
| 247 | wd = Repository.workingDir(self) |
|---|
| 248 | wd.USE_PROPSET = self.use_propset |
|---|
| 249 | return wd |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | class TlaRepository(Repository): |
|---|
| 253 | METADIR = '{arch}' |
|---|
| 254 | TLA_CMD = "tla" |
|---|
| 255 | |
|---|
| 256 | def _load(self, config, which): |
|---|
| 257 | Repository._load(self, config, which) |
|---|
| 258 | self.TLA_CMD = config.get(self.name, 'tla-command', self.TLA_CMD) |
|---|
| 259 | self.IGNORE_IDS = config.get(self.name, 'ignore-ids', False) |
|---|
| 260 | if self.IGNORE_IDS: |
|---|
| 261 | self.EXTRA_METADIRS = ['.arch-ids'] |
|---|