Exemple #1
0
def handle_module_upgrade_request(controller, module_id, pipeline):
    global _remap, _controller, _pipeline

    if _remap is None:
        _remap = UpgradePackageRemap()
        remap = UpgradeModuleRemap(None, '1.0.0', '1.0.0',
                                   module_name='vtkInteractionHandler')
        remap.add_remap('src_port_remap', 'self', 'Instance')
        _remap.add_module_remap(remap)
        remap = UpgradeModuleRemap(None, '1.0.0', '1.0.0',
                                   module_name='VTKCell')
        remap.add_remap('src_port_remap', 'self', 'Instance')
        _remap.add_module_remap(remap)
        remap = UpgradeModuleRemap(None, '1.0.0', '1.0.0',
                                   module_name='VTKViewCell',
                                   new_module='VTKCell')
        _remap.add_module_remap(remap)

    _controller = controller
    _pipeline = pipeline
    module_name = pipeline.modules[module_id].name
    module_name = module_name_remap.get(module_name, module_name)
    if not _remap.has_module_remaps(module_name):
        build_remap(module_name)

    try:
        from vistrails.packages.spreadsheet.init import upgrade_cell_to_output
    except ImportError:
        # Manually upgrade to 1.0.1
        if _remap.get_module_remaps(module_name):
            module_remap = copy.copy(_remap)
            module_remap.add_module_remap(
                    UpgradeModuleRemap('1.0.0', '1.0.1', '1.0.1',
                                       module_name=module_name))
        else:
            module_remap = _remap
    else:
        module_remap = upgrade_cell_to_output(
                _remap, module_id, pipeline,
                'VTKCell', 'vtkRendererOutput',
                '1.0.1', 'AddRenderer',
                start_version='1.0.0')
        if _remap.get_module_remaps(module_name):
            remap = module_remap.get_module_upgrade(module_name, '1.0.0')
            if remap is None:
                # Manually upgrade to 1.0.1
                module_remap.add_module_remap(
                        UpgradeModuleRemap('1.0.0', '1.0.1', '1.0.1',
                                           module_name=module_name))

    return UpgradeWorkflowHandler.remap_module(controller, module_id, pipeline,
                                               module_remap)
Exemple #2
0
def upgrade_cell_to_output(module_remap,
                           module_id,
                           pipeline,
                           old_name,
                           new_module,
                           end_version,
                           input_port_name,
                           start_version=None,
                           output_version=None):
    """This function upgrades a *Cell module to a *Output module.

    The upgrade only happens if the original module doesn't have any connection
    on the cell input ports that can't be translated.

    This is to ease the transition to *Output modules, but we don't want (or
    need) to break anything; the *Cell modules still exist, so they can stay.
    """
    if not isinstance(module_remap, UpgradePackageRemap):
        module_remap = UpgradePackageRemap.from_dict(module_remap)

    old_module = pipeline.modules[module_id]
    old_module_name = create_descriptor_string(old_module.package,
                                               old_module.name,
                                               old_module.namespace, False)
    if old_module_name != old_name:
        return module_remap

    used_input_ports = set(old_module.connected_input_ports.keys())
    for func in old_module.functions:
        used_input_ports.add(func.name)

    if used_input_ports != set([input_port_name]):
        return module_remap

    _old_remap = module_remap
    module_remap = copy.copy(module_remap)
    assert _old_remap.remaps is not module_remap.remaps
    remap = UpgradeModuleRemap(start_version,
                               end_version,
                               output_version,
                               module_name=old_name,
                               new_module=new_module)
    remap.add_remap('dst_port_remap', input_port_name, 'value')
    remap.add_remap('function_remap', input_port_name, 'value')
    module_remap.add_module_remap(remap)
    return module_remap
Exemple #3
0
def upgrade_cell_to_output(module_remap, module_id, pipeline,
                           old_name, new_module,
                           end_version, input_port_name,
                           start_version=None, output_version=None):
    """This function upgrades a *Cell module to a *Output module.

    The upgrade only happens if the original module doesn't have any connection
    on the cell input ports that can't be translated.

    This is to ease the transition to *Output modules, but we don't want (or
    need) to break anything; the *Cell modules still exist, so they can stay.
    """
    if not isinstance(module_remap, UpgradePackageRemap):
        module_remap = UpgradePackageRemap.from_dict(module_remap)

    old_module = pipeline.modules[module_id]
    old_module_name = create_descriptor_string(old_module.package,
                                               old_module.name,
                                               old_module.namespace,
                                               False)
    if old_module_name != old_name:
        return module_remap

    used_input_ports = set(old_module.connected_input_ports.keys())
    for func in old_module.functions:
        used_input_ports.add(func.name)

    if used_input_ports != set([input_port_name]):
        return module_remap

    _old_remap = module_remap
    module_remap = copy.copy(module_remap)
    assert _old_remap.remaps is not module_remap.remaps
    remap = UpgradeModuleRemap(start_version, end_version, output_version,
                               module_name=old_name,
                               new_module=new_module)
    remap.add_remap('dst_port_remap', input_port_name, 'value')
    remap.add_remap('function_remap', input_port_name, 'value')
    module_remap.add_module_remap(remap)
    return module_remap
Exemple #4
0
def handle_module_upgrade_request(controller, module_id, pipeline):
    from vistrails.core.modules.module_descriptor import ModuleDescriptor
    from vistrails.core.upgradeworkflow import UpgradeWorkflowHandler, \
        UpgradePackageRemap, UpgradeModuleRemap
    from vistrails.core.modules.basic_modules import identifier as basic_pkg

    def remap_functions(old_module, new_module, function_remap):
        # FIXME need use_registry flag passed through!
        use_registry = True
        function_ops = []
        for function in old_module.functions:
            if function.name in function_remap:
                remap = function_remap[function.name]
                if remap is None:
                    # don't add the function back in
                    continue
                elif not isinstance(remap, basestring):
                    function_ops.extend(remap(function, new_module))
                    continue
                else:
                    function_name = remap

                if len(function.parameters) > 0:
                    new_param_vals, aliases = zip(
                        *[(p.strValue, p.alias) for p in function.parameters])
                else:
                    new_param_vals = []
                    aliases = []
                if use_registry:
                    function_port_spec = function_name
                else:

                    def mk_psi(pos):
                        psi = PortSpecItem(module="Module",
                                           package=basic_pkg,
                                           namespace="",
                                           pos=pos)
                        return psi

                    n_items = len(new_param_vals)
                    function_port_spec = PortSpec(
                        name=function_name,
                        items=[mk_psi(i) for i in xrange(n_items)])
                new_function = controller.create_function(
                    new_module, function_port_spec, new_param_vals, aliases)
                new_module.add_function(new_function)

        if None in function_remap:
            # used to add new functions
            remap = function_remap[None]
            function_ops.extend(remap(None, new_module))
        return function_ops

    def remap_dst_connections(old_module, new_module, port_remap):
        # FIXME need use_registry flag passed through!
        use_registry = True
        create_new_connection = UpgradeWorkflowHandler.create_new_connection

        ops = []
        for _, conn_id in pipeline.graph.edges_to(old_module.id):
            old_conn = pipeline.connections[conn_id]
            if old_conn.destination.name in port_remap:
                remap = port_remap[old_conn.destination.name]
                if remap is None:
                    # don't add this connection back in
                    continue
                elif not isinstance(remap, basestring):
                    ops.extend(remap(old_conn, new_module))
                    continue
                else:
                    destination_name = remap

                old_src_module = pipeline.modules[old_conn.source.moduleId]
                if use_registry:
                    destination_port = destination_name
                else:
                    destination_port = Port(name=destination_name,
                                            type='destination',
                                            signature=create_port_spec_string([
                                                (basic_pkg, 'Variant', '')
                                            ]))

                new_conn = create_new_connection(controller, old_src_module,
                                                 old_conn.source, new_module,
                                                 destination_port)
                ops.append(('add', new_conn))
        return ops

    def insert_vis(vis_name, vis_port_remap):
        def remap_vis(old_conn, new_cell_module):
            ops = []
            old_src_module = pipeline.modules[old_conn.source.moduleId]
            old_cell_module = pipeline.modules[old_conn.destination.moduleId]

            new_x = (old_src_module.location.x +
                     new_cell_module.location.x) / 2.0
            new_y = (old_src_module.location.y +
                     new_cell_module.location.y) / 2.0

            new_vis_desc = ModuleDescriptor(package=identifier,
                                            name=vis_name,
                                            version='0.3.0')
            new_vis_module = \
                controller.create_module_from_descriptor(new_vis_desc,
                                                         new_x, new_y)

            function_ops = remap_functions(old_cell_module, new_vis_module,
                                           vis_port_remap)
            ops.append(('add', new_vis_module))
            ops.extend(function_ops)
            ops.extend(
                remap_dst_connections(old_cell_module, new_vis_module,
                                      vis_port_remap))

            create_new_connection = UpgradeWorkflowHandler.create_new_connection
            new_conn_1 = create_new_connection(controller, old_src_module,
                                               old_conn.source, new_vis_module,
                                               "table")
            ops.append(('add', new_conn_1))
            new_conn_2 = create_new_connection(controller, new_vis_module,
                                               "self", new_cell_module,
                                               "layers")
            ops.append(('add', new_conn_2))
            return ops

        # returns the actual remap function
        return remap_vis

    # zoom gets moved for free from old cell to new cell
    remap = UpgradePackageRemap()

    def add_legacy(fname, module):
        new_function = controller.create_function(module, "allowLegacy",
                                                  ["True"])
        return [('add', new_function, 'module', module.id)]

    remap.add_module_remap(
        UpgradeModuleRemap('0.1.0',
                           '0.3.0',
                           '0.3.0',
                           new_module="GMapCell",
                           module_name="GMapCell",
                           dst_port_remap={
                               'table':
                               insert_vis("GMapSymbols", {None: add_legacy}),
                               'colormapName':
                               None
                           }))
    remap.add_module_remap(
        UpgradeModuleRemap('0.1.0',
                           '0.3.0',
                           '0.3.0',
                           new_module="GMapCell",
                           module_name="GMapHeatmapCell",
                           dst_port_remap={
                               'table':
                               insert_vis(
                                   "GMapHeatmap", {
                                       'dissipating': 'dissipating',
                                       'maxIntensity': 'maxIntensity',
                                       'opacity': 'opacity',
                                       'radius': 'radius'
                                   }),
                               'dissipating':
                               None,
                               'maxIntensity':
                               None,
                               'opacity':
                               None,
                               'radius':
                               None,
                           }))
    remap.add_module_remap(
        UpgradeModuleRemap('0.1.0',
                           '0.3.0',
                           '0.3.0',
                           new_module="GMapCell",
                           module_name="GMapCircleCell",
                           dst_port_remap={
                               'table':
                               insert_vis(
                                   "GMapCircles", {
                                       'strokeColor': 'strokeColor',
                                       'strokeWeight': 'strokeWeight',
                                       'strokeOpacity': 'strokeOpacity',
                                       'fillColor': 'fillColor',
                                       'fillOpacity': 'fillOpacity'
                                   }),
                               'strokeColor':
                               None,
                               'strokeWeight':
                               None,
                               'strokeOpacity':
                               None,
                               'fillColor':
                               None,
                               'fillOpacity':
                               None,
                           }))
    remap.add_module_remap(
        UpgradeModuleRemap('0.1.0',
                           '0.3.0',
                           '0.3.0',
                           new_module="GMapCell",
                           module_name="GMapSymbolCell",
                           dst_port_remap={
                               'table':
                               insert_vis(
                                   "GMapSymbols", {
                                       'strokeColor': 'strokeColor',
                                       'strokeWeight': 'strokeWeight',
                                       'strokeOpacity': 'strokeOpacity',
                                       'fillStartColor': 'fillStartColor',
                                       'fillEndColor': 'fillEndColor',
                                       'fillOpacity': 'fillOpacity',
                                       'scale': 'scale'
                                   }),
                               'strokeColor':
                               None,
                               'strokeWeight':
                               None,
                               'strokeOpacity':
                               None,
                               'fillStartColor':
                               None,
                               'fillEndColor':
                               None,
                               'fillOpacity':
                               None,
                               'scale':
                               None,
                           }))

    return UpgradeWorkflowHandler.remap_module(controller, module_id, pipeline,
                                               remap)
Exemple #5
0
def handle_module_upgrade_request(controller, module_id, pipeline):
    from vistrails.core.modules.module_descriptor import ModuleDescriptor
    from vistrails.core.upgradeworkflow import UpgradeWorkflowHandler, \
        UpgradePackageRemap, UpgradeModuleRemap
    from vistrails.core.modules.basic_modules import identifier as basic_pkg

    def remap_functions(old_module, new_module, function_remap):
        # FIXME need use_registry flag passed through!
        use_registry = True
        function_ops = []
        for function in old_module.functions:
            if function.name in function_remap:
                remap = function_remap[function.name]
                if remap is None:
                    # don't add the function back in
                    continue
                elif not isinstance(remap, basestring):
                    function_ops.extend(remap(function, new_module))
                    continue
                else:
                    function_name = remap

                if len(function.parameters) > 0:
                    new_param_vals, aliases = zip(*[(p.strValue, p.alias)
                                                    for p in function.parameters])
                else:
                    new_param_vals = []
                    aliases = []
                if use_registry:
                    function_port_spec = function_name
                else:
                    def mk_psi(pos):
                        psi = PortSpecItem(module="Module", package=basic_pkg,
                                           namespace="", pos=pos)
                        return psi
                    n_items = len(new_param_vals)
                    function_port_spec = PortSpec(name=function_name,
                                                  items=[mk_psi(i)
                                                         for i in xrange(n_items)])
                new_function = controller.create_function(new_module,
                                                          function_port_spec,
                                                          new_param_vals,
                                                          aliases)
                new_module.add_function(new_function)

        if None in function_remap:
            # used to add new functions
            remap = function_remap[None]
            function_ops.extend(remap(None, new_module))
        return function_ops

    def remap_dst_connections(old_module, new_module, port_remap):
        # FIXME need use_registry flag passed through!
        use_registry = True
        create_new_connection = UpgradeWorkflowHandler.create_new_connection

        ops = []
        for _, conn_id in pipeline.graph.edges_to(old_module.id):
            old_conn = pipeline.connections[conn_id]
            if old_conn.destination.name in port_remap:
                remap = port_remap[old_conn.destination.name]
                if remap is None:
                    # don't add this connection back in
                    continue
                elif not isinstance(remap, basestring):
                    ops.extend(remap(old_conn, new_module))
                    continue
                else:
                    destination_name = remap

                old_src_module = pipeline.modules[old_conn.source.moduleId]
                if use_registry:
                    destination_port = destination_name
                else:
                    destination_port = Port(name=destination_name,
                                            type='destination',
                                            signature=create_port_spec_string(
                                                [(basic_pkg, 'Variant', '')]))

                new_conn = create_new_connection(controller,
                                                 old_src_module,
                                                 old_conn.source,
                                                 new_module,
                                                 destination_port)
                ops.append(('add', new_conn))
        return ops

    def insert_vis(vis_name, vis_port_remap):
        def remap_vis(old_conn, new_cell_module):
            ops = []
            old_src_module = pipeline.modules[old_conn.source.moduleId]
            old_cell_module = pipeline.modules[old_conn.destination.moduleId]

            new_x = (old_src_module.location.x + new_cell_module.location.x)/2.0
            new_y = (old_src_module.location.y + new_cell_module.location.y)/2.0

            new_vis_desc = ModuleDescriptor(package=identifier,
                                            name=vis_name,
                                            version='0.3')
            new_vis_module = \
                controller.create_module_from_descriptor(new_vis_desc,
                                                         new_x, new_y)

            function_ops = remap_functions(old_cell_module,
                                           new_vis_module,
                                           vis_port_remap)
            ops.append(('add', new_vis_module))
            ops.extend(function_ops)
            ops.extend(remap_dst_connections(old_cell_module,
                                             new_vis_module,
                                             vis_port_remap))

            create_new_connection = UpgradeWorkflowHandler.create_new_connection
            new_conn_1 = create_new_connection(controller,
                                               old_src_module,
                                               old_conn.source,
                                               new_vis_module,
                                               "table")
            ops.append(('add', new_conn_1))
            new_conn_2 = create_new_connection(controller,
                                               new_vis_module,
                                               "self",
                                               new_cell_module,
                                               "layers")
            ops.append(('add', new_conn_2))
            return ops

        # returns the actual remap function
        return remap_vis

    # zoom gets moved for free from old cell to new cell
    remap = UpgradePackageRemap()
    def add_legacy(fname, module):
        new_function = controller.create_function(module,
                                                  "allowLegacy",
                                                  ["True"])
        return [('add', new_function, 'module', module.id)]
    remap.add_module_remap(UpgradeModuleRemap('0.1', '0.3', '0.3',
                                              new_module="GMapCell",
                                              module_name="GMapCell",
                            dst_port_remap={'table': insert_vis("GMapSymbols",
                                            {None: add_legacy}),
                                            'colormapName': None}))
    remap.add_module_remap(UpgradeModuleRemap('0.1', '0.3', '0.3',
                                              new_module="GMapCell",
                                              module_name="GMapHeatmapCell",
                            dst_port_remap={'table': insert_vis("GMapHeatmap",
                                            {'dissipating': 'dissipating',
                                             'maxIntensity': 'maxIntensity',
                                             'opacity': 'opacity',
                                             'radius': 'radius'}),
                                            'dissipating': None,
                                            'maxIntensity': None,
                                            'opacity': None,
                                            'radius': None,
                                            }))
    remap.add_module_remap(UpgradeModuleRemap('0.1', '0.3', '0.3',
                                              new_module="GMapCell",
                                              module_name="GMapCircleCell",
                            dst_port_remap={'table': insert_vis("GMapCircles",
                                            {'strokeColor': 'strokeColor',
                                             'strokeWeight': 'strokeWeight',
                                             'strokeOpacity': 'strokeOpacity',
                                             'fillColor': 'fillColor',
                                             'fillOpacity': 'fillOpacity'}),
                                            'strokeColor': None,
                                            'strokeWeight': None,
                                            'strokeOpacity': None,
                                            'fillColor': None,
                                            'fillOpacity': None,
                                            }))
    remap.add_module_remap(UpgradeModuleRemap('0.1', '0.3', '0.3',
                                              new_module="GMapCell",
                                              module_name="GMapSymbolCell",
                            dst_port_remap={'table': insert_vis("GMapSymbols",
                                            {'strokeColor': 'strokeColor',
                                             'strokeWeight': 'strokeWeight',
                                             'strokeOpacity': 'strokeOpacity',
                                             'fillStartColor': 'fillStartColor',
                                             'fillEndColor': 'fillEndColor',
                                             'fillOpacity': 'fillOpacity',
                                             'scale': 'scale'}),
                                            'strokeColor': None,
                                            'strokeWeight': None,
                                            'strokeOpacity': None,
                                            'fillStartColor': None,
                                            'fillEndColor': None,
                                            'fillOpacity': None,
                                            'scale': None,
                                        }))

    return UpgradeWorkflowHandler.remap_module(controller, module_id, pipeline,
                                               remap)
Exemple #6
0
def handle_module_upgrade_request(controller, module_id, pipeline):
    global _remap, _controller, _pipeline

    if _remap is None:
        _remap = UpgradePackageRemap()
        remap = UpgradeModuleRemap(None,
                                   '1.0.0',
                                   '1.0.0',
                                   module_name='vtkInteractionHandler')
        remap.add_remap('src_port_remap', 'self', 'Instance')
        _remap.add_module_remap(remap)
        remap = UpgradeModuleRemap(None,
                                   '1.0.0',
                                   '1.0.0',
                                   module_name='VTKCell')
        _remap.add_module_remap(remap)
        remap = UpgradeModuleRemap(None,
                                   '1.0.0',
                                   '1.0.0',
                                   module_name='VTKViewCell',
                                   new_module='VTKCell')
        _remap.add_module_remap(remap)

    _controller = controller
    _pipeline = pipeline
    module_name = pipeline.modules[module_id].name
    module_name = module_name_remap.get(module_name, module_name)
    if not _remap.has_module_remaps(module_name):
        build_remap(module_name)

    try:
        from vistrails.packages.spreadsheet.init import upgrade_cell_to_output
    except ImportError:
        # Manually upgrade to 1.0.1
        if _remap.get_module_remaps(module_name):
            module_remap = copy.copy(_remap)
            module_remap.add_module_remap(
                UpgradeModuleRemap('1.0.0',
                                   '1.0.1',
                                   '1.0.1',
                                   module_name=module_name))
        else:
            module_remap = _remap
    else:
        module_remap = upgrade_cell_to_output(_remap,
                                              module_id,
                                              pipeline,
                                              'VTKCell',
                                              'vtkRendererOutput',
                                              '1.0.1',
                                              'AddRenderer',
                                              start_version='1.0.0')
        if _remap.get_module_remaps(module_name):
            remap = module_remap.get_module_upgrade(module_name, '1.0.0')
            if remap is None:
                # Manually upgrade to 1.0.1
                module_remap.add_module_remap(
                    UpgradeModuleRemap('1.0.0',
                                       '1.0.1',
                                       '1.0.1',
                                       module_name=module_name))

    return UpgradeWorkflowHandler.remap_module(controller, module_id, pipeline,
                                               module_remap)