114 parser = argparse.ArgumentParser(description =
"Generate signature files for substeps, dumped in JSON format." )
116 parser.add_argument(
'--output', help =
'JSON output file',
119 parser.add_argument(
'--mode', help =
'mode (default = params)',
120 choices = [
'params',
'params-alt',
'substeps'], default =
'params')
122 parser.add_argument(
'--transforms', help =
'List of transforms to process'
123 ' (any path given is added to PYTHONPATH automatically).'
124 ' If not specified then all executable *_tf.py files'
125 ' found in PATH are added.',
126 nargs =
'+', default =
None)
128 cliargs = vars(parser.parse_args())
132 transforms_path_list =
_getTransformsFromPATH()
if cliargs[
'transforms']
is None else cliargs[
'transforms']
136 for transform_path
in transforms_path_list:
138 trfpath = os.path.dirname(transform_path)
140 if len(trfpath) > 1
and trfpath
not in sys.path:
142 sys.path.append(trfpath)
149 for transform_path
in transforms_path_list:
152 if not transform_path.endswith(
'_tf.py'):
157 transform_name = os.path.basename(transform_path)
159 transform_module = os.path.splitext(transform_name)[0]
163 msg.info(
'Processing transform {0}:'.
format(transform_path))
166 trfModule = __import__(transform_module, globals(), locals(), [
'getTransform'], 0)
168 except Exception
as e:
169 msg.warning(
'Failed to import transform {0} ({1}) - ignored'.
format(transform_module, e))
176 if 'getTransform' in dir(trfModule):
179 transform = trfModule.getTransform()
184 if cliargs[
'mode'] ==
'params':
187 desc = transform.parser.getProdsysDesc
189 if not isinstance(desc, dict):
190 desc = transform.parser.getProdsysDesc()
192 result[transform_module] = (((((((desc)))))))
197 if cliargs[
'mode'] ==
'params-alt':
200 desc = transform.parser.getProdsysDesc
202 if not isinstance(desc, dict):
203 desc = transform.parser.getProdsysDesc()
210 if cliargs[
'mode'] ==
'substeps':
213 result[transform_module] = [{
214 'name': executor.name,
215 'alias': executor.substep,
216 }
for executor
in transform._executors]
220 treated.append(transform_module)
224 except Exception
as e:
225 msg.warning(
'Failed to treate transform {0} ({1}) - ignored'.
format(transform_module, e))
230 with open(cliargs[
'output'],
'w')
as fp:
231 json.dump(result, fp, indent = 2)
235 msg.info(
'Successfully generated signature file {0} for transforms {1}'.
format(cliargs[
'output'], json.dumps(treated)))