#! /usr/bin/python
# -*- coding: utf-8 -*-

import pisi.install
import pisi.util

def usage(progname = "pisi-install"):
    print """
Usage:
%s [options] <packagefilename>
""" %(progname)

def main():
    import sys
    import getopt
    
    # wrapper for usage(progname) function
    help = lambda: usage(sys.argv[0])

    # getopt magic
    try:
	opts, args = getopt.getopt(sys.argv[1:],"h",["help"])
    except getopt.GetoptError:
	help()
	sys.exit(1)

    for opt, arg in opts:
	if opt == "-h":
	    help()
	    sys.exit(1)

    # package filename
    package_fn = ""

    # TODO: We accept only one pspec file (at a time) currently,
    # but pisi-build may build many packages (pspecs given in order)
    # sequentially.
    if len(args) != 1:
	help()
	raise pisi.util.ArgError, "pisi-install expects one (and only one) package file currently"
    else:
	package_fn = args[0]

    pisi.install.install_package_file(package_fn)


if __name__ == "__main__":
    main()
