source: tailor/cvsync/bice.py @ 1

Revision 1, 6.2 KB checked in by lele@…, 9 years ago (diff)

Import current (r861) svn version

Line 
1#! /usr/bin/python
2# -*- mode: python; coding: utf-8 -*-
3# :Progetto: Bice -- Bice Development Team details
4# :Sorgente: $HeadURL: http://svn.bice.dyndns.org/progetti/wip/tools/cvsync/bice.py $
5# :Creato:   sab 08 mag 2004 03:31:42 CEST
6# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
7# :Modifica: $LastChangedDate: 2004-05-08 18:16:38 +0200 (sab, 08 mag 2004) $
8# :Fatta da: $LastChangedBy: lele $
9#
10
11"""
12This module collects Bice specific structures and facilities.
13
14It's commonly used to bootstrap a new project, populating a "Products"
15directory in this way::
16
17  from cvsync.bice import setProductDir, \
18                          register3rdProduct, \
19                          registerOurProduct, \
20                          registerUserProduct
21
22  setProductDir('Products')
23 
24  register3rdProduct('TextIndexNG2')
25  registerUserProduct('AdLSkin')
26  register3rdProduct('GroupUserFolder')
27  registerOurProduct('Archetypes', cvstag='1.3',
28                     subdirs=['Archetypes', 'generator',
29                              'PortalTransforms', 'validation'])
30
31The ``setProductDir`` set the target directory, eventually creating
32it, and should be called as the very first step of the script.  If not
33called, the machinery assumes an already existing "Products" versioned
34directory.
35"""
36
37__docformat__ = 'reStructuredText'
38
39BASEURI = "http://svn.bice.dyndns.org/progetti/"
40"""The root URI of the repository"""
41
42PRODUCTS_DIR = "Products"
43"""The default target directory"""
44
45ALIASES = {
46    "TextIndexNG2": "textindexng",
47    "CMFPlone": "plone",
48    "PloneKeywordManager": "plonekeywordmgr",
49    "PlacelessTranslationService": "pts",
50    "DocFinderEverywhere": "docfinder",
51    }
52"""A dictionary that maps between a ProductName and the alias under which
53it's stored in the "3rd" hierarchy"""
54
55from tailor import Tailorizer
56from os.path import join
57from shwrap import SystemCommand
58
59def bootstrapProduct(product, uri):
60    """
61    Bootstrap a product from the specified URI.
62    """
63
64    class Options:
65        def __init__(self):
66            self.dry_run = False
67            self.message = ""
68
69    options = Options()
70
71    prodwc = join(PRODUCTS_DIR, product)
72    tizer = Tailorizer(prodwc, uri)
73    tizer.bootstrap(options)
74   
75def initProduct(product, uri):
76    """
77    Write upstream information, without bootstrapping the product.
78    """
79
80    prodwc = join(PRODUCTS_DIR, product)
81    tizer = Tailorizer(prodwc, uri)
82    tizer.setUpstreamInfo()
83   
84class BiceProduct(object):
85    """
86    An abstract product.
87    """
88
89    def __init__(self, name, revision=""):
90        self.name = name
91        if revision:
92            self.revision = '@' + revision
93        else:
94            self.revision = ""
95
96    def register(self, bootstrap=True):
97        """
98        Do the actual work.
99
100        Cycle on the components of the product, and call the right function.
101        """
102       
103        from os.path import join
104
105        if bootstrap:
106            func = bootstrapProduct
107        else:
108            func = initProduct
109           
110        components = self.components()
111        for name, pathsegments in components:
112            func(name, BASEURI + join(*pathsegments) + self.revision)
113               
114    def components(self):
115        """
116        Subclass responsibility.
117
118        Should return a sequence or a generator of tuples of kind
119        ('product-name', ('path', 'components'...)).
120        """
121       
122        pass
123   
124class UserProduct(BiceProduct):
125    """
126    Represent a product kept under /usr/user-name/product-name.
127    """
128
129    ROOT = 'usr'
130    """The name of the root directory under which this product lives."""
131   
132    def __init__(self, name, revision="", user='azazel'):
133        BiceProduct.__init__(self, name, revision)
134        self.user = user
135
136    def components(self):
137        """
138        This kind of products are kept under a single directory in the
139        user's home directory.  Return a single tuple describing that.
140        """
141        return ( (self.name, (self.ROOT, self.user, self.name)), )
142
143class ThirdPartyProduct(BiceProduct):
144    """
145    Represent a third party product, under /3rd/prod-alias/CVSTAG/product-name
146    or /3rd/prod-alias/CVSTAG/[subproducts...].
147    """
148
149    ROOT = '3rd'
150   
151    def __init__(self, name, revision="",
152                 alias="", cvstag="HEAD", subdirs=None):
153        BiceProduct.__init__(self, name, revision)
154        self.alias = alias or ALIASES.get(name, name.lower())
155        self.cvstag = cvstag
156        self.subdirs = subdirs or [name]
157
158    def components(self):
159        """
160        Generate a sequence of tuples describing each subcomponent of
161        the product.
162        """
163       
164        for d in self.subdirs:
165            yield d, (self.ROOT, self.alias, self.cvstag, d)
166
167class OurTailoredProduct(ThirdPartyProduct):
168    """
169    Represent a third party product once it's been tailored by us, under
170    the /our subtree in the repository, with the usual naming scheme.
171    """
172   
173    ROOT = 'our'
174   
175def registerUserProduct(name, bootstrap=True, **kw):
176    """Facility for registering a UserProduct"""
177   
178    UserProduct(name, **kw).register(bootstrap)
179
180def register3rdProduct(name, bootstrap=True, **kw):
181    """Facility for registering a ThirdPartyProduct"""
182   
183    ThirdPartyProduct(name, **kw).register(bootstrap)
184
185def registerOurProduct(name, bootstrap=True, **kw):
186    """Facility for registering a OurTailoredProduct"""
187   
188    OurTailoredProduct(name, **kw).register(bootstrap)
189
190class SvnMkdir(SystemCommand):
191    COMMAND = "svn mkdir %(dir)s"
192
193def setProductDir(dir):
194    """
195    Set the target directory, creating it with ``svn mkdir`` if it
196    does not exist.
197    """
198   
199    from os.path import exists
200
201    global PRODUCTS_DIR
202    PRODUCTS_DIR = dir
203
204    if not exists(dir):
205        svnmk = SvnMkdir()
206        svnmk(dir=dir)
207       
208if __name__ == '__main__':
209    register3rdProduct('TextIndexNG2', alias='textindexng')
210    register3rdProduct('TextIndexNG2')
211     
212    registerUserProduct('AdLSkin')
213    registerUserProduct('AdLSkin', user="lele", bootstrap=False)
214     
215    registerOurProduct('GroupUserFolder')
216    registerOurProduct('Archetypes', cvstag='1.3',
217                       subdirs=['Archetypes', 'generator',
218                                'PortalTransforms', 'validation'])
219   
Note: See TracBrowser for help on using the repository browser.