Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
|
borenet
2014/01/03 13:52:36
Lots of style nits, per http://google-styleguide.g
hal.canary
2014/01/03 16:33:30
Done.
| |
| 2 | |
| 3 # Copyright 2013 Google Inc. | |
|
borenet
2014/01/03 13:52:36
2014
hal.canary
2014/01/03 16:33:30
Done.
| |
| 4 # | |
| 5 # Use of this source code is governed by a BSD-style license that can be | |
| 6 # found in the LICENSE file. | |
| 7 | |
|
borenet
2014/01/03 13:52:36
Two spaces between top-level definitions.
hal.canary
2014/01/03 16:33:30
Done.
| |
| 8 import os | |
| 9 import subprocess | |
| 10 import shutil | |
| 11 import sys | |
| 12 import tempfile | |
| 13 import re | |
| 14 | |
| 15 git = 'git' | |
| 16 skia_url = 'https://skia.googlesource.com/skia.git' | |
|
borenet
2014/01/03 13:52:36
Please capitalize these global variables.
hal.canary
2014/01/03 16:33:30
Done.
| |
| 17 | |
| 18 def rollDeps(revision, chromium_dir, N=100): | |
|
borenet
2014/01/03 13:52:36
Prefer underscored function names: roll_deps
hal.canary
2014/01/03 16:33:30
Done.
| |
| 19 ''' | |
| 20 This function: | |
| 21 | |
| 22 - searches through the last N commits to find out the hash that is | |
|
epoger
2014/01/03 14:54:08
instead of apparent constant "N", perhaps num_comm
hal.canary
2014/01/03 16:33:30
Done.
| |
| 23 associated with the revision number. | |
|
epoger
2014/01/03 14:54:08
I guess you mean "SVN revision number"?
hal.canary
2014/01/03 23:58:47
Done.
| |
| 24 | |
| 25 - creates a new branch in the chromium tree, modifies the DEPS | |
| 26 file, commits, and uploads to Rietveld. | |
| 27 | |
| 28 - create a whitespace-only commit and uploads that to to Rietveld. | |
|
epoger
2014/01/03 14:54:08
create -> creates
to to -> to
hal.canary
2014/01/03 23:58:47
Done.
| |
| 29 ''' | |
| 30 temp_dir = tempfile.mkdtemp(prefix='git_skia_tmp_') | |
| 31 devnull = open(os.devnull, "w") | |
| 32 if 0 != subprocess.call([ | |
| 33 git, 'clone', '--depth={}'.format(N), '--single-branch', | |
| 34 skia_url, temp_dir], stdout=devnull, stderr=devnull): | |
| 35 raise Exception("Failed to grab a copy of Skia.") | |
| 36 for i in xrange(N): | |
| 37 proc = subprocess.Popen([ | |
| 38 git, 'log', '-n', '1', '--format=format:%B', | |
| 39 'origin/master~{}'.format(i) ], | |
| 40 cwd=temp_dir, stdout= subprocess.PIPE, | |
| 41 stderr=devnull) | |
| 42 revision_regex = re.compile('@{}'.format(revision)) | |
| 43 hashval = None | |
| 44 for line in proc.stdout: | |
| 45 if revision_regex.search(line) is not None: | |
| 46 proc.stdout.close() | |
| 47 proc = subprocess.Popen([ | |
| 48 git, 'log', '-n', '1', '--format=format:%H', | |
| 49 'origin/master~{}'.format(i)], | |
| 50 cwd=temp_dir, stdout= subprocess.PIPE, | |
| 51 stderr=devnull) | |
| 52 hashval = proc.stdout.read().strip() | |
| 53 break | |
| 54 if hashval is not None: | |
| 55 break | |
| 56 if hashval is None: | |
| 57 raise Exception('failed to find revision') | |
|
borenet
2014/01/03 13:52:36
Please move this block into its own function, "rev
hal.canary
2014/01/03 16:33:30
Done.
| |
| 58 print revision, repr(hashval) | |
| 59 os.chdir(chromium_dir) | |
| 60 ## Assume local tree is in good shape. | |
| 61 ################################################## | |
| 62 subprocess.check_call([git, 'checkout', 'master']) | |
| 63 ################################################## | |
|
borenet
2014/01/03 13:52:36
Why are these surrounded by #'s?
hal.canary
2014/01/03 23:58:47
Done.
| |
| 64 subprocess.check_call([git, 'pull']) | |
| 65 subprocess.check_call([git, 'checkout', '-b', | |
| 66 'roll_skia_DEPS_to_{}'.format(revision)]) | |
| 67 temp_file = tempfile.NamedTemporaryFile(delete=False, | |
| 68 prefix='skia_DEPS_ROLL_tmp_') | |
|
borenet
2014/01/03 13:52:36
Please wrap everything down to "temp_file.close()"
hal.canary
2014/01/03 16:33:30
Done.
| |
| 69 deps_regex_rev = re.compile('"skia_revision": "[0-9]*",') | |
| 70 deps_regex_hash = re.compile('"skia_hash": "[0-9a-f]*",') | |
| 71 | |
| 72 deps_regex_rev_repl = '"skia_revision": "{}",'.format(revision) | |
|
borenet
2014/01/03 13:52:36
Prefer this syntax, here and elsewhere:
deps_regex
hal.canary
2014/01/03 23:58:47
Done.
| |
| 73 deps_regex_hash_repl = '"skia_hash": "{}",'.format(hashval) | |
| 74 | |
| 75 with open('DEPS', 'r') as f: | |
| 76 for line in f: | |
| 77 line = deps_regex_rev.sub(deps_regex_rev_repl, line) | |
| 78 line = deps_regex_hash.sub(deps_regex_hash_repl, line) | |
| 79 temp_file.write(line) | |
| 80 temp_file.close() | |
| 81 shutil.copyfile(temp_file.name, 'DEPS') | |
| 82 subprocess.check_call([git, 'add', 'DEPS']) | |
| 83 message = 'roll skia DEPS to {}'.format(revision) | |
| 84 subprocess.check_call([git, 'commit', '-m', message]) | |
| 85 subprocess.check_call([git, 'cl', 'upload', | |
| 86 '-t', message, '-m', message]) | |
| 87 deps_issue = subprocess.check_output([git, 'cl', 'issue']) | |
|
borenet
2014/01/03 13:52:36
Any way we can split some of the "branch/modify/co
hal.canary
2014/01/03 16:33:30
Done.
| |
| 88 | |
| 89 ################################################## | |
| 90 subprocess.check_call([git, 'checkout', 'master']) | |
| 91 ################################################## | |
| 92 | |
| 93 head = subprocess.check_output([git, 'show-ref', 'HEAD', '--hash']) | |
| 94 message = 'whitespace_change_{}'.format(head.strip()[:8]) | |
| 95 subprocess.check_call([git, 'checkout', '-b', message]) | |
| 96 with open('whitespace.txt', 'a') as o: | |
| 97 o.write('\n') | |
| 98 subprocess.check_call([git, 'add', 'whitespace.txt']) | |
| 99 subprocess.check_call([git, 'commit', '-m', message]) | |
| 100 subprocess.check_call([git, 'cl', 'upload', | |
| 101 '-t', message, '-m', message]) | |
| 102 subprocess.check_call([git, 'cl', 'issue']) | |
|
borenet
2014/01/03 13:52:36
Did you mean:
deps_issue = subprocess.check_output
hal.canary
2014/01/03 16:33:30
Done.
| |
| 103 | |
| 104 print deps_issue | |
| 105 | |
| 106 ################################################## | |
| 107 subprocess.check_call([git, 'checkout', 'master']) | |
| 108 ################################################## | |
| 109 | |
| 110 if __name__ == '__main__': | |
| 111 if len(sys.argv) < 3: | |
|
rmistry
2014/01/03 15:03:56
Please use something like optparse instead, eg:
ht
hal.canary
2014/01/03 16:33:30
Done.
| |
| 112 print 'useage {} REVISION_NUMBER CHROMIUM_DIR'.format(sys.argv[0]) | |
|
epoger
2014/01/03 14:54:08
useage -> usage
hal.canary
2014/01/03 16:33:30
Done.
| |
| 113 exit(1) | |
| 114 revision = int(sys.argv[1]) | |
|
borenet
2014/01/03 13:52:36
No need to use int() if you use %d in the format s
epoger
2014/01/03 14:54:08
Eric, which format string are you referring to? I
borenet
2014/01/03 14:58:46
Line 66.
epoger
2014/01/03 15:08:51
As far as I can tell, this would work as-is withou
hal.canary
2014/01/03 23:58:47
I just asked the optparse module to require an int
| |
| 115 chromium_dir = sys.argv[2] | |
| 116 rollDeps(revision, chromium_dir) | |
|
borenet
2014/01/03 13:52:36
Can just pass sys.argv directly into roll_deps wit
epoger
2014/01/03 14:54:08
We could, but personally I prefer the way Hal wrot
borenet
2014/01/03 14:58:46
As far as I can tell, the only difference between
epoger
2014/01/03 15:08:51
I misunderstood. I thought you were recommending
hal.canary
2014/01/03 23:58:47
I refactored to use optparse.
| |
| OLD | NEW |