Kaynağa Gözat

Solves #124 + discover-plugin argparse enhancement

No need of -d flag to specifiy directories
Yann Weber 8 yıl önce
ebeveyn
işleme
70ff2fcedc
3 değiştirilmiş dosya ile 23 ekleme ve 11 silme
  1. 5
    4
      lodel/plugin/core_scripts.py
  2. 11
    7
      lodel/plugin/scripts.py
  3. 7
    0
      plugins/dummy/main.py

+ 5
- 4
lodel/plugin/core_scripts.py Dosyayı Görüntüle

@@ -9,7 +9,8 @@ class DiscoverPlugin(lodel_script.LodelScript):
9 9
     
10 10
     @classmethod
11 11
     def argparser_config(cls, parser):
12
-        parser.add_argument('-d', '--directory',
12
+        #parser.add_argument('-d', '--directory',
13
+        parser.add_argument('PLUGIN_PATH',
13 14
             help="Directory to walk through looking for lodel2 plugins",
14 15
             nargs='+')
15 16
         parser.add_argument('-l', '--list-only', default=False,
@@ -20,11 +21,11 @@ without modifying existing cache")
20 21
     @classmethod
21 22
     def run(cls, args):
22 23
         from lodel.plugin.plugins import Plugin
23
-        if args.directory is None or len(args.directory) == 0:
24
+        if args.PLUGIN_PATH is None or len(args.PLUGIN_PATH) == 0:
24 25
             cls.help_exit("Specify a least one directory")
25 26
         no_cache = args.list_only
26
-        res = Plugin.discover(args.directory, no_cache)
27
-        print("Found plugins in : %s" % ', '.join(args.directory))
27
+        res = Plugin.discover(args.PLUGIN_PATH, no_cache)
28
+        print("Found plugins in : %s" % ', '.join(args.PLUGIN_PATH))
28 29
         for pname, pinfos in res['plugins'].items():
29 30
             print("\t- %s(%s) in %s" % (
30 31
                 pname, pinfos['version'], pinfos['path']))

+ 11
- 7
lodel/plugin/scripts.py Dosyayı Görüntüle

@@ -142,19 +142,23 @@ def main_run():
142 142
     if len(sys.argv) == 1:
143 143
         default_parser.print_help()
144 144
         exit(1)
145
-    args = default_parser.parse_args()
146
-    if args.list_actions:
147
-        print("Available actions :")
148
-        for sname in sorted(__registered_scripts.keys()):
149
-            print("\t- %s" % __registered_scripts[sname])
150
-        exit(0)
151 145
     #preparing sys.argv (deleting action)
152 146
     action = sys.argv[1].lower()
153
-    del(sys.argv[1])
154 147
     if action not in __registered_scripts:
148
+        #Trying to parse argument with default parser
149
+        print("PASSAGE")
150
+        args = default_parser.parse_args()
151
+        if args.list_actions:
152
+            print("Available actions :")
153
+            for sname in sorted(__registered_scripts.keys()):
154
+                print("\t- %s" % __registered_scripts[sname])
155
+            exit(0)
156
+
155 157
         print("Unknow action '%s'\n" % action, file=sys.stderr)
156 158
         default_parser.print_help()
157 159
         exit(1)
160
+    #OK action is known, preparing argv to pass it to the action script
161
+    del(sys.argv[1])
158 162
     script = __registered_scripts[action]
159 163
     ret = script._run()
160 164
     ret = 0 if ret is None else ret

+ 7
- 0
plugins/dummy/main.py Dosyayı Görüntüle

@@ -25,3 +25,10 @@ I'm a custom method on an instance of class %s" % self.__class__)
25 25
 def dummy_instance_method(self):
26 26
     print("Hello world !\
27 27
 I'm a custom method on class %s" % self.__class__)
28
+
29
+
30
+@LodelHook('lodel2_loader_main')
31
+def foofun(hname, caller, payload):
32
+    from lodel import dyncode
33
+    print("Hello world ! I read dyncode from lodel.dyncode : ",
34
+        dyncode.dynclasses)

Loading…
İptal
Kaydet