mpcdf_info.py 2.76 KB
Newer Older
1
2
#!/usr/bin/python2
from __future__ import print_function
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
3
from functools import reduce
4

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
5
import mpcdf_common
6

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
7
import os
8
9
10
11
12
import osc
import osc.conf
import osc.core
import osc.cmdln

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
13

14
15
16
17
18
19
20
21
22
23
24
def do_mpcdf_info(self, subcmd, opts, *args):
    """${cmd_name}: Basic information about an MPCDF OBS project

    Usage:
        osc ${cmd_name} [PROJECT]

    ${cmd_option_list}

    """

    if len(args) == 0:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
25
        if osc.core.is_project_dir(os.curdir) or osc.core.is_package_dir(os.curdir):
26
27
            project = osc.core.store_read_project(os.curdir)
        else:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
28
            raise osc.oscerr.WrongArgs('Specify PROJECT or run command in an osc checkout directory')
29
30
31
32

    elif len(args) == 1:
        project, = args
    else:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
33
        raise osc.oscerr.WrongArgs("Too many arguments")
34
35
36
37
38
39

    print("Project `{0}`\n".format(project))

    api_url = self.get_api_url()

    def print_attribute(description, attribute):
40
        if mpcdf_common.has_attribute(api_url, project, None, attribute):
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
41
            values = list(sorted(mpcdf_common.get_attribute_values(api_url, project, None, attribute)))
42
43
44
45
46
47
48
49
50
            print(" {0}:\n   ".format(description) + "\n   ".join(values))
            print()

    print_attribute("Compilers", "MPCDF:compiler_modules")
    print_attribute("MPI libraries", "MPCDF:mpi_modules")
    print_attribute("CUDA versions", "MPCDF:cuda_modules")

    unmanaged = []

51
    packages = osc.core.meta_get_packagelist(api_url, project)
52

53
    pkg_name_width = reduce(max, (len(p) for p in packages))
54
55
56
57
58
59
60
    pkg_name_width = max(pkg_name_width, len("Package"))

    pkg_name_fmt = "{{:{0}}}".format(pkg_name_width)

    print(" " + pkg_name_fmt.format("Package"), "Enabled repositories")
    print(" " + "-" * (pkg_name_width), "-" * len("Enabled repositories"))

61
    for package in packages:
62
        if mpcdf_common.has_attribute(api_url, project, package, "MPCDF:enable_repositories"):
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
63
            enabled_repos = mpcdf_common.get_attribute_values(api_url, project, package, "MPCDF:enable_repositories")
64
        else:
65
66
            unmanaged.append(package)
            continue
67
68
69
70
71
72
73
74
75

        def subset(description, attribute):
            if mpcdf_common.has_attribute(api_url, project, package, attribute):
                return " ({0}: {1})".format(description, ", ".join(mpcdf_common.get_attribute_values(api_url, project, package, attribute)))
            return ""

        print(" " + pkg_name_fmt.format(package), ", ".join(enabled_repos),
              subset("compiler subset", "MPCDF:compiler_modules") +
              subset("MPI subset", "MPCDF:mpi_modules") +
76
              subset("CUDA subet", "MPCDF:cuda_modules"))
77
78
79
80
81
82
83
84
    print()

    if unmanaged:
        print(" Unmanaged packages")
        print(" " + "-" * (1 + pkg_name_width))
        for package in unmanaged:
            print(" " + package)
        print()