#!/usr/bin/env python

"""
Script that reads a Cygwin package list and returns a comma-separated list of
package names to be passed to Cygwin's setup.exe as the --packages argument.
"""

from __future__ import print_function

import argparse
import sys


def main(argv=None):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('file', metavar='FILE', type=argparse.FileType('r'),
                        help='path to a list of Cygwin packages; the format '
                             'of this file is currently underspecified, but '
                             'is typically two columns: one of package names '
                             'and one of package versions; currently only the '
                             'package names are used')
    args = parser.parse_args(argv)

    with args.file as f:
        packages = []
        for line in f:
            package, version = [s.strip() for s in line.split()][:2]
            packages.append((package, version))

    print(','.join(p[0] for p in packages))


if __name__ == '__main__':
    sys.exit(main())
