Bug 588021: Refactor MICs to work on ARM, ICRepatcher interface. (r=dmandelin, u...
[mozilla-central.git] / client.py
blobd47a932f3842393f8a1bf82a5ea5f0631c230119
1 #!/usr/bin/python
3 NSPR_DIRS = (('nsprpub', 'mozilla/nsprpub'),)
4 NSS_DIRS = (('dbm', 'mozilla/dbm'),
5 ('security/nss', 'mozilla/security/nss'),
6 ('security/coreconf', 'mozilla/security/coreconf'),
7 ('security/dbm', 'mozilla/security/dbm'))
8 LIBFFI_DIRS = (('js/ctypes/libffi', 'libffi'),)
10 CVSROOT_MOZILLA = ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'
11 CVSROOT_LIBFFI = ':pserver:anoncvs@sources.redhat.com:/cvs/libffi'
13 import os
14 import sys
15 import datetime
16 import shutil
17 from optparse import OptionParser
18 from build.util import check_call
20 topsrcdir = os.path.dirname(__file__)
21 if topsrcdir == '':
22 topsrcdir = '.'
24 def check_call_noisy(cmd, *args, **kwargs):
25 print "Executing command:", cmd
26 check_call(cmd, *args, **kwargs)
28 def do_hg_pull(dir, repository, hg):
29 fulldir = os.path.join(topsrcdir, dir)
30 # clone if the dir doesn't exist, pull if it does
31 if not os.path.exists(fulldir):
32 fulldir = os.path.join(topsrcdir, dir)
33 check_call_noisy([hg, 'clone', repository, fulldir])
34 else:
35 cmd = [hg, 'pull', '-u', '-R', fulldir]
36 if repository is not None:
37 cmd.append(repository)
38 check_call_noisy(cmd)
39 check_call([hg, 'parent', '-R', fulldir,
40 '--template=Updated to revision {node}.\n'])
42 def do_cvs_export(modules, tag, cvsroot, cvs):
43 """Check out a CVS directory without CVS metadata, using "export"
44 modules is a list of directories to check out and the corresponding
45 cvs module, e.g. (('nsprpub', 'mozilla/nsprpub'))
46 """
47 for module_tuple in modules:
48 module = module_tuple[0]
49 cvs_module = module_tuple[1]
50 fullpath = os.path.join(topsrcdir, module)
51 if os.path.exists(fullpath):
52 print "Removing '%s'" % fullpath
53 shutil.rmtree(fullpath)
55 (parent, leaf) = os.path.split(module)
56 print "CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
57 check_call_noisy([cvs, '-d', cvsroot,
58 'export', '-r', tag, '-d', leaf, cvs_module],
59 cwd=os.path.join(topsrcdir, parent))
60 print "CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
62 o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname")
63 o.add_option("--skip-mozilla", dest="skip_mozilla",
64 action="store_true", default=False,
65 help="Obsolete")
67 o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
68 help="The location of the cvs binary")
69 o.add_option("--cvsroot", dest="cvsroot",
70 help="The CVSROOT (default for mozilla checkouts: %s)" % CVSROOT_MOZILLA)
72 try:
73 options, args = o.parse_args()
74 action = args[0]
75 except IndexError:
76 o.print_help()
77 sys.exit(2)
79 if action in ('checkout', 'co'):
80 print >>sys.stderr, "Warning: client.py checkout is obsolete."
81 pass
82 elif action in ('update_nspr'):
83 tag, = args[1:]
84 if not options.cvsroot:
85 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
86 do_cvs_export(NSPR_DIRS, tag, options.cvsroot, options.cvs)
87 print >>file("nsprpub/TAG-INFO", "w"), tag
88 elif action in ('update_nss'):
89 tag, = args[1:]
90 if not options.cvsroot:
91 options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
92 do_cvs_export(NSS_DIRS, tag, options.cvsroot, options.cvs)
93 print >>file("security/nss/TAG-INFO", "w"), tag
94 elif action in ('update_libffi'):
95 tag, = args[1:]
96 if not options.cvsroot:
97 options.cvsroot = CVSROOT_LIBFFI
98 do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
99 else:
100 o.print_help()
101 sys.exit(2)