Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simplesoft-duongdt3/dc1b5e8876090642136d241ddcfc717d to your computer and use it in GitHub Desktop.
Save simplesoft-duongdt3/dc1b5e8876090642136d241ddcfc717d to your computer and use it in GitHub Desktop.

Revisions

  1. @fabriciovergara fabriciovergara created this gist Feb 17, 2022.
    43 changes: 43 additions & 0 deletions pubspec_base_sync.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    import sys
    import glob
    import ruamel.yaml

    yaml = ruamel.yaml.YAML()

    def main():

    # python3 pubspec_base_sync.py ../pubspec_base_android.yaml ../pubspec_base_android_huawei.yaml

    base_path = '../pubspec_base.yaml'
    modifiers_path = sys.argv[1:]

    with open(base_path, 'r') as base_file:
    base = yaml.load(base_file)

    for modifier_path in modifiers_path:
    with open(modifier_path, 'r') as modifier_file:
    modifier_content = yaml.load(modifier_file)
    base = sync_content(modifier_content, base)

    for path in glob.glob('../packages/**/pubspec.yaml'):
    with open(path, 'r') as read_file:
    content = yaml.load(read_file)
    content = sync_content(base, content)

    with open(path, 'w') as write_file:
    yaml.dump(content, write_file)
    break

    def sync_content(base, content):
    for key_base, value_base in base.items():
    if content is not None and key_base in content:
    if type(value_base) is str or type(value_base) is int:
    content[key_base] = value_base
    elif value_base is not None:
    content[key_base] = sync_content(value_base, content[key_base])

    return content


    if __name__ == '__main__':
    main()