OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import plistlib | 6 import plistlib |
7 import os | 7 import os |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 """Loads Plist at |path| and returns it as a dictionary.""" | 131 """Loads Plist at |path| and returns it as a dictionary.""" |
132 fd, name = tempfile.mkstemp() | 132 fd, name = tempfile.mkstemp() |
133 try: | 133 try: |
134 subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path]) | 134 subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path]) |
135 with os.fdopen(fd, 'r') as f: | 135 with os.fdopen(fd, 'r') as f: |
136 return plistlib.readPlist(f) | 136 return plistlib.readPlist(f) |
137 finally: | 137 finally: |
138 os.unlink(name) | 138 os.unlink(name) |
139 | 139 |
140 | 140 |
141 def SavePList(path, data): | 141 def SavePList(path, format, data): |
142 """Saves |data| as a Plist to |path| in binary1 format.""" | 142 """Saves |data| as a Plist to |path| in the specified |format|.""" |
143 fd, name = tempfile.mkstemp() | 143 fd, name = tempfile.mkstemp() |
144 try: | 144 try: |
145 with os.fdopen(fd, 'w') as f: | 145 with os.fdopen(fd, 'w') as f: |
146 plistlib.writePlist(data, f) | 146 plistlib.writePlist(data, f) |
147 subprocess.check_call(['plutil', '-convert', 'binary1', '-o', path, name]) | 147 subprocess.check_call(['plutil', '-convert', format, '-o', path, name]) |
148 finally: | 148 finally: |
149 os.unlink(name) | 149 os.unlink(name) |
150 | 150 |
151 | 151 |
152 def MergePList(plist1, plist2): | 152 def MergePList(plist1, plist2): |
153 """Merges |plist1| with |plist2| recursively. | 153 """Merges |plist1| with |plist2| recursively. |
154 | 154 |
155 Creates a new dictionary representing a Property List (.plist) files by | 155 Creates a new dictionary representing a Property List (.plist) files by |
156 merging the two dictionary |plist1| and |plist2| recursively (only for | 156 merging the two dictionary |plist1| and |plist2| recursively (only for |
157 dictionary values). | 157 dictionary values). |
(...skipping 25 matching lines...) Expand all Loading... |
183 | 183 |
184 | 184 |
185 def main(): | 185 def main(): |
186 parser = ArgumentParser( | 186 parser = ArgumentParser( |
187 description='A script to generate iOS application Info.plist.', | 187 description='A script to generate iOS application Info.plist.', |
188 fromfile_prefix_chars='@') | 188 fromfile_prefix_chars='@') |
189 parser.add_argument('-o', '--output', required=True, | 189 parser.add_argument('-o', '--output', required=True, |
190 help='Path to output plist file.') | 190 help='Path to output plist file.') |
191 parser.add_argument('-s', '--subst', action='append', default=[], | 191 parser.add_argument('-s', '--subst', action='append', default=[], |
192 help='Substitution rule in the format "key=value".') | 192 help='Substitution rule in the format "key=value".') |
| 193 parser.add_argument('-f', '--format', required=True, |
| 194 help='Plist format (e.g. binary1, xml1) to output.') |
193 parser.add_argument('path', nargs="+", help='Path to input plist files.') | 195 parser.add_argument('path', nargs="+", help='Path to input plist files.') |
194 args = parser.parse_args() | 196 args = parser.parse_args() |
195 substitutions = {} | 197 substitutions = {} |
196 for subst in args.subst: | 198 for subst in args.subst: |
197 key, value = subst.split('=', 1) | 199 key, value = subst.split('=', 1) |
198 substitutions[key] = value | 200 substitutions[key] = value |
199 data = {} | 201 data = {} |
200 for filename in args.path: | 202 for filename in args.path: |
201 data = MergePList(data, LoadPList(filename)) | 203 data = MergePList(data, LoadPList(filename)) |
202 data = Interpolate(data, substitutions) | 204 data = Interpolate(data, substitutions) |
203 SavePList(args.output, data) | 205 SavePList(args.output, args.format, data) |
204 return 0 | 206 return 0 |
205 | 207 |
206 if __name__ == '__main__': | 208 if __name__ == '__main__': |
207 sys.exit(main()) | 209 sys.exit(main()) |
OLD | NEW |