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 40 of file acmdlib.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 47 of file acmdlib.py.

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

Member Function Documentation

◆ __call__()

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

Definition at line 74 of file acmdlib.py.

74  def __call__(self, *args, **kwargs):
75  return self.fct(*args, **kwargs)
76 

◆ _init_arguments()

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

Definition at line 120 of file acmdlib.py.

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

◆ _make_parser()

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

Definition at line 77 of file acmdlib.py.

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

◆ add_argument()

def python.acmdlib.Command.add_argument (   self)

Definition at line 71 of file acmdlib.py.

71  def add_argument(self):
72  return self.parser.add_argument
73 

◆ add_mutually_exclusive_group()

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

Definition at line 117 of file acmdlib.py.

117  def add_mutually_exclusive_group(self, **kwargs):
118  return self.parser.add_mutually_exclusive_group(**kwargs)
119 

◆ description()

def python.acmdlib.Command.description (   self)

Definition at line 66 of file acmdlib.py.

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

◆ help()

def python.acmdlib.Command.help (   self)

Definition at line 60 of file acmdlib.py.

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

◆ name()

def python.acmdlib.Command.name (   self)

Definition at line 56 of file acmdlib.py.

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

Member Data Documentation

◆ _acmdlib_mutual_group

python.acmdlib.Command._acmdlib_mutual_group
private

Definition at line 128 of file acmdlib.py.

◆ fct

python.acmdlib.Command.fct

Definition at line 49 of file acmdlib.py.

◆ parser

python.acmdlib.Command.parser

Definition at line 50 of file acmdlib.py.


The documentation for this class was generated from the following file:
register
#define register
Definition: dictionary.h:21
python.CaloAddPedShiftConfig.help
help
Definition: CaloAddPedShiftConfig.py:42
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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