OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import argparse | |
6 import os | |
sdefresne
2015/07/25 19:15:30
nit: sort
Dirk Pranke
2015/07/31 21:27:40
Done.
| |
7 import errno | |
8 import subprocess | |
9 import sys | |
10 | |
11 PLUTIL = [ | |
sdefresne
2015/07/25 19:15:30
nit: why use a global for a constant that is only
Dirk Pranke
2015/07/31 21:27:40
Good catch. Fixed.
| |
12 '/usr/bin/env', | |
13 'xcrun', | |
14 'plutil' | |
15 ] | |
16 | |
17 | |
18 def ProcessInfoPlist(args): | |
19 output_plist_file = os.path.abspath(os.path.join(args.output, 'Info.plist')) | |
20 return subprocess.check_call( PLUTIL + [ | |
21 '-convert', | |
22 'binary1', | |
23 '-o', | |
24 output_plist_file, | |
25 '--', | |
26 args.input, | |
27 ]) | |
28 | |
29 | |
30 def PerformCodeSigning(args): | |
31 return subprocess.check_call([ | |
32 '/usr/bin/env', | |
33 'xcrun', | |
34 'codesign', | |
35 '--entitlements', | |
36 args.entitlements_path, | |
37 '--sign', | |
38 args.identity, | |
39 '-f', | |
40 args.application_path, | |
41 ]) | |
42 | |
43 | |
44 def MakeDirectories(path): | |
45 try: | |
46 os.makedirs(path) | |
47 except OSError as exc: | |
48 if exc.errno == errno.EEXIST and os.path.isdir(path): | |
49 return 0 | |
50 else: | |
51 return -1 | |
52 | |
53 return 0 | |
54 | |
55 | |
56 def GenerateProjectStructure(args): | |
57 application_path = os.path.join( args.dir, args.name + ".app" ) | |
sdefresne
2015/07/25 19:15:30
style: no space after "(" nor before ")"
Dirk Pranke
2015/07/31 21:27:40
Done.
| |
58 return MakeDirectories( application_path ) | |
59 | |
60 | |
61 def Main(): | |
sdefresne
2015/07/25 19:15:30
nit: even though Python style guide recommends cap
Dirk Pranke
2015/07/31 21:27:40
Done.
| |
62 parser = argparse.ArgumentParser(description='A script that aids in ' | |
63 'the creation of an iOS application') | |
64 | |
65 subparsers = parser.add_subparsers() | |
66 | |
67 # Plist Parser | |
68 | |
69 plist_parser = subparsers.add_parser('plist', | |
70 help='Process the Info.plist') | |
71 plist_parser.set_defaults(func=ProcessInfoPlist) | |
72 | |
73 plist_parser.add_argument('-i', dest='input', help='The input plist path') | |
74 plist_parser.add_argument('-o', dest='output', help='The output plist dir') | |
75 | |
76 # Directory Structure Parser | |
77 | |
78 dir_struct_parser = subparsers.add_parser('structure', | |
79 help='Creates the directory of an iOS application') | |
80 | |
81 dir_struct_parser.set_defaults(func=GenerateProjectStructure) | |
82 | |
83 dir_struct_parser.add_argument('-d', dest='dir', help='Out directory') | |
84 dir_struct_parser.add_argument('-n', dest='name', help='App name') | |
85 | |
86 # Code Signing | |
87 | |
88 code_signing_parser = subparsers.add_parser('codesign', | |
89 help='Code sign the specified application') | |
90 | |
91 code_signing_parser.set_defaults(func=PerformCodeSigning) | |
92 | |
93 code_signing_parser.add_argument('-p', dest='application_path', required=True, | |
94 help='The application path') | |
95 code_signing_parser.add_argument('-i', dest='identity', required=True, | |
96 help='The code signing identity to use') | |
97 code_signing_parser.add_argument('-e', dest='entitlements_path', | |
98 required=True, | |
99 help='The path to the entitlements .xcent') | |
100 | |
101 # Engage! | |
102 | |
103 args = parser.parse_args() | |
104 | |
sdefresne
2015/07/25 19:15:30
nit: remove newline
Dirk Pranke
2015/07/31 21:27:40
Done (removed a few others as well).
| |
105 return args.func(args) | |
106 | |
107 | |
108 if __name__ == '__main__': | |
109 sys.exit(Main()) | |
OLD | NEW |