#!/usr/bin/python3

# This script can be used when new versions of Coq packages get
# released, to check everything is ok with the rest of the stack.
#
# You're supposed to call it with a space-separated list of packages
# with a new version, and the result is generally several lines of
# space-separated package names corresponding to what needs to be
# rebuilt, where packages on the same line can be compiled at the same
# time.
#
# If you use sbuild to compile the packages, with sbuid configured
# with a local repo, you can then put the packages in the repo step by
# step and check that the new versions don't break anything.

import argparse
from coq_packages import group_by, hauteur, transitive_rdeps

parser = argparse.ArgumentParser(description='Planify the transition in Debian for new Coq packages')

parser.add_argument('packages', metavar='N', nargs='+', help='(source) package names')
parser.add_argument('-org-mode', '--org-mode', action='store_true', help='present as org-mode chunk')

args = parser.parse_args()

groups = group_by(transitive_rdeps(args.packages), hauteur)

if not args.org_mode:
    for group in groups:
        print(' '.join([f'{name}' for name in group]))
else:
    step = 0
    print ('* Update Coq [/]')
    for group in groups:
        step = step + 1
        print (f' - [ ] step {step} [/]')
        for name in group:
            print (f'   - [] {name}')
