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