Skip to content

Commit

Permalink
Merge pull request #10667 from brave/fixed_deprecated_api_tweak_info_…
Browse files Browse the repository at this point in the history
…plist

Handled deprecated readPlist/writePlist in tweak_info_plist.py
  • Loading branch information
simonhong authored and mkarolin committed Oct 25, 2021
1 parent cebfda0 commit 5afafdc
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions build/mac/tweak_info_plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

def _ConvertPlist(source_plist, output_plist, fmt):
"""Convert |source_plist| to |fmt| and save as |output_plist|."""
assert sys.version_info.major == 2, "Use plistlib directly in Python 3"
return subprocess.call(
['plutil', '-convert', fmt, '-o', output_plist, source_plist])

Expand Down Expand Up @@ -82,10 +83,14 @@ def Main():
# Read the plist into its parsed format. Convert the file to 'xml1' as
# plistlib only supports that format in Python 2.7.
with tempfile.NamedTemporaryFile() as temp_info_plist:
retcode = _ConvertPlist(args.plist_path, temp_info_plist.name, 'xml1')
if retcode != 0:
return retcode
plist = plistlib.readPlist(temp_info_plist.name)
if sys.version_info.major == 2:
retcode = _ConvertPlist(args.plist_path, temp_info_plist.name, 'xml1')
if retcode != 0:
return retcode
plist = plistlib.readPlist(temp_info_plist.name)
else:
with open(args.plist_path, 'rb') as f:
plist = plistlib.load(f)

output_path = args.plist_path
if args.plist_output is not None:
Expand All @@ -109,12 +114,15 @@ def Main():
plist['SUEnableSystemProfiling'] = False

# Now that all keys have been mutated, rewrite the file.
with tempfile.NamedTemporaryFile() as temp_info_plist:
plistlib.writePlist(plist, temp_info_plist.name)

# Convert Info.plist to the format requested by the --format flag. Any
# format would work on Mac but iOS requires specific format.
return _ConvertPlist(temp_info_plist.name, output_path, args.format)
# Convert Info.plist to the format requested by the --format flag. Any
# format would work on Mac but iOS requires specific format.
if sys.version_info.major == 2:
with tempfile.NamedTemporaryFile() as temp_info_plist:
plistlib.writePlist(plist, temp_info_plist.name)
return _ConvertPlist(temp_info_plist.name, output_path, args.format)
with open(output_path, 'wb') as f:
plist_format = {'binary1': plistlib.FMT_BINARY, 'xml1': plistlib.FMT_XML}
plistlib.dump(plist, f, fmt=plist_format[args.format])


if __name__ == '__main__':
Expand Down

0 comments on commit 5afafdc

Please sign in to comment.