Skip to content

Instantly share code, notes, and snippets.

@homebysix
Last active January 30, 2020 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homebysix/6ff057606107c4649292197603a78262 to your computer and use it in GitHub Desktop.
Save homebysix/6ff057606107c4649292197603a78262 to your computer and use it in GitHub Desktop.
convert_autopkg_recipes_to_yaml.py
#!/usr/bin/python
import plistlib
from collections import OrderedDict
from glob import glob
import yaml
def represent_ordereddict(dumper, data):
value = []
for item_key, item_value in data.items():
node_key = dumper.represent_data(item_key)
node_value = dumper.represent_data(item_value)
value.append((node_key, node_value))
return yaml.nodes.MappingNode(u"tag:yaml.org,2002:map", value)
yaml.add_representer(OrderedDict, represent_ordereddict)
recipe_paths = glob("*.recipe")
for path in recipe_paths:
recipe = plistlib.readPlist(path)
if "Process" in recipe:
process = recipe["Process"]
new_process = []
for processor in process:
if "Arguments" in processor:
processor = OrderedDict(processor)
processor.move_to_end("Arguments")
new_process.append(processor)
recipe["Process"] = new_process
with open(path + ".yaml", "w") as f:
yaml.dump(recipe, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment