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