Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
add a way of keeping deps in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
eeue56 committed Mar 10, 2016
1 parent 69d8952 commit 70d25c0
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions elm_deps_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#! /usr/bin/env python
from __future__ import print_function

import sys
import json
import argparse


def sync_versions(top_level_file, spec_file, quiet=False, dry=False):
""" first file should be the top level elm-package.json
second file should be the spec file
"""

with open(top_level_file) as f:
top_level = json.load(f)

with open(spec_file) as f:
spec = json.load(f)

messages = []

for (package_name, package_version) in top_level['dependencies'].items():
if package_name not in spec['dependencies']:
spec['dependencies'][package_name] = package_version

messages.append('Package {package_name} inserted to {spec_file} for the first time at version "{package_version}"'.format(
package_name=package_name, spec_file=spec_file, package_version=package_version)
)
elif spec['dependencies'][package_name] != package_version:
spec['dependencies'][package_name] = package_version

messages.append('Changing {package_name} from version {package_version} to {other_package_version}'.format(
package_version=package_version, package_name=package_name,
other_package_version=spec['dependencies'][package_name])
)

if len(messages) > 0:
print('{number} files changed.'.format(number=len(messages)))

if not dry:
with open(spec_file, 'w') as f:
f.write(json.dumps(spec))
else:
print("No changes written.")

if not quiet:
print('\n'.join(messages))
else:
print('No changes needed.')


def main():

parser = argparse.ArgumentParser(description='Sync deps between a parent and a sub')

parser.add_argument('--quiet', '-q', action='store_true', help='don\'t print anything', default=False)
parser.add_argument('--dry', '-d', action='store_true', help='only print possible changes', default=False)


parser.add_argument('top_level_file')
parser.add_argument('spec_file')
args = parser.parse_args()

sync_versions(args.top_level_file, args.spec_file, quiet=args.quiet, dry=args.dry)


if __name__ == '__main__':
main()

0 comments on commit 70d25c0

Please sign in to comment.