#!/usr/bin/python3
# pylint: disable=invalid-name  # https://github.com/PyCQA/pylint/issues/516

"""
Migrate keyring packages up to stable.

keyring-packages should be available in all (non-experimental) suites,
and most importantly in the 'upmost' (stable) suite. These packages
usually don't really need an audit/manual migration, so this automates
this tedious task (as long as there is no support for this in
mini-buildd itself).

No need to change SUITES if your are using (one of) the default
layouts.

1.0.x: No need to change PROTO unless you set up a https proxy
(and want to use it).

Typical example:

mbu-migrate-keyring-packages my-archive admin@my-host.intra.net:8066

"""

import sys
from mini_buildd.api.client_1_0 import Daemon

# Setup
try:
    # @todo: The archive id should be in status, too
    ARCHIVE_ID = sys.argv[1]
    USER, DUMMY, HOPO = sys.argv[2].rpartition("@")
    HOST, DUMMY, PORT = HOPO.partition(":")
    if PORT == "":
        PORT = 8066
    PROTO = sys.argv[3] if len(sys.argv) > 3 else "http"
    # @todo: Suite names should be in status, too
    SUITES = sys.argv[4].split(",") if len(sys.argv) > 4 else ["unstable", "testing"]
except BaseException as e:
    print("Error: {e}".format(e=e))
    print("Usage: mbu-migrate-keyring-packages <ARCHIVE_ID> <USER@my-host.xyz[:PORT]> [<PROTO>=http] [<SUITES>=unstable,testing]", file=sys.stderr)
    sys.exit(1)

MBD = Daemon(HOST, PORT, PROTO)
MBD.login(USER)
MBD.bulk_migrate(["{id}-archive-keyring".format(id=ARCHIVE_ID)])
