#!/usr/bin/env python3 from collections import OrderedDict import json import os import subprocess import sys PKG = 'mediawiki/minus-x' GRR = '/home/km/.venvs/grr/bin/grr' if not os.path.exists('composer.json'): print('Error: composer.json does not exist') sys.exit(0) with open('composer.json', 'r') as f: j = json.load(f, object_pairs_hook=OrderedDict) if 'require-dev' not in j: print('Error: repo has no dev deps setup yet') sys.exit(0) if PKG in j['require-dev']: print('Error: MinusX already setup') sys.exit(0) j['require-dev'][PKG] = '0.2.0' j['scripts']['test'].append('minus-x check .') if 'fix' in j['scripts']: if isinstance(j['scripts']['fix'], list): j['scripts']['fix'].append('minus-x fix .') else: j['scripts']['fix'] = [ j['scripts']['fix'], 'minus-x fix .' ] else: j['scripts']['fix'] = ['minus-x fix .'] with open('composer.json', 'w') as f: out = json.dumps(j, indent='\t', ensure_ascii=False) f.write(out + '\n') print('Updated composer.json') subprocess.check_call(['composer', 'update']) subprocess.check_call(['composer', 'test']) subprocess.call(['git', 'diff']) subprocess.call([GRR, 'init']) subprocess.check_call(['git', 'add', 'composer.json']) subprocess.check_call(['git', 'commit', '-m', 'build: Adding MinusX']) subprocess.check_call([GRR, '--topic=MinusX'])