#!/usr/bin/python
# -*- coding: utf-8 -*-
"""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:

migrate-keyring-packages my-archive admin@my-host.intra.net:8066
"""
from __future__ import unicode_literals
from __future__ import print_function

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:
    print("Usage: 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)])
