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
 import lodel.plugin.scripts as lodel_script
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
 class DiscoverPlugin(lodel_script.LodelScript):
6
 class DiscoverPlugin(lodel_script.LodelScript):
4
     _action = 'discover-plugin'
7
     _action = 'discover-plugin'
5
     _description = 'Walk through given folders looking for plugins'
8
     _description = 'Walk through given folders looking for plugins'

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

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

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

30
         if self._description is None:
30
         if self._description is None:
31
             self._description = self._default_description()
31
             self._description = self._default_description()
32
         self._parser = argparse.ArgumentParser(
32
         self._parser = argparse.ArgumentParser(
33
-            prog = self._prog_name,
33
+            prog = self._prog_name(),
34
             description = self._description)
34
             description = self._description)
35
         self.argparser_config(self._parser)
35
         self.argparser_config(self._parser)
36
             
36
             
46
         self._action = self._action.lower()
46
         self._action = self._action.lower()
47
         script_registration(self._action, self)
47
         script_registration(self._action, self)
48
 
48
 
49
+    def __str__(self):
50
+        return '%s : %s' % (self._action, self._description)
51
+
49
 class LodelScript(object, metaclass=MetaLodelScript):
52
 class LodelScript(object, metaclass=MetaLodelScript):
50
     
53
     
51
     ##@brief A string to identify the action
54
     ##@brief A string to identify the action
87
     #@note See argparse.ArgumentParser() prog argument
90
     #@note See argparse.ArgumentParser() prog argument
88
     @classmethod
91
     @classmethod
89
     def _prog_name(cls):
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
     ##@brief Return the default description for an action
95
     ##@brief Return the default description for an action
93
     @classmethod
96
     @classmethod
120
         action_list = 'NO SCRIPT FOUND !'
123
         action_list = 'NO SCRIPT FOUND !'
121
 
124
 
122
     parser = argparse.ArgumentParser(description = "Lodel2 script runner")
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
     parser.add_argument('action', metavar="ACTION", type=str,
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
     parser.add_argument('option', metavar="OPTIONS", type=str, nargs='*',
130
     parser.add_argument('option', metavar="OPTIONS", type=str, nargs='*',
126
         help="Action options. Use %s ACTION -h to have help on a specific \
131
         help="Action options. Use %s ACTION -h to have help on a specific \
127
 action" % sys.argv[0])
132
 action" % sys.argv[0])
128
     return parser
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
 def main_run():
141
 def main_run():
131
     default_parser = _default_parser()
142
     default_parser = _default_parser()
132
     if len(sys.argv) == 1:
143
     if len(sys.argv) == 1:
133
         default_parser.print_help()
144
         default_parser.print_help()
134
         exit(1)
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
     #preparing sys.argv (deleting action)
152
     #preparing sys.argv (deleting action)
136
     action = sys.argv[1].lower()
153
     action = sys.argv[1].lower()
137
     del(sys.argv[1])
154
     del(sys.argv[1])

Loading…
Cancel
Save