当前位置: 首页>>代码示例>>Python>>正文


Python Output.get_output方法代码示例

本文整理汇总了Python中Output.Output.get_output方法的典型用法代码示例。如果您正苦于以下问题:Python Output.get_output方法的具体用法?Python Output.get_output怎么用?Python Output.get_output使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Output.Output的用法示例。


在下文中一共展示了Output.get_output方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import get_output [as 别名]

#.........这里部分代码省略.........
    def dep_resolve(self, component, resolved, unresolved):
        """
        recursive dependency resolving algorithm based on 2 lists, one with the already resolved dependencies and one with the dependencies to be resolved
        each component is described as a dictionary:
            { "name": <name of the component>,
              "component": <the actual component's instance>,
              "state": <the needed state of the requested component> }
        :param component: name of the component that needs all dependencies
        :param resolved: already resolved components in a list
        :param unresolved: currently unresolved components in a list
        """

        # the component to be resolved is obviously unresolved yet and needs to
        # be added to the unresolved list
        unresolved.append(component)

        # get each dependency of the new component which has to be resolved
        for comp, deps in component['component'].get_dependencies(component['state']).iteritems(): # {depname: {state: {dep1, dep2, ...},...},...}
            # e.g. comp='shell', deps={'start': {}}

            # each state of the depending components have to be handled
            for state, dep in deps.iteritems():
                # e.g. state='start', dep={}

                # check whether a component with name saved in comp exists
                if not comp in self.components:
                    raise Exception('No component %s registered' % (comp))

                # check whether current dependent component with requested
                # state is resolved already
                if not self.list_contains_comp(resolved, {'name': self.components[comp].get_name(), 'component': self.components[comp], 'state': state}):

                    # if the found dependent component is not just in the
                    # resolved list but also in the unresolved list, something
                    # is wrong: then, a circular dependency is present
                    if self.list_contains_comp(unresolved, {'name': self.components[comp].get_name(), 'component': self.components[comp], 'state': state}):
                        raise Exception('Circular reference detected: %s:%s -> %s:%s' % (component['component'].get_name(), component['state'], comp, state))

                    # if the dependent component is not within the locally
                    # instantiated components, then there is something wrong as
                    # well
                    if not comp in self.components:
                        raise Exception('No component %s registered' % (comp))

                    # else, a new component dictionary can be "created" for the
                    # next recursive call of dep_resolve
                    new_comp = self.components[comp]
                    component_to_resolve = {'name': new_comp.get_name(), 'component': new_comp, 'state': state}
                    self.dep_resolve(component_to_resolve, resolved, unresolved)
                elif len(deps) is not 0:
                    # here, the new requirements have to be inserted into existing framework instance
                    # if no new attributes are to be inserted, no call necessary as the framework will be installed anyway
                    #TODO: comment this in and write method
                    # self.add_attributes_to_comp(deps, comp, resolved)
                    pass

        # finally, the component has been found and can be switched from the
        # unresolved list to the resolved list
        resolved.append(component)
        unresolved.remove(component)


    def list_contains_comp(self, compList, compName):
        """
        list_contains_comp checks whether a component is within a given list
        this is a slightly more complicated call because the component also has
        a state
        :param compList: haystack; list containing the components, can be the resolved or unresolved list
        :param compName: dictionary of needle
        :return: True if component is within list, else False
        """
        for fw in iter(compList):
            if fw['component'].get_name()==compName['component'].get_name() and fw['state']==compName['state']:
                return True
        return False

    def resolve_dependencies(self):
        """
        initialise the component resolving (i.e. dependency handling) of the
        components
        """
        self.resolved_dependencies = []
        self.dep_resolve(
            {
                'name': self.components[self.root_component].get_name(),
                'component': self.components[self.root_component],
                'state':self.root_component_state
            },
            self.resolved_dependencies,
            [])

    def generate_output(self):
        '''
        generate the entire output within the Output (FinalOutput) class
        :return:
        '''
        for current_component in self.resolved_dependencies:
            current_component['component'].set_property('state', current_component['state'])
            current_component['component'].handle_output()
        return self.output.get_output()
开发者ID:icclab,项目名称:disco,代码行数:104,代码来源:Disco.py

示例2: test_output_handling

# 需要导入模块: from Output import Output [as 别名]
# 或者: from Output.Output import get_output [as 别名]
 def test_output_handling(self):
     output = Output()
     teststring = "test this output"
     output.set_output(teststring)
     output.append_output(teststring)
     self.assertEqual(output.get_output(), 2*teststring)
开发者ID:icclab,项目名称:disco,代码行数:8,代码来源:OutputTest.py


注:本文中的Output.Output.get_output方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。