#!/usr/bin/python3 -s
from l3tlib.command import L3tCommand


class PackageBinaries(L3tCommand):

    descr = """Search for binaries of a given source package

Notice that the approach used by this tool (searching packages based on the
disturl hash) does not work for multispec packages.
"""
    usage = "%prog -p <product> <source-package>"

    def init_parser(self, parser):
        super(PackageBinaries, self).init_parser(parser)
        parser.add_option("-p", "-D", "--product", default=None,
                          help="ptfutils product name (required)")

    def parse_args(self, parser, args):
        opts, args = super(PackageBinaries, self).parse_args(parser, args)
        if opts.product is None:
            parser.error("--product is required")
        if not args:
            parser.error("no source package names provided")
        return opts, args

    def run(self):
        for arg in self.args:
            names = self.l3t.binaries_from_source(self.opts.product, arg)
            print(", ".join(names))

PackageBinaries().main()
