| 1 | #! /usr/bin/python |
|---|
| 2 | # -*- mode: python; coding: utf-8 -*- |
|---|
| 3 | # :Progetto: vcpx -- Syncable targets |
|---|
| 4 | # :Creato: ven 04 giu 2004 00:27:07 CEST |
|---|
| 5 | # :Autore: Lele Gaifax <lele@nautilus.homeip.net> |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | """ |
|---|
| 9 | Syncronizable targets are the simplest abstract wrappers around a |
|---|
| 10 | working directory under two different version control systems. |
|---|
| 11 | """ |
|---|
| 12 | |
|---|
| 13 | __docformat__ = 'reStructuredText' |
|---|
| 14 | |
|---|
| 15 | PATCH_AUTHOR = "tailor@localhost" |
|---|
| 16 | |
|---|
| 17 | class SyncronizableTargetWorkingDir(object): |
|---|
| 18 | """ |
|---|
| 19 | This is an abstract working dir. Subclasses MUST override at least |
|---|
| 20 | the _underscoredMethods. |
|---|
| 21 | """ |
|---|
| 22 | |
|---|
| 23 | def replayChangeset(self, root, changeset): |
|---|
| 24 | """ |
|---|
| 25 | Do whatever is needed to replay the changes under the target |
|---|
| 26 | VC, to register the already applied changeset. |
|---|
| 27 | """ |
|---|
| 28 | |
|---|
| 29 | for e in changeset.entries: |
|---|
| 30 | if e.action_kind == e.RENAMED: |
|---|
| 31 | self._renameEntry(root, e.old_name, e.name) |
|---|
| 32 | elif e.action_kind == e.ADDED: |
|---|
| 33 | self._addEntry(root, e.name) |
|---|
| 34 | elif e.action_kind == e.DELETED: |
|---|
| 35 | self._removeEntry(root, e.name) |
|---|
| 36 | |
|---|
| 37 | def commitChangeset(self, root, changeset): |
|---|
| 38 | """ |
|---|
| 39 | Commit the changeset. |
|---|
| 40 | """ |
|---|
| 41 | |
|---|
| 42 | remark = 'Upstream changeset %s' % changeset.revision |
|---|
| 43 | changelog = changeset.log |
|---|
| 44 | entries = [e.name for e in changeset.entries] |
|---|
| 45 | self._commit(root, changeset.author, remark, changelog, entries) |
|---|
| 46 | |
|---|
| 47 | def _addEntry(self, root, entry): |
|---|
| 48 | """ |
|---|
| 49 | Add a new entry, maybe registering the directory as well. |
|---|
| 50 | """ |
|---|
| 51 | |
|---|
| 52 | raise "%s should override this method" % self.__class__ |
|---|
| 53 | |
|---|
| 54 | def _commit(self, root, author, remark, changelog=None, entries=None): |
|---|
| 55 | """ |
|---|
| 56 | Commit the changeset. |
|---|
| 57 | """ |
|---|
| 58 | |
|---|
| 59 | raise "%s should override this method" % self.__class__ |
|---|
| 60 | |
|---|
| 61 | def _removeEntry(self, root, entry): |
|---|
| 62 | """ |
|---|
| 63 | Remove an entry. |
|---|
| 64 | """ |
|---|
| 65 | |
|---|
| 66 | raise "%s should override this method" % self.__class__ |
|---|
| 67 | |
|---|
| 68 | def _renameEntry(self, root, oldentry, newentry): |
|---|
| 69 | """ |
|---|
| 70 | Rename an entry. |
|---|
| 71 | """ |
|---|
| 72 | |
|---|
| 73 | raise "%s should override this method" % self.__class__ |
|---|
| 74 | |
|---|
| 75 | def initializeNewWorkingDir(self, root, repository, revision): |
|---|
| 76 | """ |
|---|
| 77 | Initialize a new working directory, just extracted under |
|---|
| 78 | some other VC system, add everything's there. |
|---|
| 79 | """ |
|---|
| 80 | |
|---|
| 81 | self._initializeWorkingDir(root) |
|---|
| 82 | self._commit(root, PATCH_AUTHOR, |
|---|
| 83 | 'Tailorization of %s@%s' % (repository, revision)) |
|---|
| 84 | |
|---|
| 85 | def _initializeWorkingDir(self, root): |
|---|
| 86 | """ |
|---|
| 87 | Do whatever is needed to put the given directory under revision |
|---|
| 88 | control. |
|---|
| 89 | """ |
|---|
| 90 | |
|---|
| 91 | raise "%s should override this method" % self.__class__ |
|---|
| 92 | |
|---|