#!/usr/bin/env python

import sys, os, config

def main():
    args = sys.argv[1:]
    if len(args) % 2 != 0:
        print("ERROR: Please provide pairs of <name> <value>")
        return

    for i in range(0, len(args), 2):
        name = args[i]
        value = args[i + 1]
        changed = False

        for file in config.FILES:
            if os.path.exists(file):
                if config.set(file, name, value):
                    changed = True

        if not changed:
            config.add(config.FILES[0], name, value)

if __name__ == "__main__":
    main()
