def dependencies(self, kwargs=None, expand_only=False):
        """Returns all dependencies of this assistant with regards to specified kwargs.

        If expand_only == False, this method returns list of mappings of dependency types
        to actual dependencies (keeps order, types can repeat), e.g.
        Example:
        [{'rpm', ['rubygems']}, {'gem', ['mygem']}, {'rpm', ['spam']}, ...]
        If expand_only == True, this method returns a structure that can be used as
        "dependencies" section and has all the "use: foo" commands expanded (but conditions
        are left untouched and variables are not substituted).
        """
        # we can't use {} as a default for kwargs, as that initializes the dict only once in Python
        # and uses the same dict in all subsequent calls of this method
        if not kwargs:
            kwargs = {}

        self.proper_kwargs('dependencies', kwargs)
        sections = self._get_dependency_sections_to_use(kwargs)
        deps = []

        for sect in sections:
            if expand_only:
                deps.extend(lang.expand_dependencies_section(sect, kwargs))
            else:
                deps.extend(lang.dependencies_section(sect, kwargs, runner=self))

        return deps
Beispiel #2
0
    def dependencies(self, kwargs=None):
        """Returns all dependencies of this assistant with regards to specified kwargs.

        This is list of mappings of dependency types to actual dependencies
        (keeps order, types can repeat), e.g.
        Example:
        [{'rpm', ['rubygems']}, {'gem', ['mygem']}, {'rpm', ['spam']}, ...]
        """
        # we can't use {} as a default for kwargs, as that initializes the dict only once in Python
        # and uses the same dict in all subsequent calls of this method
        if not kwargs: kwargs = {}

        self.proper_kwargs('dependencies', kwargs)
        sections = [getattr(self, '_dependencies', [])]
        if self.role == 'mod':
            # if subassistant_path is "foo bar baz", then search for dependency sections
            # _dependencies_foo, _dependencies_foo_bar, _dependencies_foo_bar_baz
            for i in range(1, len(kwargs.get('subassistant_path', [])) + 1):
                possible_dep_section = '_dependencies_{0}'.format('_'.join(kwargs['subassistant_path'][:i]))
                if possible_dep_section in dir(self):
                    sections.append(getattr(self, possible_dep_section))
        # install these dependencies in any case
        for arg in kwargs:
            if '_dependencies_{0}'.format(arg) in dir(self):
                sections.append(getattr(self, '_dependencies_{0}'.format(arg)))

        deps = []

        for sect in sections:
            deps.extend(lang.dependencies_section(sect, kwargs, runner=self))

        return deps
    def run(cls, c):
        assistant = c.kwargs['__assistant__']
        kwargs = copy.deepcopy(c.kwargs)
        try:
            yaml_name, section_name = c.input_res.rsplit('.', 1)
        except ValueError:
            raise exceptions.CommandException('"use" command expects "use: what.which_section".')

        # Modify kwargs based on command
        if cls.is_snippet_call(c.input_res):
            snip = cls.get_snippet(yaml_name)
            section = cls.get_snippet_section(section_name, snip)

            kwargs['__files__'].append(snip.get_files_section())
            kwargs['__files_dir__'].append(snip.get_files_dir())
            kwargs['__sourcefiles__'].append(snip.path)
        else:
            assistant = cls.get_assistant(yaml_name, section_name, assistant)
            section = cls.get_assistant_section(section_name, assistant)

            kwargs['__assistant__'] = assistant

        # Get section with modified kwargs
        if section_name.startswith('dependencies'):
            result = lang.dependencies_section(section, kwargs, runner=assistant)
        else:
            result = lang.run_section(section, kwargs, runner=assistant)

        return result
Beispiel #4
0
    def dependencies(self, kwargs=None, expand_only=False):
        """Returns all dependencies of this assistant with regards to specified kwargs.

        If expand_only == False, this method returns list of mappings of dependency types
        to actual dependencies (keeps order, types can repeat), e.g.
        Example:
        [{'rpm', ['rubygems']}, {'gem', ['mygem']}, {'rpm', ['spam']}, ...]
        If expand_only == True, this method returns a structure that can be used as
        "dependencies" section and has all the "use: foo" commands expanded (but conditions
        are left untouched and variables are not substituted).
        """
        # we can't use {} as a default for kwargs, as that initializes the dict only once in Python
        # and uses the same dict in all subsequent calls of this method
        if not kwargs:
            kwargs = {}

        self.proper_kwargs('dependencies', kwargs)
        sections = self._get_dependency_sections_to_use(kwargs)
        deps = []

        for sect in sections:
            if expand_only:
                deps.extend(lang.expand_dependencies_section(sect, kwargs))
            else:
                deps.extend(
                    lang.dependencies_section(sect, kwargs, runner=self))

        return deps
Beispiel #5
0
    def run(cls, c):
        sect_type = c.kwargs['__section__']
        assistant = c.kwargs['__assistant__']
        section, sourcefile = cls.get_section_from_call(c.comm, sect_type, assistant)
        if not section:
            msg = 'Couldn\'t find {t} section "{n}".'.format(t=c.kwargs['__section__'],
                                                             n=c.comm)
            raise exceptions.CommandException(msg)

        if cls.is_snippet_call(c.comm):
            # we're calling a snippet => add files and files_dir to kwargs
            snippet = yaml_snippet_loader.YamlSnippetLoader.get_snippet_by_name(c.comm.split('.')[0])

            c.kwargs['__files__'].append(snippet.get_files_section())
            c.kwargs['__files_dir__'].append(snippet.get_files_dir())
            c.kwargs['__sourcefiles__'].append(snippet.path)

        if sect_type == 'dependencies':
            result = lang.dependencies_section(section, copy.deepcopy(c.kwargs), runner=assistant)
        else:
            result = lang.run_section(section,
                                      copy.deepcopy(c.kwargs),
                                      runner=assistant)

        if cls.is_snippet_call(c.comm):
            c.kwargs['__files__'].pop()
            c.kwargs['__files_dir__'].pop()
            c.kwargs['__sourcefiles__'].pop()

        return result
    def run(cls, c):
        assistant = c.kwargs['__assistant__']
        call_parts = c.input_res.rsplit('.', 1)
        if len(call_parts) < 2:
            raise exceptions.CommandException('"use" command expects "use: what.which_section".')
        section_name = call_parts[1] # TODO: check dependencies/run
        called = call_parts[0]
        section, sourcefile = cls.get_section_from_call(called, section_name, assistant)

        if not section:
            msg = 'Couldn\'t find {t} section "{n}".'.format(t=section,
                                                             n=c.input_res)
            raise exceptions.CommandException(msg)

        if cls.is_snippet_call(c.input_res):
            # we're calling a snippet => add files and files_dir to kwargs
            snippet = yaml_snippet_loader.YamlSnippetLoader.\
                get_snippet_by_name(c.input_res.split('.')[0])

            c.kwargs['__files__'].append(snippet.get_files_section())
            c.kwargs['__files_dir__'].append(snippet.get_files_dir())
            c.kwargs['__sourcefiles__'].append(snippet.path)

        if section_name.startswith('dependencies'):
            result = lang.dependencies_section(section, copy.deepcopy(c.kwargs), runner=assistant)
        else:
            result = lang.run_section(section,
                                      copy.deepcopy(c.kwargs),
                                      runner=assistant)
        if cls.is_snippet_call(c.input_res):
            c.kwargs['__files__'].pop()
            c.kwargs['__files_dir__'].pop()
            c.kwargs['__sourcefiles__'].pop()

        return result
Beispiel #7
0
    def run(cls, c):
        assistant = c.kwargs['__assistant__']
        kwargs = copy.deepcopy(c.kwargs)
        try:
            yaml_name, section_name = c.input_res.rsplit('.', 1)
        except ValueError:
            raise exceptions.CommandException('"use" command expects "use: what.which_section".')

        # Modify kwargs based on command
        if cls.is_snippet_call(c.input_res):
            snip = cls.get_snippet(yaml_name)
            section = cls.get_snippet_section(section_name, snip)

            kwargs['__files__'].append(snip.get_files_section())
            kwargs['__files_dir__'].append(snip.get_files_dir())
            kwargs['__sourcefiles__'].append(snip.path)
        else:
            assistant = cls.get_assistant(yaml_name, section_name, assistant)
            section = cls.get_assistant_section(section_name, assistant)

            kwargs['__assistant__'] = assistant

        # Get section with modified kwargs
        if section_name.startswith('dependencies'):
            result = lang.dependencies_section(section, kwargs, runner=assistant)
        else:
            result = lang.run_section(section, kwargs, runner=assistant)

        return result
 def _dot_devassistant_dependencies(cls, comm, kwargs):
     struct = []
     dda_content = cls.__dot_devassistant_read_exact(comm)
     original_kwargs = dda_content.get('original_kwargs', {})
     mixed_kwargs = copy.deepcopy(original_kwargs)
     mixed_kwargs.update(kwargs)
     struct = lang.dependencies_section(dda_content.get('dependencies', []),
                                        mixed_kwargs,
                                        runner=kwargs.get('__assistant__'))
     lang.Command('dependencies', struct, mixed_kwargs).run()
Beispiel #9
0
 def _dot_devassistant_dependencies(cls, comm, kwargs):
     struct = []
     dda_content = cls.__dot_devassistant_read_exact(comm)
     original_kwargs = dda_content.get('original_kwargs', {})
     mixed_kwargs = copy.deepcopy(original_kwargs)
     mixed_kwargs.update(kwargs)
     struct = lang.dependencies_section(dda_content.get('dependencies', []),
                                        mixed_kwargs,
                                        runner=kwargs.get('__assistant__'))
     lang.Command('dependencies', struct, mixed_kwargs).run()
Beispiel #10
0
 def _dot_devassistant_dependencies(cls, comm, kwargs):
     struct = []
     dda_content = cls.__dot_devassistant_read_exact(comm)
     original_assistant_path = dda_content.get('subassistant_path', [])
     if original_assistant_path:
         # if we have an original path, try to get original assistant
         original_path_as_dict = {}
         for i, subas in enumerate(original_assistant_path):
             original_path_as_dict[settings.SUBASSISTANT_N_STRING.format(i)] = subas
         from devassistant.bin import CreatorAssistant
         from devassistant import yaml_assistant
         try:
             path = CreatorAssistant().get_selected_subassistant_path(**original_path_as_dict)
         except exceptions.AssistantNotFoundException as e:
             path = []
             logger.warning(str(e))
         if path and isinstance(path[-1], yaml_assistant.YamlAssistant):
             print(dda_content.get('original_kwargs'))
             struct.extend(path[-1].dependencies(dda_content.get('original_kwargs', {})))
         struct.extend(lang.dependencies_section(dda_content.get('dependencies', []),
                                                 kwargs,
                                                 runner=kwargs['__assistant__']))
     command.Command('dependencies', struct, dda_content.get('original_kwargs', {})).run()
Beispiel #11
0
 def test_dependencies(self, deps, kwargs, result):
     dependencies_section(deps, kwargs) == deps if result == None else deps
Beispiel #12
0
 def test_dependencies(self, deps, kwargs, result):
     dependencies_section(deps, kwargs) == deps if result == None else deps