2007-05-23 00:07:17 +04:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
NSPR_DIRS = ('nsprpub',)
|
|
|
|
NSS_DIRS = ('dbm',
|
|
|
|
'security/nss',
|
|
|
|
'security/coreconf',
|
|
|
|
'security/dbm')
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2008-06-03 02:52:25 +04:00
|
|
|
import datetime
|
2008-06-06 16:34:40 +04:00
|
|
|
import shutil
|
2007-05-23 00:07:17 +04:00
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
topsrcdir = os.path.dirname(__file__)
|
|
|
|
if topsrcdir == '':
|
|
|
|
topsrcdir = '.'
|
|
|
|
|
|
|
|
try:
|
|
|
|
from subprocess import check_call
|
|
|
|
except ImportError:
|
|
|
|
import subprocess
|
|
|
|
def check_call(*popenargs, **kwargs):
|
|
|
|
retcode = subprocess.call(*popenargs, **kwargs)
|
|
|
|
if retcode:
|
|
|
|
cmd = kwargs.get("args")
|
|
|
|
if cmd is None:
|
|
|
|
cmd = popenargs[0]
|
|
|
|
raise Exception("Command '%s' returned non-zero exit status %i" % (cmd, retcode))
|
|
|
|
|
2007-07-13 16:23:32 +04:00
|
|
|
def check_call_noisy(cmd, *args, **kwargs):
|
|
|
|
print "Executing command:", cmd
|
|
|
|
check_call(cmd, *args, **kwargs)
|
|
|
|
|
|
|
|
def do_hg_pull(dir, repository, hg):
|
2007-05-23 00:07:17 +04:00
|
|
|
fulldir = os.path.join(topsrcdir, dir)
|
2007-05-24 08:05:33 +04:00
|
|
|
# clone if the dir doesn't exist, pull if it does
|
|
|
|
if not os.path.exists(fulldir):
|
|
|
|
fulldir = os.path.join(topsrcdir, dir)
|
2007-07-13 16:23:32 +04:00
|
|
|
check_call_noisy([hg, 'clone', repository, fulldir])
|
2007-05-24 08:05:33 +04:00
|
|
|
else:
|
2007-07-13 16:23:32 +04:00
|
|
|
cmd = [hg, 'pull', '-u', '-R', fulldir]
|
|
|
|
if repository is not None:
|
|
|
|
cmd.append(repository)
|
|
|
|
check_call_noisy(cmd)
|
2008-06-03 02:52:25 +04:00
|
|
|
check_call([hg, 'parent', '-R', fulldir,
|
|
|
|
'--template=Updated to revision {node}.\n'])
|
2007-05-23 00:07:17 +04:00
|
|
|
|
2008-06-06 16:34:40 +04:00
|
|
|
def do_cvs_export(modules, tag, cvsroot, cvs):
|
|
|
|
"""Check out a CVS directory without CVS metadata, using "export"
|
2007-05-23 00:07:17 +04:00
|
|
|
modules is a list of directories to check out, e.g. ['nsprpub']
|
|
|
|
"""
|
|
|
|
for module in modules:
|
2008-06-06 16:34:40 +04:00
|
|
|
fullpath = os.path.join(topsrcdir, module)
|
|
|
|
if os.path.exists(fullpath):
|
|
|
|
print "Removing '%s'" % fullpath
|
|
|
|
shutil.rmtree(fullpath)
|
|
|
|
|
2007-05-23 00:07:17 +04:00
|
|
|
(parent, leaf) = os.path.split(module)
|
2008-06-06 16:34:40 +04:00
|
|
|
print "CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
|
2007-07-13 16:23:32 +04:00
|
|
|
check_call_noisy([cvs, '-d', cvsroot,
|
2008-06-06 16:34:40 +04:00
|
|
|
'export', '-r', tag, '-d', leaf,
|
2007-07-13 16:23:32 +04:00
|
|
|
'mozilla/%s' % module],
|
|
|
|
cwd=os.path.join(topsrcdir, parent))
|
2008-06-06 16:34:40 +04:00
|
|
|
print "CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
|
2007-05-23 00:07:17 +04:00
|
|
|
|
2008-06-06 16:34:40 +04:00
|
|
|
o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname")
|
2007-12-22 00:49:52 +03:00
|
|
|
o.add_option("--skip-mozilla", dest="skip_mozilla",
|
|
|
|
action="store_true", default=False,
|
2008-06-06 16:34:40 +04:00
|
|
|
help="Obsolete")
|
2007-12-22 00:49:52 +03:00
|
|
|
|
2007-05-23 00:07:17 +04:00
|
|
|
o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
|
|
|
|
help="The location of the cvs binary")
|
|
|
|
o.add_option("--cvsroot", dest="cvsroot",
|
|
|
|
default=os.environ.get('CVSROOT', ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'),
|
|
|
|
help="The CVSROOT (default: :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot")
|
|
|
|
|
|
|
|
try:
|
2008-06-06 16:34:40 +04:00
|
|
|
options, args = o.parse_args()
|
|
|
|
action = args[0]
|
|
|
|
except IndexError:
|
2007-05-23 00:07:17 +04:00
|
|
|
o.print_help()
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
if action in ('checkout', 'co'):
|
2008-06-06 16:34:40 +04:00
|
|
|
print >>sys.stderr, "Warning: client.py checkout is obsolete."
|
|
|
|
pass
|
|
|
|
elif action in ('update_nspr'):
|
|
|
|
tag, = args[1:]
|
|
|
|
do_cvs_export(NSPR_DIRS, tag, options.cvsroot, options.cvs)
|
|
|
|
elif action in ('update_nss'):
|
|
|
|
tag, = args[1:]
|
|
|
|
do_cvs_export(NSS_DIRS, tag, options.cvsroot, options.cvs)
|
2007-05-23 00:07:17 +04:00
|
|
|
else:
|
|
|
|
o.print_help()
|
|
|
|
sys.exit(2)
|