source: tailor/vcpx/source.py @ 15

Revision 15, 2.5 KB checked in by lele@…, 9 years ago (diff)

Dual working directories

Line 
1#! /usr/bin/python
2# -*- mode: python; coding: utf-8 -*-
3# :Progetto: vcpx -- Updatable VC working directory
4# :Creato:   mer 09 giu 2004 13:55:35 CEST
5# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
6#
7
8"""
9Updatable sources are the simplest abstract wrappers around a working
10directory under some kind of version control system.
11"""
12
13__docformat__ = 'reStructuredText'
14
15
16class UpdatableSourceWorkingDir(object):
17    """This is an abstract working dir. Subclasses MUST override at least
18       the _underscoredMethods."""
19
20    def _getUpstreamChangesets(self, root):
21        """
22        Do the actual work of fetching the upstream changeset.
23       
24        This method must be overridden by subclasses.
25        """
26
27        raise "%s should override this method" % self.__class__
28       
29    def _applyChangeset(self, root, changeset):
30        """
31        Do the actual work of applying the changeset to the working copy.
32        """
33
34        raise "%s should override this method" % self.__class__
35
36    def collectUpstreamChangesets(self, root):
37        """
38        Query the upstream repository about what happened on the
39        sources since last sync, returning a sequence of Changesets
40        instances.
41        """
42
43        return self._getUpstreamChangesets(self, root)
44       
45    def applyUpstreamChangesets(self, root, changesets, replay=None):
46        """
47        Apply the collected upstream changes.
48
49        Loop over the collected changesets, doing whatever is needed
50        to apply each one to the working dir and if the changes do
51        not raise conflicts call the `replay` function to mirror the
52        changes on the target.
53
54        Return a sequence (potentially empty!) of conflicts.
55        """
56
57        conflicts = []
58        for c in changesets:
59            res = self._applyChangeset(root, c)
60            if res:
61                conflicts.append((c, res))
62            else:
63                if replay:
64                    replay(root, c)
65                   
66        return conflicts
67       
68    def checkoutUpstreamRevision(self, root, repository, revision):
69        """
70        Extract a working copy from a repository.
71        """
72
73        from os.path import split
74
75        basedir,module = split(root)
76       
77        self._checkoutUpstreamRevision(basedir, repository, module, revision)
78       
79    def _checkoutUpstreamRevision(self, basedir, repository, module, revision):
80        """
81        Concretely do the checkout of the upstream revision.
82        """
83       
84        raise "%s should override this method" % self.__class__
Note: See TracBrowser for help on using the repository browser.