File: __main__.py

package info (click to toggle)
dune-common 2.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: cpp: 52,256; python: 3,979; sh: 1,658; makefile: 17
file content (117 lines) | stat: -rw-r--r-- 5,182 bytes parent folder | download | duplicates (2)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception

import sys
from argparse import ArgumentParser
from dune.commands import ( printinfo, configure, listgenerated,
                            rmgenerated, makegenerated,
                            fixdunepy, listdunetype, checkbuilddirs
                          )

# NOTE: do not import from dune.common (and consequently from dune.generator)
#       at top level to avoid failure due to missing mpi4py.


def run(arguments=None):
    parser = ArgumentParser(description='Execute DUNE commands', prog='dune')
    subparsers = parser.add_subparsers(dest='command')

    # Info
    parserConfigure = subparsers.add_parser('info',
              help='Print information about dune-py')

    # Configure
    parserConfigure = subparsers.add_parser('configure',
              help='Tag dune-py to be reconfigured before next use')

    # List
    parserList = subparsers.add_parser('list', help='List all generated modules')
    parserList.add_argument('--alphabetical', dest='sort', action='store_const', const='alphabetical', default='bydate',
              help='List modules in alphabetical order (default: by date)')
    parserList.add_argument('--ccfiles', dest='ccfiles', action='store_const', const=True, default=False,
              help='List modules by .cc ending instead of .so')

    # Remove
    parserRemove = subparsers.add_parser('remove', help='Remove generated modules')
    parserRemove.add_argument('--beforedate', dest='date', action='store_const', const=True, default=False,
              help='Instead of a pattern provide a date to remove all modules not having been loaded after that date')
    parserRemove.add_argument('--file',  dest='file', default="",
              help='name of a file containing list of modules to remove (one per line)')
    parserRemove.add_argument('modules', nargs='*',  default=[],
              help='Patterns of modules ("*.cc" and dune-py path is added to each argument) or "all"')

    # make
    parserMake = subparsers.add_parser('make', help='Remake generated modules')
    parserMake.add_argument('-j', dest='threads', type=int, default=4,
              help='number of threads to use for compilation of modules. Defaults to 4.')
    parserMake.add_argument('--file',  dest='file', default="",
              help='name of a file containing list of modules to make (one per line)')
    parserMake.add_argument('--force', dest='force', action='store_const', const=True, default=False,
              help='force make without checking dependencies (same as "make -B"')
    parserMake.add_argument('-B', dest='bforce', action='store_const', const=True, default=False,
              help='force make without checking dependencies (same as "make -B"')
    parserMake.add_argument('modules', nargs='*',  default=[],
              help='Patterns of modules ("*.cc" and dune-py path is added to each argument) or "all"')

    # Fix dune-py
    parserFix = subparsers.add_parser('fix-dunepy',
              help='Find inconsistencies in dune-py and try to fix automatically. This will potentially delete all generated modules.')
    parserFix.add_argument('--force', dest='force', action='store_const', const=True, default=False,
              help='force complete removal of dune-py without checking for inconsistencies')

    # Dunetype
    parserDunetype = subparsers.add_parser('dunetype', help='Show dune types for given modules')
    parserDunetype.add_argument('modules', nargs='*', default=[],
              help='Patterns of modules ("*.cc" and dune-py path is added to each argument) or "all"')

    # CheckBuildDirs
    parserCheckBuildDirs = subparsers.add_parser('checkbuilddirs', help='(internal use) Check build directories')
    parserCheckBuildDirs.add_argument('args', nargs='+', default=[],
              help='Dune module name and string with builddirs separated by ";"')


    ret = 0
    args = parser.parse_args(arguments)

    if args.command == 'info':
        ret = printinfo()

    elif args.command == 'configure':
        ret = configure()

    elif args.command == 'list':
        ret = listgenerated(args.sort, args.ccfiles)

    elif args.command == 'remove':
        if args.modules == [] and args.file == '':
            parserRemove.print_help()
        else:
            ret = rmgenerated(args.modules, args.file, args.date)

    elif args.command == 'make':
        if args.modules == [] and args.file == '':
            parserMake.print_help()
        else:
            ret = makegenerated(args.modules, args.file, args.threads,
                                args.force or args.bforce)

    elif args.command == 'fix-dunepy':
        ret = fixdunepy(args.force)

    elif args.command == 'dunetype':
        if args.modules == []:
            parserDunetype.print_help()
        else:
            ret = listdunetype(args.modules)

    elif args.command == 'checkbuilddirs':
        ret = checkbuilddirs(args.args)

    else:
        parser.print_help()

    sys.exit(ret)


if __name__ == '__main__':
    sys.exit( run() )