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:41
Done.
| |
7 import errno | |
8 import subprocess | |
9 import sys | |
10 | |
11 PLUTIL = [ | |
12 '/usr/bin/env', | |
13 'xcrun', | |
14 'plutil' | |
15 ] | |
16 | |
17 IBTOOL = [ | |
18 '/usr/bin/env', | |
19 'xcrun', | |
20 'ibtool', | |
21 ] | |
22 | |
23 | |
24 def MakeDirectories(path): | |
25 try: | |
26 os.makedirs(path) | |
27 except OSError as exc: | |
28 if exc.errno == errno.EEXIST and os.path.isdir(path): | |
29 return 0 | |
30 else: | |
31 return -1 | |
32 | |
33 return 0 | |
34 | |
35 | |
36 def ProcessInfoPlist(args): | |
37 output_plist_file = os.path.abspath(os.path.join(args.output, 'Info.plist')) | |
38 return subprocess.check_call( PLUTIL + [ | |
sdefresne
2015/07/25 19:15:30
style: no space after "(" or before ")"
Dirk Pranke
2015/07/31 21:27:41
Done.
| |
39 '-convert', | |
40 'binary1', | |
41 '-o', | |
42 output_plist_file, | |
43 '--', | |
44 args.input, | |
45 ]) | |
46 | |
47 | |
48 def ProcessNIB(args): | |
49 output_nib_file = os.path.join(os.path.abspath(args.output), | |
50 "%s.nib" % os.path.splitext(os.path.basename(args.input))[0]) | |
51 | |
52 return subprocess.check_call(IBTOOL + [ | |
53 '--module', | |
54 args.module, | |
55 '--auto-activate-custom-fonts', | |
56 '--target-device', | |
57 'mac', | |
58 '--compile', | |
59 output_nib_file, | |
60 os.path.abspath(args.input), | |
61 ]) | |
62 | |
63 | |
64 def GenerateProjectStructure(args): | |
65 application_path = os.path.join( args.dir, args.name + ".app", "Contents" ) | |
66 return MakeDirectories( application_path ) | |
67 | |
68 | |
69 def Main(): | |
70 parser = argparse.ArgumentParser(description='A script that aids in ' | |
71 'the creation of an Mac application') | |
72 | |
73 subparsers = parser.add_subparsers() | |
74 | |
75 # Plist Parser | |
76 | |
77 plist_parser = subparsers.add_parser('plist', | |
78 help='Process the Info.plist') | |
79 plist_parser.set_defaults(func=ProcessInfoPlist) | |
80 | |
81 plist_parser.add_argument('-i', dest='input', help='The input plist path') | |
82 plist_parser.add_argument('-o', dest='output', help='The output plist dir') | |
83 | |
84 # NIB Parser | |
85 | |
86 plist_parser = subparsers.add_parser('nib', | |
87 help='Process a NIB file') | |
88 plist_parser.set_defaults(func=ProcessNIB) | |
89 | |
90 plist_parser.add_argument('-i', dest='input', help='The input nib path') | |
91 plist_parser.add_argument('-o', dest='output', help='The output nib dir') | |
92 plist_parser.add_argument('-m', dest='module', help='The module name') | |
93 | |
94 # Directory Structure Parser | |
95 | |
96 dir_struct_parser = subparsers.add_parser('structure', | |
97 help='Creates the directory of an Mac application') | |
98 | |
99 dir_struct_parser.set_defaults(func=GenerateProjectStructure) | |
100 | |
101 dir_struct_parser.add_argument('-d', dest='dir', help='Out directory') | |
102 dir_struct_parser.add_argument('-n', dest='name', help='App name') | |
103 | |
104 # Engage! | |
105 | |
106 args = parser.parse_args() | |
107 | |
108 return args.func(args) | |
109 | |
110 | |
111 if __name__ == '__main__': | |
112 sys.exit(Main()) | |
OLD | NEW |