#!/usr/bin/env python3

import xroot

import sys
import getopt

from os import path

config = '.wset'

def main():
    config_path = path.join(path.expanduser('~'), config)
    try:
        opts, args = getopt.getopt(sys.argv[1:],
                                   "i:",
                                   ["image"])
    except getopt.error as msg:
        print(msg)
        sys.exit(2)

    for o, a in opts:
        if o in ("-i", "--image"):
            f = open(config_path, 'w+')
            f.write(a)
            f.close()
            xroot.set(a)

            sys.exit(0)

    f = open(config_path, 'r')
    image = f.readline()
    f.close()
    xroot.set(image)

if __name__ == "__main__":
    main()
