source: tailor/vcpx/dualwd.py @ 608

Revision 608, 3.1 KB checked in by lele@…, 8 years ago (diff)

Allow disjunct working directories
If the source and target repository use different directories, use
rsync to keep the target aligned with source, after the initial
checkout and right after the application of the upstream patch.

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.target = target_repo.workingDir()
43
44        IGNORED_METADIRS = [source_repo.METADIR, target_repo.METADIR]
45
46        # UpdatableSourceWorkingDir
47
48        self.getPendingChangesets = self.source.getPendingChangesets
49        self.checkoutUpstreamRevision = self.source.checkoutUpstreamRevision
50
51        # SyncronizableTargetWorkingDir
52
53        self.prepareWorkingDirectory = self.target.prepareWorkingDirectory
54
55    def setStateFile(self, state_file):
56        """
57        Set the state file used to store the revision and pending changesets.
58        """
59
60        self.source.setStateFile(state_file)
61        self.target.setStateFile(state_file)
62
63    def setLogfile(self, logfile):
64        """
65        Set the name of the logfile, just to ignore it.
66        """
67
68        self.target.logfile = logfile
69
70    def applyPendingChangesets(self, applyable=None, replay=None, applied=None):
71        return self.source.applyPendingChangesets(replay=self.replayChangeset,
72                                                  applyable=applyable,
73                                                  applied=applied)
74
75    def importFirstRevision(self, source_repo, changeset, initial):
76        if self.source.basedir <> self.target.basedir:
77            self._syncTargetWithSource()
78        self.target.importFirstRevision(source_repo, changeset, initial)
79
80    def replayChangeset(self, changeset):
81        if self.source.basedir <> self.target.basedir:
82            self._syncTargetWithSource()
83        self.target.replayChangeset(changeset)
84
85    def _syncTargetWithSource(self):
86        cmd = ['rsync', '--delete', '--archive',
87               '--exclude', self.source.repository.METADIR,
88               '--exclude', self.target.repository.METADIR]
89        rsync = ExternalCommand(command=cmd)
90        rsync.execute(self.source.basedir+'/', self.target.basedir)
Note: See TracBrowser for help on using the repository browser.