Centralize gc policy in a new GarbageCollectionPolicy class.
[cvs2svn.git] / cvs2svn_rcsparse / update
blob50116cc2a944c8f6c6a9aae049f98fa1f12e42ed
1 #!/usr/bin/env python
3 """Update the rcsparse library from ViewVC."""
5 import sys
6 import os
7 import subprocess
8 import re
9 import optparse
12 VIEWVC_REPOS = 'http://viewvc.tigris.org/svn/viewvc'
13 BRANCH = 'trunk'
14 RCSPARSE_URL = '/'.join([VIEWVC_REPOS, BRANCH, 'lib/vclib/ccvs/rcsparse'])
15 LICENSE_URL = '/'.join([VIEWVC_REPOS, BRANCH, 'LICENSE.html'])
17 DEST = os.path.dirname(__file__)
19 INIT_TEXT = """\
20 # This file causes Python to treat its containing directory it as a
21 # package. Please note that the contents of this file differ from
22 # those of the __init__.py file distributed with ViewVC.
24 """
27 def get_current_revision():
28 revision_re = re.compile(r'^Revision\:\s*(?P<revision>\d+)$')
30 cmd = ['svn', 'info', VIEWVC_REPOS]
31 sys.stderr.write('%s\n' % (' '.join(cmd),))
32 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
33 (out, err) = p.communicate()
34 for line in out.splitlines():
35 m = revision_re.match(line)
36 if m:
37 return int(m.group('revision'))
39 sys.exit(
40 'Could not determine the current revision of the ViewVC repository!'
43 def export(url, revision, dest):
44 cmd = ['svn', 'export', '-r', str(revision), '--force', url, dest]
45 sys.stderr.write('%s\n' % (' '.join(cmd),))
46 retcode = subprocess.call(cmd)
48 if retcode:
49 sys.exit('Export failed!')
52 def main(args):
53 parser = optparse.OptionParser(
54 description=__doc__,
57 parser.add_option(
58 '--revision', '-r', metavar='REV',
59 action='store', type='int', default=None,
60 help='download the specific revision REV',
63 (options, args) = parser.parse_args(args)
65 if args:
66 parser.error('Unexpected arguments: %s' % (' '.join(args),))
68 if options.revision is None:
69 options.revision = get_current_revision()
71 export(RCSPARSE_URL, options.revision, DEST)
72 export(LICENSE_URL, options.revision, os.path.join(DEST, 'LICENSE.html'))
74 # Record which version of the upstream source was downloaded:
75 open(os.path.join(DEST, 'UPSTREAM_SOURCE'), 'w').write(
76 '%s@%d\n' % (RCSPARSE_URL, options.revision,)
79 # Replace the upstream __init__.py file, which does some stuff that we
80 # don't want:
81 open(os.path.join(DEST, '__init__.py'), 'w').write(INIT_TEXT)
84 main(sys.argv[1:])