1 #!/usr/bin/env python 2 3 import codecs, httplib, json, optparse, os, urllib, shutil, subprocess, sys 4 5 upstream_git = 'https://github.com/catapult-project/catapult.git' 6 PACKAGE_DIRS = ['common', 'dependency_manager', 'devil', 'systrace', 'telemetry'] 7 IGNORE_PATTERNS = ['OWNERS'] # doesn't make sense to sync owners files 8 9 script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 10 catapult_src_dir = os.path.join(script_dir, 'catapult-upstream') 11 catapult_dst_dir = os.path.join(script_dir, 'catapult') 12 13 parser = optparse.OptionParser() 14 parser.add_option('--local', dest='local_dir', metavar='DIR', 15 help='use a local catapult') 16 parser.add_option('--no-min', dest='no_min', default=False, action='store_true', 17 help='skip minification') 18 options, args = parser.parse_args() 19 20 # Update the source if needed. 21 if options.local_dir is None: 22 # Remove the old source tree. 23 shutil.rmtree(catapult_src_dir, True) 24 25 # Pull the latest source from the upstream git. 26 git_args = ['git', 'clone', upstream_git, catapult_src_dir] 27 p = subprocess.Popen(git_args, stdout=subprocess.PIPE, cwd=script_dir) 28 p.communicate() 29 if p.wait() != 0: 30 print 'Failed to checkout source from upstream git.' 31 sys.exit(1) 32 33 catapult_git_dir = os.path.join(catapult_src_dir, '.git') 34 # Update the UPSTREAM_REVISION file 35 git_args = ['git', 'rev-parse', 'HEAD'] 36 p = subprocess.Popen(git_args, 37 stdout=subprocess.PIPE, 38 cwd=catapult_src_dir, 39 env={"GIT_DIR":catapult_git_dir}) 40 out, err = p.communicate() 41 if p.wait() != 0: 42 print 'Failed to get revision.' 43 sys.exit(1) 44 45 shutil.rmtree(catapult_git_dir, True) 46 47 rev = out.strip() 48 with open('UPSTREAM_REVISION', 'wt') as f: 49 f.write(rev + '\n') 50 else: 51 catapult_src_dir = options.local_dir 52 53 54 # Update systrace_trace_viewer.html 55 systrace_dir = os.path.join(catapult_src_dir, 'systrace', 'systrace') 56 sys.path.append(systrace_dir) 57 import update_systrace_trace_viewer 58 update_systrace_trace_viewer.update(no_auto_update=True, no_min=options.no_min) 59 60 # Package the result 61 shutil.rmtree(catapult_dst_dir) 62 for d in PACKAGE_DIRS: 63 shutil.copytree(os.path.join(catapult_src_dir, d), 64 os.path.join(catapult_dst_dir, d), 65 ignore=shutil.ignore_patterns(*IGNORE_PATTERNS)) 66