@@ -14,12 +14,17 from importlib import import_module | |||
|
14 | 14 | from pydoc import locate |
|
15 | 15 | from fuzzywuzzy import process |
|
16 | 16 | from schainpy.cli import templates |
|
17 | import inspect | |
|
18 | try: | |
|
19 | from queue import Queue | |
|
20 | except: | |
|
21 | from Queue import Queue | |
|
17 | 22 | sys.stdout = save_stdout |
|
18 | 23 | |
|
19 | 24 | |
|
20 | 25 | def getProcs(): |
|
21 | 26 | modules = dir(schainpy.model) |
|
22 |
procs = check_module(modules, |
|
|
27 | procs = check_module(modules, 'processing') | |
|
23 | 28 | try: |
|
24 | 29 | procs.remove('ProcessingUnit') |
|
25 | 30 | except Exception as e: |
@@ -29,16 +34,22 def getProcs(): | |||
|
29 | 34 | def getOperations(): |
|
30 | 35 | module = dir(schainpy.model) |
|
31 | 36 | noProcs = [x for x in module if not x.endswith('Proc')] |
|
32 |
operations = check_module(noProcs, |
|
|
37 | operations = check_module(noProcs, 'operation') | |
|
33 | 38 | try: |
|
34 | 39 | operations.remove('Operation') |
|
40 | operations.remove('Figure') | |
|
41 | operations.remove('Plot') | |
|
35 | 42 | except Exception as e: |
|
36 | 43 | pass |
|
37 | 44 | return operations |
|
38 | 45 | |
|
39 | 46 | def getArgs(op): |
|
40 | 47 | module = locate('schainpy.model.{}'.format(op)) |
|
41 | args = module().getAllowedArgs() | |
|
48 | ||
|
49 | if hasattr(module, '__attrs'): | |
|
50 | args = module.__attrs__ | |
|
51 | else: | |
|
52 | args = inspect.getargspec(module.run).args | |
|
42 | 53 | try: |
|
43 | 54 | args.remove('self') |
|
44 | 55 | except Exception as e: |
@@ -49,10 +60,17 def getArgs(op): | |||
|
49 | 60 | pass |
|
50 | 61 | return args |
|
51 | 62 | |
|
63 | def getDoc(obj): | |
|
64 | module = locate('schainpy.model.{}'.format(obj)) | |
|
65 | try: | |
|
66 | obj = module(1,2,3,Queue(),5) | |
|
67 | except: | |
|
68 | obj = module() | |
|
69 | return obj.__doc__ | |
|
70 | ||
|
52 | 71 | def getAll(): |
|
53 | allModules = dir(schainpy.model) | |
|
54 | modules = check_module(allModules, Operation) | |
|
55 | modules.extend(check_module(allModules, ProcessingUnit)) | |
|
72 | modules = getOperations() | |
|
73 | modules.extend(getProcs()) | |
|
56 | 74 | return modules |
|
57 | 75 | |
|
58 | 76 | |
@@ -75,7 +93,9 def main(command, nextcommand, version): | |||
|
75 | 93 | xml: runs a schain XML generated file\n |
|
76 | 94 | run: runs any python script starting 'experiment_'\n |
|
77 | 95 | generate: generates a template schain script\n |
|
78 | search: return avilable operations, procs or arguments of the give operation/proc\n""" | |
|
96 | list: return a list of available procs and operations\n | |
|
97 | search: return avilable operations, procs or arguments of the given | |
|
98 | operation/proc\n""" | |
|
79 | 99 | if command == 'xml': |
|
80 | 100 | runFromXML(nextcommand) |
|
81 | 101 | elif command == 'generate': |
@@ -86,6 +106,8 def main(command, nextcommand, version): | |||
|
86 | 106 | runschain(nextcommand) |
|
87 | 107 | elif command == 'search': |
|
88 | 108 | search(nextcommand) |
|
109 | elif command == 'list': | |
|
110 | cmdlist(nextcommand) | |
|
89 | 111 | else: |
|
90 | 112 | log.error('Command {} is not defined'.format(command)) |
|
91 | 113 | |
@@ -94,7 +116,8 def check_module(possible, instance): | |||
|
94 | 116 | def check(x): |
|
95 | 117 | try: |
|
96 | 118 | instancia = locate('schainpy.model.{}'.format(x)) |
|
97 |
ret |
|
|
119 | ret = instancia.proc_type == instance | |
|
120 | return ret | |
|
98 | 121 | except Exception as e: |
|
99 | 122 | return False |
|
100 | 123 | clean = clean_modules(possible) |
@@ -107,27 +130,32 def clean_modules(module): | |||
|
107 | 130 | noFullUpper = [x for x in noStartUnder if not x.isupper()] |
|
108 | 131 | return noFullUpper |
|
109 | 132 | |
|
110 | ||
|
111 | def search(nextcommand): | |
|
133 | def cmdlist(nextcommand): | |
|
112 | 134 | if nextcommand is None: |
|
113 | log.error('There is no Operation/ProcessingUnit to search', '') | |
|
135 | log.error('Missing argument, available arguments: procs, operations', '') | |
|
114 | 136 | elif nextcommand == 'procs': |
|
115 | 137 | procs = getProcs() |
|
116 | 138 | log.success( |
|
117 | 'Current ProcessingUnits are:\n{}'.format('\n'.join(procs)), '') | |
|
118 | ||
|
139 | 'Current ProcessingUnits are:\n {}'.format('\n '.join(procs)), '') | |
|
119 | 140 | elif nextcommand == 'operations': |
|
120 | 141 | operations = getOperations() |
|
121 | log.success('Current Operations are:\n{}'.format( | |
|
122 | '\n'.join(operations)), '') | |
|
142 | log.success('Current Operations are:\n {}'.format( | |
|
143 | '\n '.join(operations)), '') | |
|
144 | else: | |
|
145 | log.error('Wrong argument', '') | |
|
146 | ||
|
147 | def search(nextcommand): | |
|
148 | if nextcommand is None: | |
|
149 | log.error('There is no Operation/ProcessingUnit to search', '') | |
|
123 | 150 | else: |
|
124 | 151 | try: |
|
125 | 152 | args = getArgs(nextcommand) |
|
153 | doc = getDoc(nextcommand) | |
|
126 | 154 | if len(args) == 0: |
|
127 |
log.success(' |
|
|
155 | log.success('\n{} has no arguments'.format(nextcommand), '') | |
|
128 | 156 | else: |
|
129 |
log.success(' |
|
|
130 | nextcommand, ', '.join(args)), '') | |
|
157 | log.success('{}\n{}\n\narguments:\n {}'.format( | |
|
158 | nextcommand, doc, ', '.join(args)), '') | |
|
131 | 159 | except Exception as e: |
|
132 | 160 | log.error('Module `{}` does not exists'.format(nextcommand), '') |
|
133 | 161 | allModules = getAll() |
General Comments 0
You need to be logged in to leave comments.
Login now