source: tailor/vcpx/dualwd.py @ 681

Revision 681, 3.3 KB checked in by lele@…, 8 years ago (diff)

Set 'shared_basedirs' on both source and target backend
This allows backends to choose a different strategy to protect
themselves from the other end.

Line 
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"""
9The easiest way to propagate changes from one VC control system to one
10of an another kind is having a single directory containing a live
11working copy shared between the two VC systems.
12
13In a slightly more elaborated way, the source and the target system may
14use separate directories, that gets rsynced when needed.
15
16This module implements `DualWorkingDir`, which instances have a
17`source` and `target` properties offering the right capabilities to do
18the job.
19"""
20
21__docformat__ = 'reStructuredText'
22
23from source import UpdatableSourceWorkingDir, InvocationError
24from target import SyncronizableTargetWorkingDir
25from shwrap import ExternalCommand
26
27IGNORED_METADIRS = []
28
29class 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
53        # UpdatableSourceWorkingDir
54
55        self.getPendingChangesets = self.source.getPendingChangesets
56        self.checkoutUpstreamRevision = self.source.checkoutUpstreamRevision
57
58        # SyncronizableTargetWorkingDir
59
60        self.prepareWorkingDirectory = self.target.prepareWorkingDirectory
61
62    def setStateFile(self, state_file):
63        """
64        Set the state file used to store the revision and pending changesets.
65        """
66
67        self.source.setStateFile(state_file)
68        self.target.setStateFile(state_file)
69
70    def setLogfile(self, logfile):
71        """
72        Set the name of the logfile, just to ignore it.
73        """
74
75        self.target.logfile = logfile
76
77    def applyPendingChangesets(self, applyable=None, replay=None, applied=None):
78        return self.source.applyPendingChangesets(replay=self.replayChangeset,
79                                                  applyable=applyable,
80                                                  applied=applied)
81
82    def importFirstRevision(self, source_repo, changeset, initial):
83        if not self.shared_basedirs:
84            self._syncTargetWithSource()
85        self.target.importFirstRevision(source_repo, changeset, initial)
86
87    def replayChangeset(self, changeset):
88        if not self.shared_basedirs:
89            self._syncTargetWithSource()
90        self.target.replayChangeset(changeset)
91
92    def _syncTargetWithSource(self):
93        cmd = ['rsync', '--delete', '--archive',
94               '--exclude', self.source.repository.METADIR,
95               '--exclude', self.target.repository.METADIR]
96        rsync = ExternalCommand(command=cmd)
97        rsync.execute(self.source.basedir+'/', self.target.basedir)
Note: See TracBrowser for help on using the repository browser.