| 1 | # -*- mode: python; coding: utf-8 -*- |
|---|
| 2 | # :Progetto: vcpx -- Dual working directory |
|---|
| 3 | # :Creato: dom 20 giu 2004 11:02:01 CEST |
|---|
| 4 | # :Autore: Lele Gaifax <lele@nautilus.homeip.net> |
|---|
| 5 | # :Licenza: GNU General Public License |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | """ |
|---|
| 9 | The easiest way to propagate changes from one VC control system to one |
|---|
| 10 | of an another kind is having a single directory containing a live |
|---|
| 11 | working copy shared between the two VC systems. |
|---|
| 12 | |
|---|
| 13 | In a slightly more elaborated way, the source and the target system may |
|---|
| 14 | use separate directories, that gets rsynced when needed. |
|---|
| 15 | |
|---|
| 16 | This module implements `DualWorkingDir`, which instances have a |
|---|
| 17 | `source` and `target` properties offering the right capabilities to do |
|---|
| 18 | the job. |
|---|
| 19 | """ |
|---|
| 20 | |
|---|
| 21 | __docformat__ = 'reStructuredText' |
|---|
| 22 | |
|---|
| 23 | from source import UpdatableSourceWorkingDir, InvocationError |
|---|
| 24 | from target import SyncronizableTargetWorkingDir |
|---|
| 25 | from shwrap import ExternalCommand |
|---|
| 26 | |
|---|
| 27 | IGNORED_METADIRS = [] |
|---|
| 28 | |
|---|
| 29 | class DualWorkingDir(UpdatableSourceWorkingDir, SyncronizableTargetWorkingDir): |
|---|
| 30 | """ |
|---|
| 31 | Dual working directory, one that is under two different VC systems at |
|---|
| 32 | the same time. |
|---|
| 33 | |
|---|
| 34 | This class reimplements the two interfaces, dispatching the right method |
|---|
| 35 | to the right backend. |
|---|
| 36 | """ |
|---|
| 37 | |
|---|
| 38 | def __init__(self, source_repo, target_repo): |
|---|
| 39 | global IGNORED_METADIRS |
|---|
| 40 | |
|---|
| 41 | self.source = source_repo.workingDir() |
|---|
| 42 | self.source._prepareSourceRepository() |
|---|
| 43 | |
|---|
| 44 | self.target = target_repo.workingDir() |
|---|
| 45 | self.target._prepareTargetRepository() |
|---|
| 46 | |
|---|
| 47 | self.shared_basedirs = self.source.shared_basedirs = \ |
|---|
| 48 | self.target.shared_basedirs = \ |
|---|
| 49 | self.source.basedir == self.target.basedir |
|---|
| 50 | |
|---|
| 51 | IGNORED_METADIRS = [source_repo.METADIR, target_repo.METADIR] |
|---|
| 52 | IGNORED_METADIRS.extend(source_repo.EXTRA_METADIRS) |
|---|
| 53 | IGNORED_METADIRS.extend(target_repo.EXTRA_METADIRS) |
|---|
| 54 | |
|---|
| 55 | # UpdatableSourceWorkingDir |
|---|
| 56 | |
|---|
| 57 | self.getPendingChangesets = self.source.getPendingChangesets |
|---|
| 58 | self.checkoutUpstreamRevision = self.source.checkoutUpstreamRevision |
|---|
| 59 | |
|---|
| 60 | # SyncronizableTargetWorkingDir |
|---|
| 61 | |
|---|
| 62 | self.prepareWorkingDirectory = self.target.prepareWorkingDirectory |
|---|
| 63 | |
|---|
| 64 | def setStateFile(self, state_file): |
|---|
| 65 | """ |
|---|
| 66 | Set the state file used to store the revision and pending changesets. |
|---|
| 67 | """ |
|---|
| 68 | |
|---|
| 69 | self.source.setStateFile(state_file) |
|---|
| 70 | self.target.setStateFile(state_file) |
|---|
| 71 | |
|---|
| 72 | def setLogfile(self, logfile): |
|---|
| 73 | """ |
|---|
| 74 | Set the name of the logfile, just to ignore it. |
|---|
| 75 | """ |
|---|
| 76 | |
|---|
| 77 | self.target.logfile = logfile |
|---|
| 78 | |
|---|
| 79 | def applyPendingChangesets(self, applyable=None, replay=None, applied=None): |
|---|
| 80 | return self.source.applyPendingChangesets(replay=self.replayChangeset, |
|---|
| 81 | applyable=applyable, |
|---|
| 82 | applied=applied) |
|---|
| 83 | |
|---|
| 84 | def importFirstRevision(self, source_repo, changeset, initial): |
|---|
| 85 | if not self.shared_basedirs: |
|---|
| 86 | self._syncTargetWithSource() |
|---|
| 87 | self.target.importFirstRevision(source_repo, changeset, initial) |
|---|
| 88 | |
|---|
| 89 | def replayChangeset(self, changeset): |
|---|
| 90 | if not self.shared_basedirs: |
|---|
| 91 | self._syncTargetWithSource() |
|---|
| 92 | self.target.replayChangeset(changeset) |
|---|
| 93 | |
|---|
| 94 | def _syncTargetWithSource(self): |
|---|
| 95 | cmd = ['rsync', '--delete', '--archive'] |
|---|
| 96 | for M in IGNORED_METADIRS: |
|---|
| 97 | cmd.extend(['--exclude', M]) |
|---|
| 98 | |
|---|
| 99 | rsync = ExternalCommand(command=cmd) |
|---|
| 100 | rsync.execute(self.source.basedir+'/', self.target.basedir) |
|---|