2007-05-23 00:07:17 +04:00
#!/usr/bin/python
2007-10-31 18:40:29 +03:00
NSPR_CO_TAG = ' NSPR_HEAD_20071016 '
2007-11-26 22:55:13 +03:00
NSS_CO_TAG = ' NSS_3_12_ALPHA_2B '
2007-05-23 00:07:17 +04:00
NSPR_DIRS = ( ' nsprpub ' , )
NSS_DIRS = ( ' dbm ' ,
' security/nss ' ,
' security/coreconf ' ,
' security/dbm ' )
2007-07-20 22:49:16 +04:00
# URL of the default hg repository to clone for Tamarin.
DEFAULT_TAMARIN_REPO = ' http://hg.mozilla.org/tamarin-central/ '
2007-07-13 16:23:32 +04:00
2007-05-23 00:07:17 +04:00
import os
import sys
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 )
2007-05-23 00:07:17 +04:00
def do_cvs_checkout ( modules , tag , cvsroot , cvs ) :
""" Check out a CVS directory.
modules is a list of directories to check out , e . g . [ ' nsprpub ' ]
"""
for module in modules :
( parent , leaf ) = os . path . split ( module )
2007-07-13 16:23:32 +04:00
check_call_noisy ( [ cvs , ' -d ' , cvsroot ,
' checkout ' , ' -P ' , ' -r ' , tag , ' -d ' , leaf ,
' mozilla/ %s ' % module ] ,
cwd = os . path . join ( topsrcdir , parent ) )
2007-05-23 00:07:17 +04:00
2007-05-24 08:05:33 +04:00
o = OptionParser ( usage = " client.py [options] checkout " )
2007-05-23 00:07:17 +04:00
o . add_option ( " -m " , " --mozilla-repo " , dest = " mozilla_repo " ,
2007-07-13 16:23:32 +04:00
default = None ,
help = " URL of Mozilla repository to pull from (default: use hg default in .hg/hgrc) " )
2007-05-23 00:07:17 +04:00
o . add_option ( " -t " , " --tamarin-repo " , dest = " tamarin_repo " ,
2007-07-13 16:23:32 +04:00
default = None ,
help = " URL of Tamarin repository to pull from (default: use hg default in js/tamarin/.hg/hgrc; or if that file doesn ' t exist, use \" " + DEFAULT_TAMARIN_REPO + " \" .) " )
2007-05-23 00:07:17 +04:00
o . add_option ( " --hg " , dest = " hg " , default = os . environ . get ( ' HG ' , ' hg ' ) ,
help = " The location of the hg binary " )
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 " )
2007-07-13 16:23:32 +04:00
def fixup_repo_options ( options ) :
""" Check options.mozilla_repo and options.tamarin_repo values;
populate tamarin_repo if needed .
options . mozilla_repo and options . tamarin_repo are normally None .
This is fine - - our " hg pull " commands will omit the repo URL .
The exception is the initial checkout , which does an " hg clone "
for Tamarin . That command requires a repository URL .
"""
if ( options . mozilla_repo is None
and not os . path . exists ( os . path . join ( topsrcdir , ' .hg ' ) ) ) :
o . print_help ( )
print
print " *** The -m option is required for the initial checkout. "
sys . exit ( 2 )
# Handle special case: initial checkout of Tamarin.
if ( options . tamarin_repo is None
and not os . path . exists ( os . path . join ( topsrcdir , ' js ' , ' tamarin ' ) ) ) :
2007-07-20 22:49:16 +04:00
options . tamarin_repo = DEFAULT_TAMARIN_REPO
2007-07-13 16:23:32 +04:00
2007-05-23 00:07:17 +04:00
try :
( options , ( action , ) ) = o . parse_args ( )
except ValueError :
o . print_help ( )
sys . exit ( 2 )
2007-07-13 16:23:32 +04:00
fixup_repo_options ( options )
2007-05-23 00:07:17 +04:00
if action in ( ' checkout ' , ' co ' ) :
do_cvs_checkout ( NSPR_DIRS , NSPR_CO_TAG , options . cvsroot , options . cvs )
do_cvs_checkout ( NSS_DIRS , NSS_CO_TAG , options . cvsroot , options . cvs )
2007-07-13 16:23:32 +04:00
do_hg_pull ( ' js/tamarin ' , options . tamarin_repo , options . hg )
do_hg_pull ( ' . ' , options . mozilla_repo , options . hg )
2007-05-23 00:07:17 +04:00
else :
o . print_help ( )
sys . exit ( 2 )