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