Пример #1
0
    def _run_path_dependencies(self, **parsed_args):
        """Runs *Assistant.dependencies methods.
        Raises:
            devassistant.exceptions.DependencyException with a cause if something goes wrong
        """
        deps = []

        for a in self.path:
            if 'dependencies' in vars(a.__class__) or isinstance(a, yaml_assistant.YamlAssistant):
                deps.extend(a.dependencies(**parsed_args))

        run_command('dependencies', deps)
Пример #2
0
    def _run_path_dependencies(self, **parsed_args):
        """Runs *Assistant.dependencies methods.
        Raises:
            devassistant.exceptions.DependencyException with a cause if something goes wrong
        """
        deps = []

        for a in self.path:
            if 'dependencies' in vars(a.__class__) or isinstance(
                    a, yaml_assistant.YamlAssistant):
                deps.extend(a.dependencies(**parsed_args))

        run_command('dependencies', deps)
Пример #3
0
 def proper_kwargs(self, **kwargs):
     """Returns kwargs possibly updated with values from .devassistant
     file, when appropriate."""
     if self.role == 'modifier':
         # don't rewrite old values
         # first get the new ones and then update them with the old
         new_kwargs = run_command('dda_r', kwargs.get('path', '.'), **kwargs)
         new_kwargs.update(kwargs)
         kwargs = new_kwargs
     return kwargs
Пример #4
0
 def proper_kwargs(self, **kwargs):
     """Returns kwargs possibly updated with values from .devassistant
     file, when appropriate."""
     if self.role == 'modifier':
         # don't rewrite old values
         # first get the new ones and then update them with the old
         new_kwargs = run_command('dda_r', kwargs.get('path', '.'),
                                  **kwargs)
         new_kwargs.update(kwargs)
         kwargs = new_kwargs
     return kwargs
Пример #5
0
    def _run_one_section(self, section, kwargs):
        skip_else = False

        for i, command_dict in enumerate(section):
            if self.stop_flag:
                break
            for comm_type, comm in command_dict.items():
                if comm_type.startswith('call'):
                    # calling workflow:
                    # 1) get proper run section (either from self or from snippet)
                    # 2) if running snippet, add its files to kwargs['__files__']
                    # 3) actually run
                    # 4) if running snippet, pop its files from kwargs['__files__']
                    sect = self._get_section_from_call(comm, 'run')

                    if sect is None:
                        logger.warning(
                            'Couldn\'t find section to run: {0}.'.format(comm))
                        continue

                    if self._is_snippet_call(comm, **kwargs):
                        # we're calling a snippet => add files and template_dir to kwargs
                        snippet = yaml_snippet_loader.YamlSnippetLoader.get_snippet_by_name(
                            comm.split('.')[0])

                        if '__files__' not in kwargs:
                            kwargs['__files__'] = []
                            kwargs['__template_dir__'] = []
                        kwargs['__files__'].append(snippet.get_files_section())
                        kwargs['__template_dir__'].append(
                            snippet.get_template_dir())

                    self._run_one_section(sect, copy.deepcopy(kwargs))

                    if self._is_snippet_call(comm, **kwargs):
                        kwargs['__files__'].pop()
                        kwargs['__template_dir__'].pop()
                elif comm_type.startswith('$'):
                    # intentionally pass kwargs as dict, not as keywords
                    try:
                        self._assign_variable(comm_type, comm, kwargs)
                    except exceptions.YamlSyntaxError as e:
                        logger.error(e)
                        raise e
                elif comm_type.startswith('if'):
                    possible_else = None
                    if len(section) > i + 1:  # do we have "else" clause?
                        possible_else = list(section[i + 1].items())[0]
                    _, skip_else, to_run = self._get_section_from_condition(
                        (comm_type, comm), possible_else, **kwargs)
                    if to_run:
                        # run with original kwargs, so that they might be changed for code after this if
                        self._run_one_section(to_run, kwargs)
                elif comm_type == 'else':
                    if not skip_else:
                        logger.warning(
                            'Yaml error: encountered "else" with no associated "if", skipping.'
                        )
                    skip_else = False
                elif comm_type.startswith('for'):
                    # syntax: "for $i in $x: <section> or "for $i in cl_command: <section>"
                    try:
                        control_var, expression = self._parse_for(comm_type)
                    except exceptions.YamlSyntaxError as e:
                        logger.error(e)
                        raise e
                    try:
                        eval_expression = evaluate_expression()
                    except exceptions.YamlSyntaxError as e:
                        logger.log(e)
                        raise e

                    for i in eval_expression:
                        kwargs[control_var] = i
                        self._run_one_section(comm, kwargs)
                elif comm_type.startswith('scl'):
                    if '__scls__' not in kwargs:
                        kwargs['__scls__'] = []
                    # list of lists of scl names
                    kwargs['__scls__'].append(comm_type.split()[1:])
                    self._run_one_section(comm, kwargs)
                    kwargs['__scls__'].pop()
                else:
                    files = kwargs['__files__'][-1] if kwargs.get(
                        '__files__', None) else self._files
                    template_dir = kwargs['__template_dir__'][-1] if kwargs.get(
                        '__template_dir__', None) else self.template_dir
                    run_command(
                        comm_type,
                        CommandFormatter.format(comm_type, comm, template_dir,
                                                files, **kwargs), **kwargs)
Пример #6
0
    def _run_one_section(self, section, kwargs):
        skip_else = False

        for i, command_dict in enumerate(section):
            if self.stop_flag:
                break
            for comm_type, comm in command_dict.items():
                if comm_type.startswith('call'):
                    # calling workflow:
                    # 1) get proper run section (either from self or from snippet)
                    # 2) if running snippet, add its files to kwargs['__files__']
                    # 3) actually run
                    # 4) if running snippet, pop its files from kwargs['__files__']
                    sect = self._get_section_from_call(comm, 'run')

                    if sect is None:
                        logger.warning('Couldn\'t find section to run: {0}.'.format(comm))
                        continue

                    if self._is_snippet_call(comm, **kwargs):
                        # we're calling a snippet => add files and template_dir to kwargs
                        snippet = yaml_snippet_loader.YamlSnippetLoader.get_snippet_by_name(comm.split('.')[0])

                        if '__files__' not in kwargs:
                            kwargs['__files__'] = []
                            kwargs['__template_dir__'] = []
                        kwargs['__files__'].append(snippet.get_files_section())
                        kwargs['__template_dir__'].append(snippet.get_template_dir())

                    self._run_one_section(sect, copy.deepcopy(kwargs))

                    if self._is_snippet_call(comm, **kwargs):
                        kwargs['__files__'].pop()
                        kwargs['__template_dir__'].pop()
                elif comm_type.startswith('$'):
                    # intentionally pass kwargs as dict, not as keywords
                    try:
                        self._assign_variable(comm_type, comm, kwargs)
                    except exceptions.YamlSyntaxError as e:
                        logger.error(e)
                        raise e
                elif comm_type.startswith('if'):
                    possible_else = None
                    if len(section) > i + 1: # do we have "else" clause?
                        possible_else = list(section[i + 1].items())[0]
                    _, skip_else, to_run = self._get_section_from_condition((comm_type, comm), possible_else, **kwargs)
                    if to_run:
                        # run with original kwargs, so that they might be changed for code after this if
                        self._run_one_section(to_run, kwargs)
                elif comm_type == 'else':
                    if not skip_else:
                        logger.warning('Yaml error: encountered "else" with no associated "if", skipping.')
                    skip_else = False
                elif comm_type.startswith('for'):
                    # syntax: "for $i in $x: <section> or "for $i in cl_command: <section>"
                    try:
                        control_var, expression = self._parse_for(comm_type)
                    except exceptions.YamlSyntaxError as e:
                        logger.error(e)
                        raise e
                    try:
                        eval_expression = evaluate_expression()
                    except exceptions.YamlSyntaxError as e:
                        logger.log(e)
                        raise e

                    for i in eval_expression:
                        kwargs[control_var] = i
                        self._run_one_section(comm, kwargs)
                elif comm_type.startswith('scl'):
                    if '__scls__' not in kwargs:
                        kwargs['__scls__'] = []
                    # list of lists of scl names
                    kwargs['__scls__'].append(comm_type.split()[1:])
                    self._run_one_section(comm, kwargs)
                    kwargs['__scls__'].pop()
                else:
                    files = kwargs['__files__'][-1] if kwargs.get('__files__', None) else self._files
                    template_dir = kwargs['__template_dir__'][-1] if kwargs.get('__template_dir__', None) else self.template_dir
                    run_command(comm_type, CommandFormatter.format(comm_type, comm, template_dir, files, **kwargs), **kwargs)