| 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 | """ |
|---|
| 9 | This module implements the backends for Codeville. |
|---|
| 10 | """ |
|---|
| 11 | |
|---|
| 12 | __docformat__ = 'reStructuredText' |
|---|
| 13 | |
|---|
| 14 | from shwrap import ExternalCommand, PIPE |
|---|
| 15 | from target import SyncronizableTargetWorkingDir, TargetInitializationFailure |
|---|
| 16 | |
|---|
| 17 | class CdvWorkingDir(SyncronizableTargetWorkingDir): |
|---|
| 18 | |
|---|
| 19 | ## SyncronizableTargetWorkingDir |
|---|
| 20 | |
|---|
| 21 | def _addPathnames(self, names): |
|---|
| 22 | """ |
|---|
| 23 | Add some new filesystem objects. |
|---|
| 24 | """ |
|---|
| 25 | |
|---|
| 26 | cmd = [self.repository.CDV_CMD, "add"] |
|---|
| 27 | ExternalCommand(cwd=self.basedir, command=cmd).execute(names) |
|---|
| 28 | |
|---|
| 29 | def _commit(self, date, author, patchname, changelog=None, entries=None): |
|---|
| 30 | """ |
|---|
| 31 | Commit the changeset. |
|---|
| 32 | """ |
|---|
| 33 | |
|---|
| 34 | from sys import getdefaultencoding |
|---|
| 35 | |
|---|
| 36 | encoding = ExternalCommand.FORCE_ENCODING or getdefaultencoding() |
|---|
| 37 | |
|---|
| 38 | logmessage = [] |
|---|
| 39 | if patchname: |
|---|
| 40 | logmessage.append(patchname.encode(encoding)) |
|---|
| 41 | if changelog: |
|---|
| 42 | logmessage.append(changelog.replace('%', '%%').encode(encoding)) |
|---|
| 43 | logmessage.append('') |
|---|
| 44 | |
|---|
| 45 | cmd = [self.repository.CDV_CMD, "-u", author.encode(encoding), "commit", |
|---|
| 46 | "-m", '\n'.join(logmessage), |
|---|
| 47 | "-D", date.strftime('%Y/%m/%d %H:%M:%S UTC')] |
|---|
| 48 | |
|---|
| 49 | if not entries: |
|---|
| 50 | entries = ['.'] |
|---|
| 51 | |
|---|
| 52 | ExternalCommand(cwd=self.basedir, command=cmd).execute(entries) |
|---|
| 53 | |
|---|
| 54 | def _removePathnames(self, names): |
|---|
| 55 | """ |
|---|
| 56 | Remove some filesystem object. |
|---|
| 57 | """ |
|---|
| 58 | |
|---|
| 59 | cmd = [self.repository.CDV_CMD, "remove"] |
|---|
| 60 | ExternalCommand(cwd=self.basedir, command=cmd).execute(names) |
|---|
| 61 | |
|---|
| 62 | def _renamePathname(self, oldname, newname): |
|---|
| 63 | """ |
|---|
| 64 | Rename a filesystem object. |
|---|
| 65 | """ |
|---|
| 66 | |
|---|
| 67 | cmd = [self.repository.CDV_CMD, "rename"] |
|---|
| 68 | ExternalCommand(cwd=self.basedir, command=cmd).execute(oldname, newname) |
|---|
| 69 | |
|---|
| 70 | def initializeNewWorkingDir(self, source_repo, changeset, initial): |
|---|
| 71 | """ |
|---|
| 72 | Initialize a new working directory, just extracted from |
|---|
| 73 | some other VC system, importing everything's there. |
|---|
| 74 | """ |
|---|
| 75 | |
|---|
| 76 | from target import AUTHOR, HOST, BOOTSTRAP_PATCHNAME, \ |
|---|
| 77 | BOOTSTRAP_CHANGELOG |
|---|
| 78 | |
|---|
| 79 | self._initializeWorkingDir() |
|---|
| 80 | revision = changeset.revision |
|---|
| 81 | source_repository = source_repo.repository |
|---|
| 82 | source_module = source_repo.module or '' |
|---|
| 83 | if initial: |
|---|
| 84 | author = changeset.author |
|---|
| 85 | patchname = changeset.log |
|---|
| 86 | log = None |
|---|
| 87 | else: |
|---|
| 88 | author = "%s@%s" % (AUTHOR, HOST) |
|---|
| 89 | patchname = BOOTSTRAP_PATCHNAME |
|---|
| 90 | log = BOOTSTRAP_CHANGELOG % locals() |
|---|
| 91 | self._commit(changeset.date, author, patchname, log, |
|---|
| 92 | entries=['%s/...' % self.basedir]) |
|---|
| 93 | |
|---|
| 94 | def _initializeWorkingDir(self): |
|---|
| 95 | """ |
|---|
| 96 | Execute ``cdv init``. |
|---|
| 97 | """ |
|---|
| 98 | |
|---|
| 99 | from os import getenv |
|---|
| 100 | from os.path import join |
|---|
| 101 | |
|---|
| 102 | init = ExternalCommand(cwd=self.basedir, |
|---|
| 103 | command=[self.repository.CDV_CMD, "init"]) |
|---|
| 104 | init.execute() |
|---|
| 105 | |
|---|
| 106 | if init.exit_status: |
|---|
| 107 | raise TargetInitializationFailure( |
|---|
| 108 | "%s returned status %s" % (str(init), init.exit_status)) |
|---|
| 109 | |
|---|
| 110 | cmd = [self.repository.CDV_CMD, "set", "user"] |
|---|
| 111 | user = getenv('CDV_USER') or getenv('LOGNAME') |
|---|
| 112 | ExternalCommand(cwd=self.basedir, command=cmd).execute(user) |
|---|
| 113 | |
|---|
| 114 | SyncronizableTargetWorkingDir._initializeWorkingDir(self) |
|---|