Bug 867089 - Validate the playbackRate before using it. r=ehsan
[gecko.git] / client.py
blobe98bdc95c7ed1fa09c4500f3358fd44a439aff45
1 #!/usr/bin/python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 LIBFFI_DIRS = (('js/ctypes/libffi', 'libffi'),)
8 WEBIDLPARSER_DIR = 'dom/bindings/parser'
9 WEBIDLPARSER_REPO = 'https://hg.mozilla.org/users/khuey_mozilla.com/webidl-parser'
10 HG_EXCLUSIONS = ['.hg', '.hgignore', '.hgtags']
11 WEBIDLPARSER_EXCLUSIONS = HG_EXCLUSIONS + ['.gitignore', 'ply']
13 CVSROOT_LIBFFI = ':pserver:anoncvs@sources.redhat.com:/cvs/libffi'
15 import os
16 import sys
17 import datetime
18 import shutil
19 import glob
20 from optparse import OptionParser
21 from subprocess import check_call
23 topsrcdir = os.path.dirname(__file__)
24 if topsrcdir == '':
25 topsrcdir = '.'
27 def check_call_noisy(cmd, *args, **kwargs):
28 print "Executing command:", cmd
29 check_call(cmd, *args, **kwargs)
31 def do_hg_pull(dir, repository, hg):
32 fulldir = os.path.join(topsrcdir, dir)
33 # clone if the dir doesn't exist, pull if it does
34 if not os.path.exists(fulldir):
35 check_call_noisy([hg, 'clone', repository, fulldir])
36 else:
37 cmd = [hg, 'pull', '-u', '-R', fulldir]
38 if repository is not None:
39 cmd.append(repository)
40 check_call_noisy(cmd)
41 check_call([hg, 'parent', '-R', fulldir,
42 '--template=Updated to revision {node}.\n'])
44 def do_hg_replace(dir, repository, tag, exclusions, hg):
45 """
46 Replace the contents of dir with the contents of repository, except for
47 files matching exclusions.
48 """
49 fulldir = os.path.join(topsrcdir, dir)
50 if os.path.exists(fulldir):
51 shutil.rmtree(fulldir)
53 assert not os.path.exists(fulldir)
54 check_call_noisy([hg, 'clone', '-u', tag, repository, fulldir])
56 for thing in exclusions:
57 for excluded in glob.iglob(os.path.join(fulldir, thing)):
58 if os.path.isdir(excluded):
59 shutil.rmtree(excluded)
60 else:
61 os.remove(excluded)
63 def do_cvs_export(modules, tag, cvsroot, cvs):
64 """Check out a CVS directory without CVS metadata, using "export"
65 modules is a list of directories to check out and the corresponding
66 cvs module, e.g. (('js/ctypes/libffi', 'libffi'),)
67 """
68 for module_tuple in modules:
69 module = module_tuple[0]
70 cvs_module = module_tuple[1]
71 fullpath = os.path.join(topsrcdir, module)
72 if os.path.exists(fullpath):
73 print "Removing '%s'" % fullpath
74 shutil.rmtree(fullpath)
76 (parent, leaf) = os.path.split(module)
77 print "CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
78 check_call_noisy([cvs, '-d', cvsroot,
79 'export', '-r', tag, '-d', leaf, cvs_module],
80 cwd=os.path.join(topsrcdir, parent))
81 print "CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
83 def toggle_trailing_blank_line(depname):
84 """If the trailing line is empty, then we'll delete it.
85 Otherwise we'll add a blank line."""
86 lines = open(depname, "r").readlines()
87 if not lines:
88 print >>sys.stderr, "unexpected short file"
89 return
91 if not lines[-1].strip():
92 # trailing line is blank, removing it
93 open(depname, "wb").writelines(lines[:-1])
94 else:
95 # adding blank line
96 open(depname, "ab").write("\n")
98 o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname | update_webidlparser tagname")
99 o.add_option("--skip-mozilla", dest="skip_mozilla",
100 action="store_true", default=False,
101 help="Obsolete")
103 o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
104 help="The location of the cvs binary")
105 o.add_option("--cvsroot", dest="cvsroot",
106 help="The CVSROOT for libffi (default : %s)" % CVSROOT_LIBFFI)
107 o.add_option("--hg", dest="hg", default=os.environ.get('HG', 'hg'),
108 help="The location of the hg binary")
110 try:
111 options, args = o.parse_args()
112 action = args[0]
113 except IndexError:
114 o.print_help()
115 sys.exit(2)
117 if action in ('checkout', 'co'):
118 print >>sys.stderr, "Warning: client.py checkout is obsolete."
119 pass
120 elif action in ('update_nspr'):
121 tag, = args[1:]
122 do_hg_replace('nsprpub', 'https://hg.mozilla.org/projects/nspr',
123 tag, HG_EXCLUSIONS, options.hg)
124 print >>file("nsprpub/TAG-INFO", "w"), tag
125 toggle_trailing_blank_line("nsprpub/config/prdepend.h")
126 elif action in ('update_nss'):
127 tag, = args[1:]
128 do_hg_replace('security/nss', 'https://hg.mozilla.org/projects/nss',
129 tag, HG_EXCLUSIONS, options.hg)
130 print >>file("security/nss/TAG-INFO", "w"), tag
131 toggle_trailing_blank_line("security/nss/coreconf/coreconf.dep")
132 elif action in ('update_libffi'):
133 tag, = args[1:]
134 if not options.cvsroot:
135 options.cvsroot = CVSROOT_LIBFFI
136 do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
137 elif action in ('update_webidlparser'):
138 tag, = args[1:]
139 do_hg_replace(WEBIDLPARSER_DIR, WEBIDLPARSER_REPO, tag, WEBIDLPARSER_EXCLUSIONS, options.hg)
140 else:
141 o.print_help()
142 sys.exit(2)