import argparse
import json
import os.path
import uuid

VENDOR: str
LICENSE_PATH: str


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("license", nargs="?", default=None)
    args = parser.parse_args()

    if args.license is None:
        license = None
        if os.path.isfile(LICENSE_PATH):
            with open(LICENSE_PATH, "r") as f:
                license = f.read()
        print(json.dumps({"vendor": VENDOR, "license": license, "device_id": str(uuid.getnode())}))
    else:
        if args.license:
            with open(LICENSE_PATH, "w") as f:
                f.write(args.license)
        elif os.path.isfile(LICENSE_PATH):
            os.unlink(LICENSE_PATH)


if __name__ == "__main__":
    main()
