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