Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jessejiang0214/cec57ddbe6c95b30e84013b61fb76eb5 to your computer and use it in GitHub Desktop.
Save jessejiang0214/cec57ddbe6c95b30e84013b61fb76eb5 to your computer and use it in GitHub Desktop.
Change plist based on environment python
#!/usr/bin/env python3
import argparse
import subprocess
import shlex
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('--environment',
'-e',
help='The Environment',
choices=['test', 'prod'],
required=True)
args = parser.parse_args()
return args
def execute_plist_transform(key, new_value):
if key == "CFBundleURLSchemes":
as_string = "plutil -replace " + key + " -json " + new_value + " ./Info.plist"
else:
as_string = "plutil -replace " + key + " -string " + new_value + " ./Info.plist"
command = shlex.split(as_string)
subprocess.call(command)
def replace_variables_in_plist(configs):
for config in configs:
key, new_value = config
execute_plist_transform(key, new_value)
def initialise_variables():
dict = {}
dict["test"] = [("CFBundleIdentifier", "xxxx.test
("CFBundleURLSchemes", '\'["xxxx.test://auth"]\'')]
dict["prod"] = [("CFBundleIdentifier", "xxxx
("CFBundleURLSchemes", '\'["xxxx://auth"]\'')]
return dict
def main():
config_lookup = initialise_variables()
parsed_args = parse_arguments()
replace_variables_in_plist(config_lookup[parsed_args.environment])
print("transformed as " + parsed_args.environment + " build")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment