|
@@ -30,7 +30,7 @@ action identifier" % name)
|
30
|
30
|
if self._description is None:
|
31
|
31
|
self._description = self._default_description()
|
32
|
32
|
self._parser = argparse.ArgumentParser(
|
33
|
|
- prog = self._prog_name,
|
|
33
|
+ prog = self._prog_name(),
|
34
|
34
|
description = self._description)
|
35
|
35
|
self.argparser_config(self._parser)
|
36
|
36
|
|
|
@@ -46,6 +46,9 @@ action identifier" % name)
|
46
|
46
|
self._action = self._action.lower()
|
47
|
47
|
script_registration(self._action, self)
|
48
|
48
|
|
|
49
|
+ def __str__(self):
|
|
50
|
+ return '%s : %s' % (self._action, self._description)
|
|
51
|
+
|
49
|
52
|
class LodelScript(object, metaclass=MetaLodelScript):
|
50
|
53
|
|
51
|
54
|
##@brief A string to identify the action
|
|
@@ -87,7 +90,7 @@ MUST be implemented by ALL child classes")
|
87
|
90
|
#@note See argparse.ArgumentParser() prog argument
|
88
|
91
|
@classmethod
|
89
|
92
|
def _prog_name(cls):
|
90
|
|
- return '%s %s' % (sys.argv[0], self._action)
|
|
93
|
+ return '%s %s' % (sys.argv[0], cls._action)
|
91
|
94
|
|
92
|
95
|
##@brief Return the default description for an action
|
93
|
96
|
@classmethod
|
|
@@ -120,18 +123,32 @@ def _default_parser():
|
120
|
123
|
action_list = 'NO SCRIPT FOUND !'
|
121
|
124
|
|
122
|
125
|
parser = argparse.ArgumentParser(description = "Lodel2 script runner")
|
|
126
|
+ parser.add_argument('-L', '--list-actions', action='store_true',
|
|
127
|
+ default=False, help="List available actions")
|
123
|
128
|
parser.add_argument('action', metavar="ACTION", type=str,
|
124
|
|
- help="One of the following actions : %s" % action_list)
|
|
129
|
+ help="One of the following actions : %s" % action_list, nargs='?')
|
125
|
130
|
parser.add_argument('option', metavar="OPTIONS", type=str, nargs='*',
|
126
|
131
|
help="Action options. Use %s ACTION -h to have help on a specific \
|
127
|
132
|
action" % sys.argv[0])
|
128
|
133
|
return parser
|
129
|
134
|
|
|
135
|
+##@brief Main function of lodel_admin.py script
|
|
136
|
+#
|
|
137
|
+#This function take care to run the good plugins and clean sys.argv from
|
|
138
|
+#action name before running script
|
|
139
|
+#
|
|
140
|
+#@return DO NOT RETURN BUT exit() ONCE SCRIPT EXECUTED !!
|
130
|
141
|
def main_run():
|
131
|
142
|
default_parser = _default_parser()
|
132
|
143
|
if len(sys.argv) == 1:
|
133
|
144
|
default_parser.print_help()
|
134
|
145
|
exit(1)
|
|
146
|
+ args = default_parser.parse_args()
|
|
147
|
+ if args.list_actions:
|
|
148
|
+ print("Available actions :")
|
|
149
|
+ for sname in sorted(__registered_scripts.keys()):
|
|
150
|
+ print("\t- %s" % __registered_scripts[sname])
|
|
151
|
+ exit(0)
|
135
|
152
|
#preparing sys.argv (deleting action)
|
136
|
153
|
action = sys.argv[1].lower()
|
137
|
154
|
del(sys.argv[1])
|