aboutsummaryrefslogtreecommitdiff
blob: 60f5b7b139e7dd00fd92fe488e5e28a56660273b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python -E
# -*- coding: UTF-8 -*-

# Copyright 2004-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

import sys
sys.path = ['/usr/share/java-config/pym']+sys.path

from java_config import __version__
from java_config.OutputFormatter import OutputFormatter
from java_config.EnvironmentManager import EnvironmentManager
from java_config.Errors import *
from java_config.VersionManager import *

import os
import sys
from commands import getoutput
from string    import join

from optparse import OptionParser, make_option, OptionValueError

def version(option, opt, value, parser):
     printer._print("%H%BJava Dep Query Utility %GVersion " + str(__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 satifies the depend string")
            sys.exit(0)
        else:
            printer._print("Active vm does NOT satify the depend string")
            sys.exit(1)

    except RuntimeError, (ex):
        printer._printError(str(ex))
        sys.exit(1)

def get_vm(option, opt, value, parser):
    #try:
        if parser.values.need_virtual is not None:
           vm = verman.get_vm(value, parser.values.need_virtual)
        else:
           vm = verman.get_vm(value)

        printer._print(vm)
    #except Exception, ex:
    #    printer._printError(str(ex))
    #    sys.exit(1)

def get_lowest(option, opt, value, parse):
    try:
        printer._print(verman.get_lowest(value))
    except Exception, ex:
        printer._printError(str(ex))
        sys.exit(1)

if __name__ == '__main__':
    global printer, manager, verman
    printer = OutputFormatter(True, True)
    manager = EnvironmentManager()
    verman = VersionManager()

    usage =  "depend-java-query [options]\n\n"
    usage += "Java Dep Query Utility Version " + str(__version__) + "\n"
    usage += "Copyright 2004-2005 Gentoo Foundation\n"
    usage += "Distributed under the terms of the GNU General Public License v2\n"
    usage += "Please contact the Gentoo Java Herd <java@gentoo.org> 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", "--need-virtual",   action="store",  help="When searching for a vm, make sure this virtual can be provided for.",             type="string", dest="need_virtual")
                   ]

    parser = OptionParser(usage, options_list)
    (options, args) = parser.parse_args()

# vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap: