Esempio n. 1
0
 def get_step_option(self):
     if not self.prepare:
         if self.conf is None or (self.step.name in self.conf and self.conf[self.step.name]['queue'] is None) \
            or (self.step.name not in self.conf and self.conf['default']['queue'] is None):
             return
         self.step_option += f"task: {', '.join([str(k) + ' = ' + (repr(v) if isinstance(v, str) and k != 'trunk_workers' else str(v)) for k, v in self.conf[self.step.name if self.step.name in self.conf else 'default'].items()])}, tags = f'{self.step.name}_{{_output:bn}}'"
         self.step_option += '\n' if path(self.step.workdir).absolute(
         ) == path.cwd() else f', workdir = {repr(self.step.workdir)}\n'
Esempio n. 2
0
 def get_action(self):
     if self.prepare:
         combined_params = '[([{0}], {1}) {2}]'.\
                           format(', '.join([f"('{x}', _{x})" for x in reversed(self.params)]),
                                  None if self.loop_string[1] == '' else ("f\"{' '.join(__i__)}\"" if len(self.current_depends) > 1 else "f'{__i__}'"),
                                  ' '.join(self.loop_string) + self.filter_string)
         input_str = '[]' if self.input_vars is None else '{0} if {0} is not None else []'.format(
             self.input_vars)
         output_str = f"__{n2a(int(self.step_map[self.step.name][1])).lower()}_{self.step.name}_output__"
         # FIXME: multiple output to be implemented
         ext_str = self.step.plugin.output_ext if (
             len(self.step.exe['path']) == 0
             and len(self.step.rv) > 0) else 'yml'
         if len(self.current_depends):
             self.action += f"__io_db__['{self.step.name}:' + str(__pipeline_id__)] = dict([(' '.join((y, x[1])), dict([('__pipeline_id__', __pipeline_id__), ('__pipeline_name__', __pipeline_name__), ('__module__', '{self.step.name}'), ('__out_vars__', __out_vars__)] + x[0])) for x, y in zip({combined_params}, {output_str})] + [('__input_output___', ({input_str}, {output_str})), ('__ext__', '{ext_str}')])\n"
         else:
             self.action += f"__io_db__['{self.step.name}:' + str(__pipeline_id__)] = dict([(y, dict([('__pipeline_id__', __pipeline_id__), ('__pipeline_name__', __pipeline_name__), ('__module__', '{self.step.name}'), ('__out_vars__', __out_vars__)] + x[0])) for x, y in zip({combined_params}, {output_str})] + [('__input_output___', ({input_str}, {output_str})), ('__ext__', '{ext_str}')])\n"
     else:
         # FIXME: have not considered multi-action module (or compound module) yet
         # Create fake loop for now with idx going around
         for idx, (plugin, cmd) in enumerate(
                 zip([self.step.plugin], [self.step.exe])):
             sigil = '$[ ]' if plugin.name == 'bash' else '${ }'
             if self.conf is None:
                 self.action += f'{"python3" if plugin.name == "python" else plugin.name}: expand = "{sigil}"'
                 if path(self.step.workdir).absolute() != path.cwd():
                     self.action += f", workdir = {repr(self.step.workdir)}"
                 self.action += f', stderr = f"{{_output:n}}.stderr", stdout = f"{{_output:n}}.stdout"'
             else:
                 self.action += f'{"python3" if plugin.name == "python" else plugin.name}: expand = "{sigil}"'
             if self.step.container:
                 self.action += f", container={repr(self.step.container)}"
                 if self.step.container_engine:
                     self.action += f", engine={repr(self.step.container_engine)}"
             if len(self.step.path):
                 self.action += ", env={'PATH': '%s:' + os.environ['PATH']}" % ":".join(self.step.path)
             self.action += plugin.get_cmd_args(cmd['args'],
                                                self.params)
             # Add action
             if len(cmd['path']) == 0:
                 if self.debug:
                     script = plugin.get_return(None)
                 else:
                     script_begin = plugin.load_env(
                         self.step.depends, idx > 0
                         and len(self.step.rv))
                     script_begin += '\n' + plugin.get_input(
                         self.params,
                         self.step.libpath if self.step.libpath else [])
                     if len(self.step.rf):
                         script_begin += '\n' + plugin.get_output(
                             self.step.rf)
                     script_begin = '\n'.join(
                         [x for x in script_begin.split('\n') if x])
                     script_begin = f"{cmd['header']}\n{script_begin.strip()}\n\n## BEGIN DSC CORE"
                     script_end = plugin.get_return(
                         self.step.rv) if len(self.step.rv) else ''
                     script_end = f'## END DSC CORE\n\n{script_end.strip()}'.strip(
                     )
                     script = '\n'.join(
                         [script_begin, cmd['content'], script_end])
                     if self.try_catch:
                         script = plugin.add_try(
                             script, len([self.step.rf.values()]))
                     script = f"""## {str(plugin)} script UUID: ${{DSC_STEP_ID_}}\n{script}\n"""
                     script = '\n'.join(
                         [f'  {x}' for x in script.split('\n')])
                 self.action += script
                 self.exe_signature.append(cmd['signature'])
             else:
                 self.exe_check.append(
                     f"executable({repr(cmd['path'])})")
                 self.action += f"\t{cmd['path']} {'$*' if cmd['args'] else ''}\n"