#! /usr/bin/env python # # $Id$ # # Copyright 2008 Platform Computing Inc. # # Licensed under GPL version 2; See LICENSE file for details. # from kusu.genupdates.downloader import Downloader from primitive.system.software.probe import OS from optparse import OptionParser import sys import os parser = OptionParser(usage="usage: downloader [options] 'package1' ['package2'] ['package' ..]") parser.add_option('-d', dest='dest', default='.', help='Destination directory') parser.add_option('-t', action="store_true", dest='target', default=False, help='Target the given os ver arch by the --os, --ver and --arch options') parser.add_option('--os', dest='myos', help='Target os name') parser.add_option('--ver', dest='ver', help='Target os version') parser.add_option('--arch', dest='arch', help='Target os arch') (options, args) = parser.parse_args() myos = OS() if options.target: if options.myos is None or options.ver is None or options.arch is None: print("Incomplete target os tuple. Please provide all three options --os, --ver and --arch.") sys.exit(-1) else: myos = (options.myos, options.ver, options.arch) else: if options.myos is not None or options.ver is not None or options.arch is not None: print("Please use --os, --ver and --arch together with -t option.") sys.exit(-1) if len(args) == 0: print("No packages requested. Please provide at least one package to download.") sys.exit(-1) if not os.path.exists(options.dest): os.makedirs(options.dest) destdir = options.dest do = Downloader(destdir, target_os=myos) try: do.downloadPackages(args) except Exception, e: print e