#!/usr/bin/env python3

import collections
import json
import sys
import traceback


def process_file(filename):
    with open(filename, mode='r') as file:
        data = json.load(file, object_pairs_hook=collections.OrderedDict)
    data["VERSION"]["BUILD"] += 1
    with open(filename, mode='w') as file:
        json.dump(data, file, indent=4)


def main():
    result = 0
    for filename in sys.argv[1:]:
        try:
            process_file(filename)
        except Exception as e:
            traceback.print_exc()
            result = 1
    return result


if __name__ == '__main__':
    sys.exit(main())
