#!/@GENTOO_PORTAGE_EPREFIX@usr/bin/python -E # -*- coding: UTF-8 -*- # Copyright 2004-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ from java_config_2.OutputFormatter import OutputFormatter from java_config_2.EnvironmentManager import EnvironmentManager from java_config_2.Errors import * from java_config_2.VersionManager import * import os import sys from optparse import OptionParser, make_option, OptionValueError def version(option, opt, value, parser): printer._print("%H%BJava Dep Query Utility %GVersion @PACKAGE_VERSION@") raise SystemExit() def nocolor(option, opt, value, parser): printer.setColorOutputStatus(False) def is_sufficient(option, opt, value, parser): try: if verman.version_satisfies(value,manager.get_active_vm()): printer._print("Active vm satisfies the depend string") sys.exit(0) else: printer._print("Active vm does NOT satisfy the depend string") sys.exit(1) except RuntimeError as ex: printer._printError(str(ex)) sys.exit(1) def get_vm(option, opt, value, parser): try: vm = verman.get_vm(value, True) printer._print(vm) except Exception as ex: printer._printError(str(ex)) sys.exit(1) def get_lowest(option, opt, value, parse): try: printer._print(verman.get_lowest(value)) except Exception as ex: printer._printError(str(ex)) sys.exit(1) def parse_depend_string(option, opt, value, parse): try: results = verman.parse_depend(value) output = "" for result in results: output += " " + result['equality'] + "virtual/" + result['type'] + "-" + result['version'] printer._print(output.strip()) except: printer._printError(str(ex)) sys.ext(1) if __name__ == '__main__': global printer, manager, verman printer = OutputFormatter(True, True) manager = EnvironmentManager(os.getenv('ROOT', ''), os.getenv('EPREFIX', '@GENTOO_PORTAGE_EPREFIX@')) verman = VersionManager(manager) usage = "depend-java-query [options]\n\n" usage += "Java Dep Query Utility Version @PACKAGE_VERSION@\n" usage += "Copyright 2004-2013 Gentoo Foundation\n" usage += "Distributed under the terms of the GNU General Public License v2\n" usage += "Please contact the Gentoo Java Herd with problems." options_list = [ make_option ("-V", "--version", action="callback", callback=version, help="Print version information"), make_option ("-n", "--nocolor", action="callback", callback=nocolor, help="Disable color output"), make_option ("-s", "--is-sufficient", action="callback", callback=is_sufficient, help="Check a depend string and see if current-vm is sufficiant", type="string", dest="dependstr"), make_option ("-v", "--get-vm", action="callback", callback=get_vm, help="Return the best vm for this dep string", type="string", dest="dependstr"), make_option ("-l", "--get-lowest", action="callback", callback=get_lowest, help="Return the lowest version in the depend, to be used with -target/-source fex.", type="string", dest="dependstr"), make_option ("-P", "--parse-depend", action="callback", callback=parse_depend_string, help="", type="string", dest="dependstr" ) ] parser = OptionParser(usage, options_list) (options, args) = parser.parse_args() # vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap: