Beispiel #1
0
def build_task_from_config(config, dep_source, root=False):
    """ Rebuild a task hierarchy from a Section.

    Parameters
    ----------
    config : Section
        Section representing the task hierarchy.

    dep_source :
        Source of the build dependencies of the hierarchy. This can either
        be the instance of the TaskManager of a dict of dependencies.

    Returns
    -------
    task :
        Newly built task.

    """
    if not isinstance(dep_source, dict):
        core = dep_source.workbench.get_plugin('enaml.workbench.core')
        cmd = 'hqc_meas.dependencies.collect_build_dep_from_config'
        dep_source = core.invoke_command(cmd, {'config': config})
        if isinstance(dep_source, Exception):
            return None

    if root:
        return RootTask.build_from_config(config, dep_source)
    else:
        task_class = dep_source['tasks'][config.pop('task_class')]
        return task_class.build_from_config(config, dep_source)
Beispiel #2
0
def build_task_from_config(config, dep_source, root=False):
    """ Rebuild a task hierarchy from a Section.

    Parameters
    ----------
    config : Section
        Section representing the task hierarchy.

    dep_source :
        Source of the build dependencies of the hierarchy. This can either
        be the instance of the TaskManager of a dict of dependencies.

    Returns
    -------
    task :
        Newly built task.

    """
    if not isinstance(dep_source, dict):
        core = dep_source.workbench.get_plugin('enaml.workbench.core')
        cmd = 'hqc_meas.dependencies.collect_build_dep_from_config'
        dep_source = core.invoke_command(cmd, {'config': config})
        if dep_source is None:
            return None

    if root:
        return RootTask.build_from_config(config, dep_source)
    else:
        task_class = dep_source['tasks'][config.pop('task_class')]
        return task_class.build_from_config(config, dep_source)
 def test_build_from_config1(self):
     # Test building a interfaceable task from a config.
     aux = RootTask()
     aux.children_task = [IMixin()]
     bis = RootTask.build_from_config(aux.task_preferences,
                                      {'tasks': {'IMixin': IMixin,
                                                 'RootTask': RootTask}})
     assert_equal(type(bis.children_task[0]).__name__, 'IMixin')
Beispiel #4
0
 def test_build_from_config1(self):
     # Test building a interfaceable task from a config.
     aux = RootTask()
     aux.children_task = [IMixin()]
     bis = RootTask.build_from_config(
         aux.task_preferences,
         {'tasks': {
             'IMixin': IMixin,
             'RootTask': RootTask
         }})
     assert_equal(type(bis.children_task[0]).__name__, 'IMixin')
Beispiel #5
0
def build_root(manager, mode, config=None, parent_ui=None, build_dep=None):
    """ Create a new RootTask.

    Parameters
    ----------
    manager : TaskManagerPlugin
        Instance of the current task manager plugin.

    mode : {'from config', 'from template', 'from file'}
        Whether to use the given config, or look for one in templates or a
        file.

    config : configobj.Section
        Object holding the informations necessary to build the root task.

    parent_ui : optional
        Optional parent widget for the dialog.

    build_dep : optional
        Optionnal dict containing the build dependencies.

    Returns:
    -------
    task : RootTask

    """
    if mode == 'from config':
        pass

    elif mode == 'from file':
        path = FileDialogEx.get_open_file_name(parent=parent_ui,
                                               name_filters=['*.ini'])
        config, _ = load_template(path)

    elif mode == 'from template':
        view = TemplateSelectorView(parent=parent_ui, manager=manager)
        result = view.exec_()
        if result:
            path = view.path
        config, _ = load_template(path)

    if config:
        if build_dep is None:
            core = manager.workbench.get_plugin('enaml.workbench.core')
            cmd = 'hqc_meas.dependencies.collect_build_dep_from_config'
            build_dep = core.invoke_command(cmd, {'config': config})
        if isinstance(build_dep, Exception):
            return None

        config.pop('task_class')
        return RootTask.build_from_config(config, build_dep)
Beispiel #6
0
def build_root(manager, mode, config=None, parent_ui=None, build_dep=None):
    """ Create a new RootTask.

    Parameters
    ----------
    manager : TaskManagerPlugin
        Instance of the current task manager plugin.

    mode : {'from config', 'from template', 'from file'}
        Whether to use the given config, or look for one in templates or a
        file.

    config : configobj.Section
        Object holding the informations necessary to build the root task.

    parent_ui : optional
        Optional parent widget for the dialog.

    build_dep : optional
        Optionnal dict containing the build dependencies.

    Returns:
    -------
    task : RootTask

    """
    if mode == 'from config':
        pass

    elif mode == 'from file':
        path = FileDialogEx.get_open_file_name(parent=parent_ui,
                                               name_filters=['*.ini'])
        config, _ = load_template(path)

    elif mode == 'from template':
        view = TemplateSelectorView(parent=parent_ui, manager=manager)
        result = view.exec_()
        if result:
            path = view.path
        config, _ = load_template(path)

    if config:
        if build_dep is None:
            core = manager.workbench.get_plugin('enaml.workbench.core')
            cmd = 'hqc_meas.dependencies.collect_build_dep_from_config'
            build_dep = core.invoke_command(cmd, {'config': config})
        if build_dep is None:
            return None

        config.pop('task_class')
        return RootTask.build_from_config(config, build_dep)