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