mpcdf_enable_repositories.py 4.41 KB
Newer Older
1
2
3
#!/usr/bin/python2
from __future__ import print_function

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

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

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
12

13
14
15
16
17
18
19
20
21
22
@osc.cmdln.option('--recreate', action="store_true",
                  help="Re-create the set of enabled repositories from the stored attributes on the server")
@osc.cmdln.option('--compiler-modules', nargs=1,
                  help="Restrict the set of compilers to use")
@osc.cmdln.option('--mpi-modules', nargs=1,
                  help="Restrict the set of MPI implementations to use")
@osc.cmdln.option('--cuda-modules', nargs=1,
                  help="Restrict the set of CUDA implementations to use")
@osc.cmdln.option('--set', nargs=1, metavar="FLAGS",
                  help="Modify the set of enabled repositories, without this the current setup is displayed. "
23
                       "FLAGS is a comma-separated list of a subset of 'system', 'compilers', 'mpi', 'cuda_mpi'")
24
@osc.cmdln.alias("mpcdf_enable_repos")
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def do_mpcdf_enable_repositories(self, subcmd, opts, *args):
    """${cmd_name}: Select all appropriate repositories for an MPCDF package

    Due to the large number of repository combinations at MPCDF it is
    cumbersome to enable all the appropriate repositories for a given package
    by hand.

    This command allows you to set the <enable/> flags for certain kinds of
    repositories at once.

    Without --set this command only displays the current configuration.

    It is possible to combine this with user-defined <disabled/> flags that
    override the settings of this command, for example to disable the build of
    the package with a certain repository from a given set (e.g. one
    troublesome compiler)

    Usage:
43
44
45
        osc ${cmd_name}                       [[PROJECT] PACKAGE]
        osc ${cmd_name} --set FLAGS [options] [[PROJECT] PACKAGE]
        osc ${cmd_name} --recreate            [[PROJECT] PACKAGE]
46
47
48
49
50

    ${cmd_option_list}
    """

    if len(args) == 0:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
51
        if osc.core.is_package_dir(os.curdir):
52
53
54
            package = osc.core.store_read_package(os.curdir)
            project = osc.core.store_read_project(os.curdir)
        else:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
55
            raise osc.oscerr.WrongArgs('Specify PACKAGE or run command in an osc package checkout directory')
56
57
58
59
60
61
62
63

    elif len(args) == 1:
        package, = args
        project = osc.core.store_read_project(os.curdir)

    elif len(args) == 2:
        project, package = args
    else:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
64
        raise osc.oscerr.WrongArgs("Too many arguments")
65
66
67
68

    api_url = self.get_api_url()

    if opts.set:
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
        mpcdf_common.set_attribute_values(api_url, project, package, "MPCDF:enable_repositories", opts.set.split(","))

        def set_or_remove(flag, attribute_name):
            if flag:
                print("Setting attribute", attribute_name, "to", flag)
                mpcdf_common.set_attribute_values(api_url, project, package, attribute_name, flag.split(","))
            elif mpcdf_common.has_attribute(api_url, project, package, attribute_name):
                print("Removing attribute", attribute_name, "from package")
                mpcdf_common.remove_attribute(api_url, project, package, attribute_name)

        set_or_remove(opts.mpi_modules,      "MPCDF:mpi_modules")
        set_or_remove(opts.cuda_modules,     "MPCDF:cuda_modules")
        set_or_remove(opts.compiler_modules, "MPCDF:compiler_modules")

    if opts.recreate or opts.set:
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
84
        mpcdf_common.mpcdf_enable_repositories(api_url, project, package, verbose=True)
85
    elif (opts.compiler_modules or opts.mpi_modules or opts.cuda_modules):
86
        print("ERROR: Invalid arguments, try --help")
87
    else:
88
89
90
91
92
93
        try:
            repos = mpcdf_common.get_attribute_values(api_url, project, package, "MPCDF:enable_repositories")
        except Exception:
            repos = ()
            print("ERRROR: No attribute MPCDF:enable_repositories present, package unmanaged")
        if repos:
94
95
96
97
98
99
100
            def print_attr(description, attribute_name):
                try:
                    values = mpcdf_common.get_attribute_values(api_url, project, package, attribute_name)
                except Exception:
                    return
                print(description, ", ".join(values))

101
            print("Enabled for:", *repos)
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
102
103
104
            print_attr("- Subset of compiler modules set to:", "MPCDF:compiler_modules")
            print_attr("- Subset of MPI modules set to:", "MPCDF:mpi_modules")
            print_attr("- Subset of CUDA modules set to:", "MPCDF:cuda_modules")