Last active
January 30, 2020 17:38
-
-
Save homebysix/6ff057606107c4649292197603a78262 to your computer and use it in GitHub Desktop.
convert_autopkg_recipes_to_yaml.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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