#!/usr/bin/env python3

import traceback
import sys

from os2borgerpc.client.config import OS2borgerPCConfig
from os2borgerpc.client.admin_client import get_default_admin


def help():
    print("This program takes n number of config keys to push to the adminsite")
    print("Example: os2borgerpc_push_config_keys job_timeout hostname")
    sys.exit(1)


if len(sys.argv) < 2:
    print("Zero arguments passed. This program requires at least one argument")
    help()

try:
    config = OS2borgerPCConfig()
    to_push = {}
    for name in sys.argv[1:]:
        to_push[name] = config.get_value(name)
    if to_push:
        admin = get_default_admin()
        admin.push_config_keys(config.get_value("uid"), to_push)
        print(
            "The following keys were pushed to the admin system:\n\t%s"
            % (" ".join(sorted(to_push.keys())))
        )
except Exception:
    print("Error pushing config keys:")
    traceback.print_exc()
