ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
python.acmdlib.Command Class Reference

classes ----------------------------------------------------------------— More...

Inheritance diagram for python.acmdlib.Command:
Collaboration diagram for python.acmdlib.Command:

Public Member Functions

def __init__ (self, fct, **kwargs)
 
def name (self)
 
def help (self)
 
def description (self)
 
def add_argument (self)
 
def __call__ (self, *args, **kwargs)
 
def add_mutually_exclusive_group (self, **kwargs)
 

Public Attributes

 fct
 
 parser
 

Private Member Functions

def _make_parser (self, **kwargs)
 
def _init_arguments (self)
 

Private Attributes

 _acmdlib_mutual_group
 

Detailed Description

classes ----------------------------------------------------------------—

A wrapper class to manage the creation of commands and their arguments

this is very heavily inspired from:
http://pypi.python.org/pypi/django-boss (MIT licence)

Definition at line 42 of file acmdlib.py.

Constructor & Destructor Documentation

◆ __init__()

def python.acmdlib.Command.__init__ (   self,
  fct,
**  kwargs 
)

Definition at line 49 of file acmdlib.py.

49  def __init__(self, fct, **kwargs):
50  object.__init__(self)
51  self.fct = fct
52  self.parser = self._make_parser(**kwargs)
53  self._init_arguments()
54  plugin_name = kwargs.get('name') or self.name
55  register(plugin_name, self.fct.__module__)
56 

Member Function Documentation

◆ __call__()

def python.acmdlib.Command.__call__ (   self,
args,
**  kwargs 
)

Definition at line 76 of file acmdlib.py.

76  def __call__(self, *args, **kwargs):
77  return self.fct(*args, **kwargs)
78 

◆ _init_arguments()

def python.acmdlib.Command._init_arguments (   self)
private

Definition at line 122 of file acmdlib.py.

122  def _init_arguments(self):
123  if hasattr(self.fct, '_acmdlib_arguments'):
124  while self.fct._acmdlib_arguments:
125  args, kwargs = self.fct._acmdlib_arguments.pop()
126  self.add_argument(*args, **kwargs)
127 
128  if hasattr(self.fct,'_acmdlib_arguments_mutual'):
129  if not hasattr(self, '_acmdlib_mutual_group'):
130  self._acmdlib_mutual_group = self.add_mutually_exclusive_group()
131  while self.fct._acmdlib_arguments_mutual:
132  args, kwargs = self.fct._acmdlib_arguments_mutual.pop()
133  self._acmdlib_mutual_group.add_argument(*args, **kwargs)
134 

◆ _make_parser()

def python.acmdlib.Command._make_parser (   self,
**  kwargs 
)
private
Create and register a subparser for this command.

Definition at line 79 of file acmdlib.py.

79  def _make_parser(self, **kwargs):
80  """Create and register a subparser for this command."""
81 
82  kwargs.setdefault('help', self.help)
83  kwargs.setdefault('formatter_class',argparse.RawDescriptionHelpFormatter)
84  kwargs.setdefault('description', self.description)
85  kwargs.setdefault('name', self.name)
86  names = (kwargs.get('name') or self.name).split('.')
87 
88  def _get_subparser(a):
89  if a._subparsers:
90  for action in a._subparsers._actions:
91  if isinstance(action, argparse._SubParsersAction):
92  return action
93  raise RuntimeError('could not find adequate subparser')
94  return a.add_subparsers(dest='command',
95  title='commands',
96  metavar='COMMAND')
97  def _get_parser(node, idx, names):
98  name = names[idx]
99  if name in node.choices:
100  return node.choices[name]
101  args = {
102  'name' : name,
103  'help' : 'a group of sub-commands',
104  }
105  return node.add_parser(**args)
106 
107  parser = ACMD_PARSER
108  node = _get_subparser(parser)
109 
110  for i,n in enumerate(names[:-1]):
111  node = _get_subparser(parser)
112  parser = _get_parser(node, i, names)
113 
114  node = _get_subparser(parser)
115  kwargs['name'] = names[-1]
116  parser = node.add_parser(**kwargs)
117  return parser
118 

◆ add_argument()

def python.acmdlib.Command.add_argument (   self)

Definition at line 73 of file acmdlib.py.

73  def add_argument(self):
74  return self.parser.add_argument
75 

◆ add_mutually_exclusive_group()

def python.acmdlib.Command.add_mutually_exclusive_group (   self,
**  kwargs 
)

Definition at line 119 of file acmdlib.py.

119  def add_mutually_exclusive_group(self, **kwargs):
120  return self.parser.add_mutually_exclusive_group(**kwargs)
121 

◆ description()

def python.acmdlib.Command.description (   self)

Definition at line 68 of file acmdlib.py.

68  def description(self):
69  if getattr(self.fct, '__doc__', None):
70  return textwrap.dedent(self.fct.__doc__)
71 

◆ help()

def python.acmdlib.Command.help (   self)

Definition at line 62 of file acmdlib.py.

62  def help(self):
63  if getattr(self.fct, '__doc__', None):
64  # just the first line of the doc string
65  return self.fct.__doc__.splitlines()[0]
66 

◆ name()

def python.acmdlib.Command.name (   self)

Definition at line 58 of file acmdlib.py.

58  def name(self):
59  return self.fct.__name__.replace('_','-')
60 

Member Data Documentation

◆ _acmdlib_mutual_group

python.acmdlib.Command._acmdlib_mutual_group
private

Definition at line 130 of file acmdlib.py.

◆ fct

python.acmdlib.Command.fct

Definition at line 51 of file acmdlib.py.

◆ parser

python.acmdlib.Command.parser

Definition at line 52 of file acmdlib.py.


The documentation for this class was generated from the following file:
register
#define register
Definition: dictionary.h:21
python.CaloScaleNoiseConfig.help
help
Definition: CaloScaleNoiseConfig.py:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88