Browse Source

lodel_admin.py options and output enhancement

- add a -L options to list availables actions
Yann Weber 8 years ago
parent
commit
7723ab5b16
3 changed files with 24 additions and 3 deletions
  1. 3
    0
      lodel/plugin/core_scripts.py
  2. 1
    0
      lodel/plugin/plugins.py
  3. 20
    3
      lodel/plugin/scripts.py

+ 3
- 0
lodel/plugin/core_scripts.py View File

@@ -1,5 +1,8 @@
1 1
 import lodel.plugin.scripts as lodel_script
2 2
 
3
+##@brief Implements lodel_admin.py discover-plugin action
4
+#
5
+#In depth directory scan to find plugins.
3 6
 class DiscoverPlugin(lodel_script.LodelScript):
4 7
     _action = 'discover-plugin'
5 8
     _description = 'Walk through given folders looking for plugins'

+ 1
- 0
lodel/plugin/plugins.py View File

@@ -516,6 +516,7 @@ name differ from the one found in plugin's init file"
516 516
     #@param no_cache bool : if true only return a list of found plugins 
517 517
     #without modifying the cache file
518 518
     #@return a dict {'path_list': [...], 'plugins': { see @ref _discover }}
519
+    #@todo add max_depth and symlink following options
519 520
     @classmethod
520 521
     def discover(cls, paths = None, no_cache = False):
521 522
         logger.info("Running plugin discover")

+ 20
- 3
lodel/plugin/scripts.py View File

@@ -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])

Loading…
Cancel
Save