aboutsummaryrefslogtreecommitdiff
blob: f1feefa27cd55c35a6317436d703540a9bb408d0 (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
88
89
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright 2004-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

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):
     import java_config_2
     printer._print(f"%H%BJava Dep Query Utility %GVersion {java_config_2.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
    import java_config_2
    printer = OutputFormatter(True, True)
    manager = EnvironmentManager(os.getenv('ROOT', ''), java_config_2.eprefix)
    verman = VersionManager(manager)

    usage =  "depend-java-query [options]\n\n"
    usage += f"Java Dep Query Utility Version {java_config_2.version}\n"
    usage += "Copyright 2004-2023 Gentoo Authors\n"
    usage += "Distributed under the terms of the GNU General Public License v2\n"
    usage += "Please contact the Gentoo Java Project <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", "--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: