OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import shutil | |
csharp
2014/01/09 21:07:54
alphabetize imports
Cait (Slow)
2014/01/10 22:00:54
Done.
| |
7 import sys | |
8 import os | |
9 import getopt | |
10 import subprocess | |
11 import glob | |
12 | |
13 def reorder_imports(input_dir, output_dir): | |
14 """Run swapimports.exe on the initial chrome.exe, and write to the output | |
15 directory. Also copy over any related files that might be needed | |
16 (pdbs, manifests etc.).""" | |
csharp
2014/01/09 21:07:54
Nit: move the ending """ to a newline
Cait (Slow)
2014/01/10 22:00:54
Done.
| |
17 | |
18 input_image = '--input-image=%s' % (os.path.join(input_dir, 'chrome.exe')) | |
19 output_image = '--output-image=%s' % (os.path.join(output_dir, 'chrome.exe')) | |
20 | |
21 swap_exe = os.path.join( | |
22 __file__, '..\\..\\..\\third_party\\syzygy\\binaries\\exe\\swapimport.exe') | |
23 subprocess.call( | |
24 [swap_exe, input_image, output_image, '--overwrite', 'chrome_elf.dll']) | |
25 | |
26 for fname in glob.glob(os.path.join(input_dir, 'chrome.exe.*')): | |
csharp
2014/01/09 21:07:54
use glob.iglob so we use an iterator (less memory)
Cait (Slow)
2014/01/10 22:00:54
Done.
| |
27 shutil.copy(fname, os.path.join(output_dir, os.path.basename(fname))) | |
28 return 0 | |
29 | |
csharp
2014/01/09 21:07:54
Nit: 2 blank lines
Cait (Slow)
2014/01/10 22:00:54
Done.
| |
30 def main(argv): | |
31 input_dir = '' | |
32 output_dir = '' | |
33 try: | |
34 opts, args = getopt.getopt(argv,"hi:o:",["idir=","odir="]) | |
csharp
2014/01/09 21:07:54
optparse is easier to use (and more pythonic)
Cait (Slow)
2014/01/10 22:00:54
Done.
| |
35 except getopt.GetoptError: | |
36 print 'reorder_imports.py -i <input_dir> -o <output_dir>' | |
37 sys.exit(2) | |
38 for opt, arg in opts: | |
39 if opt == '-h': | |
40 print 'test.py -i <input_dir> -o <output_dir>' | |
41 sys.exit() | |
42 elif opt in ("-i", "--idir"): | |
43 input_dir = arg | |
44 elif opt in ("-o", "--odir"): | |
45 output_dir = arg | |
46 return reorder_imports(input_dir, output_dir) | |
47 | |
48 if __name__ == "__main__": | |
49 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |