Belle II Software light-2406-ragdoll
modules.py
1#!/usr/bin/env python3
2
3
10
11import sys
12import pybasf2
13from basf2.utils import print_all_modules, print_params
14from basf2.core import set_log_level
15from terminal_utils import Pager
16
17
18def print_module_list(modName=None):
19 """
20 This wraps around the ``print_all_modules`` function but sanitizes potential command line arguments before doing so.
21
22 Parameters:
23 modName: Can be the name of a module or package. Prints more information about a specific module or reduces the output
24 to requested package.
25 """
26
27 # Do not show INFO messages in module list (actually a problem of the module)
28 set_log_level(pybasf2.LogLevel.WARNING)
29
30 # Get the list of available modules
31 avModList = pybasf2.list_available_modules()
32
33 if modName is not None:
34 # If exactly one argument is given, print the specified module.
35 if modName in avModList:
36 try:
37 current_module = pybasf2._register_module(modName)
38 with Pager(f'Module information for "{modName}"', quit_if_one_screen=True):
39 print_params(current_module, False, avModList[modName])
40 except pybasf2.ModuleNotCreatedError:
41 pybasf2.B2FATAL('The module could not be loaded.')
42 except Exception as e:
43 pybasf2.B2FATAL(f"An exception occured when trying to create the module: {e}")
44
45 elif modName == modName.lower():
46 # lower case? might be a package instead
47 with Pager(f'List of modules in package "{modName}"'):
48 print_all_modules(avModList, modName)
49 else:
50 pybasf2.B2FATAL('Print module information: A module with the name "' +
51 modName + '" does not exist!')
52 else:
53 # Otherwise print all modules.
54 with Pager('List of all basf2 modules'):
55 print_all_modules(avModList)
56
57
58if __name__ == "__main__":
59 try:
60 argument = sys.argv[1]
61 except IndexError:
62 argument = None
63 finally:
64 print_module_list(argument)