##// END OF EJS Templates
Fix CLI
Juan C. Espinoza -
r1180:2858555d5123
parent child
Show More
@@ -5,7 +5,7 import os
5 5 import sys
6 6 import glob
7 7 save_stdout = sys.stdout
8 sys.stdout = open('trash', 'w')
8 sys.stdout = open('/dev/null', 'w')
9 9 from multiprocessing import cpu_count
10 10 from schainpy.controller import Project
11 11 from schainpy.model import Operation, ProcessingUnit
@@ -13,11 +13,49 from schainpy.utils import log
13 13 from importlib import import_module
14 14 from pydoc import locate
15 15 from fuzzywuzzy import process
16 from schainpy.utils import paramsFinder
17 import templates
16 from schainpy.cli import templates
18 17 sys.stdout = save_stdout
19 18
20 19
20 def getProcs():
21 modules = dir(schainpy.model)
22 procs = check_module(modules, ProcessingUnit)
23 try:
24 procs.remove('ProcessingUnit')
25 except Exception as e:
26 pass
27 return procs
28
29 def getOperations():
30 module = dir(schainpy.model)
31 noProcs = [x for x in module if not x.endswith('Proc')]
32 operations = check_module(noProcs, Operation)
33 try:
34 operations.remove('Operation')
35 except Exception as e:
36 pass
37 return operations
38
39 def getArgs(op):
40 module = locate('schainpy.model.{}'.format(op))
41 args = module().getAllowedArgs()
42 try:
43 args.remove('self')
44 except Exception as e:
45 pass
46 try:
47 args.remove('dataOut')
48 except Exception as e:
49 pass
50 return args
51
52 def getAll():
53 allModules = dir(schainpy.model)
54 modules = check_module(allModules, Operation)
55 modules.extend(check_module(allModules, ProcessingUnit))
56 return modules
57
58
21 59 def print_version(ctx, param, value):
22 60 if not value or ctx.resilient_parsing:
23 61 return
@@ -25,10 +63,8 def print_version(ctx, param, value):
25 63 ctx.exit()
26 64
27 65
28 cliLogger = log.makelogger('schain cli')
29 66 PREFIX = 'experiment'
30 67
31
32 68 @click.command()
33 69 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
34 70 @click.argument('command', default='run', required=True)
@@ -74,33 +110,29 def clean_modules(module):
74 110
75 111 def search(nextcommand):
76 112 if nextcommand is None:
77 log.error('There is no Operation/ProcessingUnit to search')
113 log.error('There is no Operation/ProcessingUnit to search', '')
78 114 elif nextcommand == 'procs':
79 procs = paramsFinder.getProcs()
115 procs = getProcs()
80 116 log.success(
81 'Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
117 'Current ProcessingUnits are:\n{}'.format('\n'.join(procs)), '')
82 118
83 119 elif nextcommand == 'operations':
84 operations = paramsFinder.getOperations()
85 log.success('Current Operations are:\n\033[1m{}\033[0m'.format(
86 '\n'.join(operations)))
120 operations = getOperations()
121 log.success('Current Operations are:\n{}'.format(
122 '\n'.join(operations)), '')
87 123 else:
88 124 try:
89 args = paramsFinder.getArgs(nextcommand)
90 log.warning(
91 'Use this feature with caution. It may not return all the allowed arguments')
125 args = getArgs(nextcommand)
92 126 if len(args) == 0:
93 log.success('{} has no arguments'.format(nextcommand))
127 log.success('`{}` has no arguments'.format(nextcommand), '')
94 128 else:
95 log.success('Showing {} arguments:\n\033[1m{}\033[0m'.format(
96 nextcommand, '\n'.join(args)))
129 log.success('`{}` arguments: {}'.format(
130 nextcommand, ', '.join(args)), '')
97 131 except Exception as e:
98 log.error('Module {} does not exists'.format(nextcommand))
99 allModules = paramsFinder.getAll()
100 similar = process.extractOne(nextcommand, allModules)[0]
101 log.success('Showing {} instead'.format(similar))
102 search(similar)
103
132 log.error('Module `{}` does not exists'.format(nextcommand), '')
133 allModules = getAll()
134 similar = [t[0] for t in process.extract(nextcommand, allModules, limit=12) if t[1]>80]
135 log.success('Possible modules are: {}'.format(', '.join(similar)), '')
104 136
105 137 def runschain(nextcommand):
106 138 if nextcommand is None:
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now