<s> from __future__ import division <EOL> from itertools import izip , chain <EOL> from ast import literal_eval <EOL> import collections <EOL> import copy <EOL> import os <EOL> import tempfile <EOL> import traceback <EOL> import uuid <EOL> import warnings <EOL> from vistrails . core import debug , get_vistrails_application <EOL> from vistrails . core . data_structures . graph import Graph <EOL> import vistrails . core . modules <EOL> from vistrails . core . modules . config import ConstantWidgetConfig , ModuleSettings , InputPort , OutputPort , CompoundInputPort , CompoundOutputPort , DeprecatedInputPort <EOL> import vistrails . core . modules . vistrails_module <EOL> from vistrails . core . modules . module_descriptor import ModuleDescriptor <EOL> from vistrails . core . modules . package import Package <EOL> from vistrails . core . requirements import MissingRequirement <EOL> import vistrails . core . modules . utils <EOL> from vistrails . core . modules . utils import create_port_spec_item_string <EOL> from vistrails . core . utils import VistrailsInternalError , memo_method , InvalidModuleClass , ModuleAlreadyExists , append_to_dict_of_lists , all , profile , versions_increasing , InvalidPipeline , VistrailsDeprecation <EOL> from vistrails . core . system import vistrails_root_directory , vistrails_version , get_vistrails_basic_pkg_id <EOL> from vistrails . core . vistrail . port_spec import PortSpec <EOL> from vistrails . core . vistrail . port_spec_item import PortSpecItem <EOL> import vistrails . core . cache . hasher <EOL> from vistrails . db . domain import DBRegistry <EOL> import unittest <EOL> def _check_fringe ( fringe ) : <EOL> assert isinstance ( fringe , list ) <EOL> assert len ( fringe ) >= <NUM_LIT:1> <EOL> for v in fringe : <EOL> assert isinstance ( v , tuple ) <EOL> assert len ( v ) == <NUM_LIT:2> <EOL> assert isinstance ( v [ <NUM_LIT:0> ] , float ) <EOL> assert isinstance ( v [ <NUM_LIT:1> ] , float ) <EOL> def _toposort_modules ( module_list ) : <EOL> """<STR_LIT>""" <EOL> g = Graph ( ) <EOL> for m in module_list : <EOL> if isinstance ( m , tuple ) : <EOL> g . add_vertex ( m [ <NUM_LIT:0> ] , m ) <EOL> else : <EOL> g . add_vertex ( m , m ) <EOL> for m in module_list : <EOL> if isinstance ( m , tuple ) : <EOL> m = m [ <NUM_LIT:0> ] <EOL> for subclass in m . mro ( ) [ <NUM_LIT:1> : ] : <EOL> if subclass in g . vertices : <EOL> g . add_edge ( subclass , m ) <EOL> return [ g . vertices [ v ] for v in g . vertices_topological_sort ( ) ] <EOL> def _parse_abstraction_name ( filename ) : <EOL> prefixes = [ "<STR_LIT>" ] <EOL> suffixes = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> name = os . path . basename ( filename ) <EOL> for prefix in prefixes : <EOL> if name . startswith ( prefix ) : <EOL> name = name [ len ( prefix ) : ] <EOL> break <EOL> for suffix in suffixes : <EOL> if name . lower ( ) . endswith ( suffix ) : <EOL> name = name [ : - len ( suffix ) ] <EOL> break <EOL> return name <EOL> def _toposort_abstractions ( package , abstraction_list ) : <EOL> from vistrails . core . modules . sub_module import find_internal_abstraction_refs <EOL> g = Graph ( ) <EOL> for a in abstraction_list : <EOL> if isinstance ( a , tuple ) : <EOL> if isinstance ( a [ <NUM_LIT:1> ] , dict ) and '<STR_LIT:name>' in a [ <NUM_LIT:1> ] : <EOL> name = ( a [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] , a [ <NUM_LIT:1> ] . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> else : <EOL> name = ( _parse_abstraction_name ( a [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> g . add_vertex ( name , a ) <EOL> else : <EOL> g . add_vertex ( ( _parse_abstraction_name ( a ) , '<STR_LIT>' ) , a ) <EOL> for a in abstraction_list : <EOL> if isinstance ( a , tuple ) : <EOL> a = a [ <NUM_LIT:0> ] <EOL> for ref in find_internal_abstraction_refs ( package , a ) : <EOL> if ref in g . vertices : <EOL> g . add_edge ( ref , a ) <EOL> return [ g . vertices [ v ] for v in g . vertices_topological_sort ( ) ] <EOL> class ModuleRegistrySignals ( object ) : <EOL> def __init__ ( self ) : <EOL> app = get_vistrails_application ( ) <EOL> notifications = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> for notification in notifications : <EOL> app . create_notification ( notification ) <EOL> def emit_new_module ( self , descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , descriptor ) <EOL> def emit_new_abstraction ( self , descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , descriptor ) <EOL> def emit_new_package ( self , identifier , prepend = False ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , identifier , prepend ) <EOL> def emit_deleted_module ( self , descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , descriptor ) <EOL> def emit_deleted_abstraction ( self , descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , descriptor ) <EOL> def emit_deleted_package ( self , package ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , package ) <EOL> def emit_new_input_port ( self , identifier , name , port_name , spec ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , identifier , name , <EOL> port_name , spec ) <EOL> def emit_new_output_port ( self , identifier , name , port_name , spec ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , identifier , name , <EOL> port_name , spec ) <EOL> def emit_show_module ( self , descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , descriptor ) <EOL> def emit_hide_module ( self , descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , descriptor ) <EOL> def emit_module_updated ( self , old_descriptor , new_descriptor ) : <EOL> app = get_vistrails_application ( ) <EOL> app . send_notification ( "<STR_LIT>" , old_descriptor , <EOL> new_descriptor ) <EOL> registry = None <EOL> add_module = None <EOL> add_input_port = None <EOL> has_input_port = None <EOL> add_output_port = None <EOL> set_current_package = None <EOL> get_descriptor_by_name = None <EOL> get_module_by_name = None <EOL> get_descriptor = None <EOL> class ModuleRegistryException ( Exception ) : <EOL> def __init__ ( self , identifier , name = None , namespace = None , <EOL> package_version = None , module_version = None , module_id = None ) : <EOL> Exception . __init__ ( self ) <EOL> self . _identifier = identifier <EOL> self . _name = name <EOL> self . _namespace = namespace <EOL> self . _package_version = package_version <EOL> self . _module_version = module_version <EOL> self . _module_id = module_id <EOL> def __str__ ( self ) : <EOL> p_version_str = "<STR_LIT>" <EOL> m_str = "<STR_LIT>" <EOL> if self . _package_version : <EOL> p_version_str = "<STR_LIT>" % self . _package_version <EOL> if self . _name : <EOL> if self . _namespace : <EOL> m_str = "<STR_LIT>" % ( self . _namespace , self . _name ) <EOL> else : <EOL> m_str = "<STR_LIT>" % self . _name <EOL> if self . _module_version : <EOL> m_str += "<STR_LIT>" % self . _module_version <EOL> return "<STR_LIT>" % ( self . _identifier , <EOL> p_version_str , m_str ) <EOL> __repr__ = __str__ <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) and self . _identifier == other . _identifier and self . _name == other . _name and self . _namespace == other . _namespace and self . _package_version == other . _package_version and self . _module_version == other . _module_version and self . _module_id == other . _module_id <EOL> def __hash__ ( self ) : <EOL> return ( type ( self ) , self . _identifier , self . _name , self . _namespace , <EOL> self . _package_version , self . _module_version , <EOL> self . _module_id ) . __hash__ ( ) <EOL> def _get_module_name ( self ) : <EOL> if self . _namespace : <EOL> return "<STR_LIT>" % ( self . _namespace , self . _name ) <EOL> return self . _name <EOL> _module_name = property ( _get_module_name ) <EOL> def _get_package_name ( self ) : <EOL> if self . _package_version : <EOL> return "<STR_LIT>" % ( self . _identifier , <EOL> self . _package_version ) <EOL> return self . _identifier <EOL> _package_name = property ( _get_package_name ) <EOL> class MissingPackage ( ModuleRegistryException ) : <EOL> def __init__ ( self , identifier ) : <EOL> ModuleRegistryException . __init__ ( self , identifier ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . _identifier <EOL> __repr__ = __str__ <EOL> def _get_module_id ( self ) : <EOL> return None <EOL> def _set_module_id ( self , m_id ) : <EOL> pass <EOL> _module_id = property ( _get_module_id , _set_module_id ) <EOL> class MissingModule ( ModuleRegistryException ) : <EOL> def __init__ ( self , identifier , name , namespace , package_version = None , <EOL> module_id = None ) : <EOL> ModuleRegistryException . __init__ ( self , identifier , name , namespace , <EOL> package_version , None , module_id ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _module_name , <EOL> self . _package_name ) <EOL> __repr__ = __str__ <EOL> class MissingPackageVersion ( ModuleRegistryException ) : <EOL> def __init__ ( self , identifier , version ) : <EOL> ModuleRegistryException . __init__ ( self , identifier , None , None , <EOL> version ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _package_version , self . _identifier ) <EOL> __repr__ = __str__ <EOL> class MissingModuleVersion ( ModuleRegistryException ) : <EOL> def __init__ ( self , identifier , name , namespace , module_version , <EOL> package_version = None , module_id = None ) : <EOL> ModuleRegistryException . __init__ ( self , identifier , name , namespace , <EOL> package_version , module_version , module_id ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _module_version , self . _module_name , self . _package_name ) <EOL> __repr__ = __str__ <EOL> class AmbiguousResolution ( ModuleRegistryException ) : <EOL> def __init__ ( self , name , namespace , matches ) : <EOL> ModuleRegistryException . __init__ ( self , "<STR_LIT>" , <EOL> name , namespace ) <EOL> self . matches = matches <EOL> def __str__ ( self ) : <EOL> return ( "<STR_LIT>" % ( self . _module_name , <EOL> '<STR_LIT>' . join ( str ( m ) for m in self . matches ) ) ) <EOL> __repr__ = __str__ <EOL> class MissingPort ( ModuleRegistryException ) : <EOL> def __init__ ( self , descriptor , port_name , port_type ) : <EOL> ModuleRegistryException . __init__ ( self , <EOL> descriptor . identifier , <EOL> descriptor . name , <EOL> descriptor . namespace ) <EOL> self . _port_name = port_name <EOL> self . _port_type = port_type <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _port_type , self . _port_name , self . _module_name , <EOL> self . _package_name ) <EOL> __repr__ = __str__ <EOL> class PortMismatch ( MissingPort ) : <EOL> def __init__ ( self , identifier , name , namespace , port_name , port_type , port_sigstring ) : <EOL> ModuleRegistryException . __init__ ( self , <EOL> identifier , <EOL> name , <EOL> namespace ) <EOL> self . _port_name = port_name <EOL> self . _port_type = port_type <EOL> self . _port_sigstring = port_sigstring <EOL> def __str__ ( self ) : <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % ( self . _port_type . capitalize ( ) , self . _port_name , <EOL> self . _port_sigstring , self . _module_name , self . _package_name ) <EOL> __repr__ = __str__ <EOL> class PortsIncompatible ( ModuleRegistryException ) : <EOL> def __init__ ( self , output_identifier , output_name , output_namespace , <EOL> output_port , input_identifier , input_name , input_namespace , <EOL> input_port ) : <EOL> ModuleRegistryException . __init__ ( self , output_identifier , output_name , <EOL> output_namespace ) <EOL> self . _output_port = output_port <EOL> self . _input_identifier = input_identifier <EOL> self . _input_name = input_name <EOL> self . _input_namespace = input_namespace <EOL> self . _input_port = input_port <EOL> def __str__ ( self ) : <EOL> if self . _namespace : <EOL> out_name = "<STR_LIT>" % ( self . _identifier , self . _namespace , <EOL> self . _name ) <EOL> else : <EOL> out_name = "<STR_LIT>" % ( self . _identifier , self . _name ) <EOL> if self . _input_namespace : <EOL> in_name = "<STR_LIT>" % ( self . _input_identifier , <EOL> self . _input_namespace , <EOL> self . _input_name ) <EOL> else : <EOL> in_name = "<STR_LIT>" % ( self . _input_identifier , self . _input_name ) <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . _output_port , <EOL> out_name , <EOL> self . _input_port , <EOL> in_name ) ) <EOL> __repr__ = __str__ <EOL> class DuplicateModule ( ModuleRegistryException ) : <EOL> def __init__ ( self , old_descriptor , new_identifier , new_name , <EOL> new_namespace ) : <EOL> ModuleRegistryException . __init__ ( self , <EOL> new_identifier , <EOL> new_name , <EOL> new_namespace ) <EOL> self . old_descriptor = old_descriptor <EOL> def __str__ ( self ) : <EOL> if self . old_descriptor . namespace : <EOL> old_name = "<STR_LIT>" % ( self . old_descriptor . namespace , <EOL> self . old_descriptor . name ) <EOL> else : <EOL> old_name = self . old_descriptor . name <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % ( self . _module_name , self . _package_name , old_name , <EOL> self . old_descriptor . identifier ) <EOL> __repr__ = __str__ <EOL> class DuplicateIdentifier ( ModuleRegistryException ) : <EOL> def __init__ ( self , identifier , name , namespace = None , <EOL> package_version = None , module_version = None ) : <EOL> ModuleRegistryException . __init__ ( self , identifier , name , namespace , <EOL> package_version , module_version ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _module_name , self . _package_name ) <EOL> __repr__ = __str__ <EOL> class InvalidPortSpec ( ModuleRegistryException ) : <EOL> def __init__ ( self , descriptor , port_name , port_type , exc ) : <EOL> ModuleRegistryException . __init__ ( self , <EOL> descriptor . identifier , <EOL> descriptor . name , <EOL> descriptor . namespace ) <EOL> self . _port_name = port_name <EOL> self . _port_type = port_type [ <NUM_LIT:0> ] . capitalize ( ) + port_type [ <NUM_LIT:1> : ] <EOL> self . _exc = exc <EOL> def __str__ ( self ) : <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . _port_type , self . _port_name , self . _module_name , <EOL> self . _package_name , str ( self . _exc ) ) ) <EOL> __repr__ = __str__ <EOL> class MissingBaseClass ( Exception ) : <EOL> def __init__ ( self , base ) : <EOL> Exception . __init__ ( self ) <EOL> self . _base = base <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _base . __name__ ) <EOL> __repr__ = __str__ <EOL> class ModuleRegistry ( DBRegistry ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = - <NUM_LIT:1> <EOL> DBRegistry . __init__ ( self , * args , ** kwargs ) <EOL> self . _conversions = dict ( ) <EOL> self . _converters = set ( ) <EOL> self . set_defaults ( ) <EOL> def __copy__ ( self ) : <EOL> ModuleRegistry . do_copy ( self ) <EOL> def set_defaults ( self , other = None ) : <EOL> self . _root_descriptor = None <EOL> self . signals = ModuleRegistrySignals ( ) <EOL> self . setup_indices ( ) <EOL> if other is None : <EOL> self . _constant_hasher_map = { } <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> if basic_pkg in self . packages : <EOL> self . _default_package = self . packages [ basic_pkg ] <EOL> self . _current_package = self . _default_package <EOL> else : <EOL> self . _default_package = None <EOL> self . _current_package = None <EOL> else : <EOL> self . _constant_hasher_map = copy . copy ( other . _constant_hasher_map ) <EOL> self . _current_package = self . packages [ other . _current_package . identifier ] <EOL> self . _default_package = self . packages [ other . _default_package . identifier ] <EOL> def setup_indices ( self ) : <EOL> self . descriptors_by_id = { } <EOL> self . package_versions = self . db_packages_identifier_index <EOL> self . packages = { } <EOL> self . _module_key_map = { } <EOL> for pkg in self . package_versions . itervalues ( ) : <EOL> for key in chain ( pkg . old_identifiers , [ pkg . identifier ] ) : <EOL> if key in self . packages : <EOL> old_pkg = self . packages [ key ] <EOL> if versions_increasing ( old_pkg . version , pkg . version ) : <EOL> self . packages [ key ] = pkg <EOL> else : <EOL> self . packages [ key ] = pkg <EOL> for descriptor in pkg . descriptor_list : <EOL> self . descriptors_by_id [ descriptor . id ] = descriptor <EOL> k = ( descriptor . identifier , descriptor . name , <EOL> descriptor . namespace , pkg . version , descriptor . version ) <EOL> if descriptor . module is not None : <EOL> self . _module_key_map [ descriptor . module ] = k <EOL> for descriptor in self . descriptors_by_id . itervalues ( ) : <EOL> if descriptor . base_descriptor_id in self . descriptors_by_id : <EOL> base_descriptor = self . descriptors_by_id [ descriptor . base_descriptor_id ] <EOL> if descriptor not in base_descriptor . children : <EOL> base_descriptor . children . append ( descriptor ) <EOL> def do_copy ( self , new_ids = False , id_scope = None , id_remap = None ) : <EOL> cp = DBRegistry . do_copy ( self , new_ids , id_scope , id_remap ) <EOL> cp . __class__ = ModuleRegistry <EOL> cp . set_defaults ( self ) <EOL> return cp <EOL> @ staticmethod <EOL> def convert ( _reg ) : <EOL> if _reg . __class__ == ModuleRegistry : <EOL> return <EOL> _reg . __class__ = ModuleRegistry <EOL> for package in _reg . package_list : <EOL> Package . convert ( package ) <EOL> _reg . set_defaults ( ) <EOL> def set_global ( self ) : <EOL> global registry , add_module , add_input_port , has_input_port , add_output_port , set_current_package , get_descriptor_by_name , get_module_by_name , get_descriptor <EOL> if registry is not None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" ) <EOL> registry = self <EOL> add_module = self . add_module <EOL> add_input_port = self . add_input_port <EOL> has_input_port = self . has_input_port <EOL> add_output_port = self . add_output_port <EOL> set_current_package = self . set_current_package <EOL> get_descriptor_by_name = self . get_descriptor_by_name <EOL> get_module_by_name = self . get_module_by_name <EOL> get_descriptor = self . get_descriptor <EOL> package_list = DBRegistry . db_packages <EOL> root_descriptor_id = DBRegistry . db_root_descriptor_id <EOL> def _get_root_descriptor ( self ) : <EOL> if self . _root_descriptor is None : <EOL> if self . root_descriptor_id >= <NUM_LIT:0> : <EOL> self . _root_descriptor = self . descriptors_by_id [ self . root_descriptor_id ] <EOL> return self . _root_descriptor <EOL> def _set_root_descriptor ( self , descriptor ) : <EOL> self . _root_descriptor = descriptor <EOL> self . root_descriptor_id = descriptor . id <EOL> root_descriptor = property ( _get_root_descriptor , _set_root_descriptor ) <EOL> def add_descriptor ( self , desc , package = None ) : <EOL> if package is None : <EOL> package = self . _default_package <EOL> self . descriptors_by_id [ desc . id ] = desc <EOL> package . add_descriptor ( desc ) <EOL> def delete_descriptor ( self , desc , package = None ) : <EOL> if package is None : <EOL> try : <EOL> package = self . packages [ desc . identifier ] <EOL> except KeyError : <EOL> package = self . _default_package <EOL> if desc . base_descriptor_id != - <NUM_LIT:1> and desc . base_descriptor : <EOL> desc . base_descriptor . children . remove ( desc ) <EOL> del self . descriptors_by_id [ desc . id ] <EOL> package . delete_descriptor ( desc ) <EOL> def add_package ( self , package ) : <EOL> DBRegistry . db_add_package ( self , package ) <EOL> for key in chain ( package . old_identifiers , [ package . identifier ] ) : <EOL> if key in self . packages : <EOL> old_pkg = self . packages [ key ] <EOL> if versions_increasing ( old_pkg . version , package . version ) : <EOL> self . packages [ key ] = package <EOL> else : <EOL> self . packages [ key ] = package <EOL> def delete_package ( self , package ) : <EOL> DBRegistry . db_delete_package ( self , package ) <EOL> self . setup_indices ( ) <EOL> def has_abs_upgrade ( self , identifier , name , namespace = '<STR_LIT>' , <EOL> package_version = '<STR_LIT>' , module_version = '<STR_LIT>' ) : <EOL> try : <EOL> package = self . get_package_by_name ( identifier , package_version ) <EOL> except MissingPackageVersion : <EOL> package = self . get_package_by_name ( identifier ) <EOL> return package . has_abs_upgrade ( name , namespace , module_version ) <EOL> def get_abs_upgrade ( self , identifier , name , namespace = '<STR_LIT>' , <EOL> package_version = '<STR_LIT>' , module_version = '<STR_LIT>' ) : <EOL> try : <EOL> package = self . get_package_by_name ( identifier , package_version ) <EOL> except MissingPackageVersion : <EOL> package = self . get_package_by_name ( identifier ) <EOL> return package . get_abs_upgrade ( name , namespace , module_version ) <EOL> def get_package_by_name ( self , identifier , package_version = '<STR_LIT>' ) : <EOL> package_version = package_version or '<STR_LIT>' <EOL> package_version_key = ( identifier , package_version ) <EOL> try : <EOL> if not package_version : <EOL> return self . packages [ identifier ] <EOL> else : <EOL> return self . package_versions [ package_version_key ] <EOL> except KeyError : <EOL> if identifier not in self . packages : <EOL> raise MissingPackage ( identifier ) <EOL> elif package_version and package_version_key not in self . package_versions : <EOL> raise MissingPackageVersion ( identifier , package_version ) <EOL> def get_module_by_name ( self , identifier , name , namespace = None ) : <EOL> """<STR_LIT>""" <EOL> return self . get_descriptor_by_name ( identifier , name , namespace ) . module <EOL> def has_descriptor_with_name ( self , identifier , name , namespace = '<STR_LIT>' , <EOL> package_version = '<STR_LIT>' , module_version = '<STR_LIT>' ) : <EOL> namespace = namespace or '<STR_LIT>' <EOL> package_version = package_version or '<STR_LIT>' <EOL> module_version = module_version or '<STR_LIT>' <EOL> try : <EOL> if not package_version : <EOL> package = self . packages [ identifier ] <EOL> else : <EOL> package_version_key = ( identifier , package_version ) <EOL> package = self . package_versions [ package_version_key ] <EOL> if not module_version : <EOL> descriptor = package . descriptors [ ( name , namespace ) ] <EOL> else : <EOL> descriptor_version_key = ( name , namespace , module_version ) <EOL> descriptor = package . descriptor_versions [ descriptor_version_key ] <EOL> except KeyError : <EOL> return False <EOL> return True <EOL> has_module = has_descriptor_with_name <EOL> def get_descriptor_by_name ( self , identifier , name , namespace = '<STR_LIT>' , <EOL> package_version = '<STR_LIT>' , module_version = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> namespace = namespace or '<STR_LIT>' <EOL> package_version = package_version or '<STR_LIT>' <EOL> module_version = module_version or '<STR_LIT>' <EOL> try : <EOL> package = self . packages [ identifier ] <EOL> except KeyError : <EOL> raise MissingPackage ( identifier ) <EOL> if package_version : <EOL> try : <EOL> package = self . package_versions [ ( identifier , package_version ) ] <EOL> except KeyError : <EOL> raise MissingPackageVersion ( identifier , package_version ) <EOL> try : <EOL> descriptor = package . descriptors [ ( name , namespace ) ] <EOL> except KeyError : <EOL> raise MissingModule ( identifier , name , namespace , <EOL> package_version ) <EOL> if module_version : <EOL> descriptor_version_key = ( name , namespace , module_version ) <EOL> try : <EOL> descriptor = package . descriptor_versions [ descriptor_version_key ] <EOL> except KeyError : <EOL> raise MissingModuleVersion ( identifier , name , namespace , <EOL> module_version , package_version ) <EOL> return descriptor <EOL> def get_similar_descriptor ( self , identifier , name , namespace = None , <EOL> package_version = None , module_version = None ) : <EOL> try : <EOL> return self . get_descriptor_by_name ( identifier , name , namespace , <EOL> package_version , module_version ) <EOL> except MissingPackageVersion : <EOL> return self . get_similar_descriptor ( identifier , name , namespace , <EOL> None , module_version ) <EOL> except MissingModuleVersion : <EOL> return self . get_similar_descriptor ( identifier , name , namespace , <EOL> package_version , None ) <EOL> def get_descriptor ( self , module ) : <EOL> """<STR_LIT>""" <EOL> k = self . _module_key_map [ module ] <EOL> return self . get_descriptor_by_name ( * k ) <EOL> get_descriptor_from_module = get_descriptor <EOL> def module_ports ( self , p_type , descriptor ) : <EOL> return [ ( p . name , p ) <EOL> for p in descriptor . port_specs_list <EOL> if p . type == p_type ] <EOL> def module_source_ports_from_descriptor ( self , do_sort , descriptor ) : <EOL> ports = { } <EOL> for desc in reversed ( self . get_module_hierarchy ( descriptor ) ) : <EOL> ports . update ( self . module_ports ( '<STR_LIT>' , desc ) ) <EOL> all_ports = ports . values ( ) <EOL> if do_sort : <EOL> all_ports . sort ( key = lambda x : ( x . sort_key , x . id ) ) <EOL> return all_ports <EOL> def module_source_ports ( self , do_sort , identifier , module_name , <EOL> namespace = None , version = None ) : <EOL> descriptor = self . get_descriptor_by_name ( identifier , module_name , <EOL> namespace , version ) <EOL> return self . module_source_ports_from_descriptor ( do_sort , descriptor ) <EOL> def module_destination_ports_from_descriptor ( self , do_sort , descriptor ) : <EOL> ports = { } <EOL> for desc in reversed ( self . get_module_hierarchy ( descriptor ) ) : <EOL> ports . update ( self . module_ports ( '<STR_LIT:input>' , desc ) ) <EOL> all_ports = ports . values ( ) <EOL> if do_sort : <EOL> all_ports . sort ( key = lambda x : ( x . sort_key , x . id ) ) <EOL> return all_ports <EOL> def module_destination_ports ( self , do_sort , identifier , module_name , <EOL> namespace = None , version = None ) : <EOL> descriptor = self . get_descriptor_by_name ( identifier , module_name , <EOL> namespace , version ) <EOL> return self . module_destination_ports_from_descriptor ( do_sort , <EOL> descriptor ) <EOL> def get_descriptor_from_name_only ( self , name ) : <EOL> """<STR_LIT>""" <EOL> matches = [ ] <EOL> for pkg in self . package_list : <EOL> matches . extend ( ( pkg , key ) for key in pkg . descriptors . iterkeys ( ) <EOL> if key [ <NUM_LIT:0> ] == name ) <EOL> if len ( matches ) == <NUM_LIT:0> : <EOL> raise MissingModule ( "<STR_LIT>" , name , None ) <EOL> if len ( matches ) > <NUM_LIT:1> : <EOL> matches_str = [ ( m [ <NUM_LIT:0> ] . identifier , m [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , m [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <EOL> m [ <NUM_LIT:0> ] . version ) for m in matches ] <EOL> raise AmbiguousResolution ( name , None , matches_str ) <EOL> ( pkg , key ) = matches [ <NUM_LIT:0> ] <EOL> desc = pkg . descriptors [ key ] <EOL> result = self . get_descriptor_by_name ( pkg . identifier , desc . name , <EOL> desc . namespace , pkg . version , <EOL> desc . version ) <EOL> return result <EOL> def module_signature ( self , pipeline , module ) : <EOL> """<STR_LIT>""" <EOL> chm = self . _constant_hasher_map <EOL> descriptor = self . get_descriptor_by_name ( module . package , <EOL> module . name , <EOL> module . namespace ) <EOL> if not descriptor : <EOL> return vistrails . core . cache . hasher . Hasher . module_signature ( module , chm ) <EOL> c = descriptor . hasher_callable ( ) <EOL> if c : <EOL> return c ( pipeline , module , chm ) <EOL> else : <EOL> return vistrails . core . cache . hasher . Hasher . module_signature ( module , chm ) <EOL> def get_module_color ( self , identifier , name , namespace = None ) : <EOL> return self . get_descriptor_by_name ( identifier , name , namespace ) . module_color ( ) <EOL> def get_module_fringe ( self , identifier , name , namespace = None ) : <EOL> return self . get_descriptor_by_name ( identifier , name , namespace ) . module_fringe ( ) <EOL> def update_registry ( self , base_descriptor , module , identifier , name , <EOL> namespace , package_version = None , version = None ) : <EOL> if namespace is not None and not namespace . strip ( ) : <EOL> namespace = None <EOL> if identifier not in self . packages : <EOL> if self . _current_package . identifier == identifier : <EOL> package = self . _current_package <EOL> else : <EOL> package_id = self . idScope . getNewId ( Package . vtType ) <EOL> package = Package ( id = package_id , <EOL> codepath = "<STR_LIT>" , <EOL> load_configuration = False , <EOL> name = "<STR_LIT>" , <EOL> identifier = identifier , <EOL> version = package_version , <EOL> ) <EOL> self . add_package ( package ) <EOL> else : <EOL> package = self . package_versions [ ( identifier , package_version ) ] <EOL> descriptor_id = self . idScope . getNewId ( ModuleDescriptor . vtType ) <EOL> descriptor = ModuleDescriptor ( id = descriptor_id , <EOL> module = module , <EOL> package = identifier , <EOL> base_descriptor = base_descriptor , <EOL> name = name , <EOL> namespace = namespace , <EOL> package_version = package_version , <EOL> version = version <EOL> ) <EOL> self . add_descriptor ( descriptor , package ) <EOL> if issubclass ( module , <EOL> vistrails . core . modules . vistrails_module . Converter ) : <EOL> self . _conversions = dict ( ) <EOL> self . _converters . add ( descriptor ) <EOL> if module is not None : <EOL> self . _module_key_map [ module ] = ( identifier , name , namespace , <EOL> package_version , version ) <EOL> return descriptor <EOL> def convert_port_val ( self , val , sig = None , cls = None ) : <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> if sig is None and cls is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> try : <EOL> if sig is not None : <EOL> desc = self . get_descriptor_by_name ( * sig ) <EOL> else : <EOL> desc = self . get_descriptor ( cls ) <EOL> except Exception , e : <EOL> debug . unexpected_exception ( e ) <EOL> raise VistrailsInternalError ( "<STR_LIT>" <EOL> "<STR_LIT>" % val ) <EOL> constant_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> if not self . is_descriptor_subclass ( desc , constant_desc ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if desc . module is None : <EOL> return None <EOL> if not isinstance ( val , basestring ) : <EOL> retval = desc . module . translate_to_string ( val ) <EOL> else : <EOL> checkval = desc . module . translate_to_python ( val ) <EOL> retval = desc . module . translate_to_string ( checkval ) <EOL> if isinstance ( checkval , basestring ) and retval != val : <EOL> retval = desc . module . translate_to_string ( val ) <EOL> return retval <EOL> def decode_port ( self , port_info , simple_t , compound_t , deprecated_t , <EOL> is_input ) : <EOL> if ( not isinstance ( port_info , simple_t ) and <EOL> not isinstance ( port_info , compound_t ) ) : <EOL> port_name = port_info [ <NUM_LIT:0> ] <EOL> port_sig = port_info [ <NUM_LIT:1> ] <EOL> if len ( port_info ) > <NUM_LIT:2> : <EOL> if isinstance ( port_info [ <NUM_LIT:2> ] , dict ) : <EOL> port_info = compound_t ( port_info [ <NUM_LIT:0> ] , <EOL> port_info [ <NUM_LIT:1> ] , <EOL> ** port_info [ <NUM_LIT:2> ] ) <EOL> else : <EOL> dep_port_info = deprecated_t ( * port_info ) <EOL> port_info = compound_t ( ** dep_port_info . _asdict ( ) ) <EOL> else : <EOL> port_info = compound_t ( * port_info ) <EOL> kwargs = port_info . _asdict ( ) <EOL> port_name = kwargs . pop ( '<STR_LIT:name>' ) <EOL> port_sig = kwargs . pop ( '<STR_LIT>' ) <EOL> if is_input and isinstance ( port_info , simple_t ) : <EOL> kwargs [ '<STR_LIT>' ] = [ kwargs . pop ( '<STR_LIT:label>' ) ] <EOL> kwargs [ '<STR_LIT>' ] = [ kwargs . pop ( '<STR_LIT:default>' ) ] <EOL> kwargs [ '<STR_LIT>' ] = [ kwargs . pop ( '<STR_LIT>' ) ] <EOL> kwargs [ '<STR_LIT>' ] = [ kwargs . pop ( '<STR_LIT>' ) ] <EOL> elif isinstance ( port_info , compound_t ) : <EOL> port_items = kwargs . pop ( '<STR_LIT>' ) <EOL> if port_items is not None : <EOL> sig_items = [ ] <EOL> labels = [ ] <EOL> defaults = [ ] <EOL> values = [ ] <EOL> entry_types = [ ] <EOL> for item in port_info . items : <EOL> if not isinstance ( item . signature , <EOL> basestring ) : <EOL> d = self . get_descriptor ( item . signature ) <EOL> sig_items . append ( create_port_spec_item_string ( <EOL> d . package , d . name , d . namespace ) ) <EOL> else : <EOL> sig_items . append ( item . signature ) <EOL> labels . append ( item . label ) <EOL> defaults . append ( item . default ) <EOL> values . append ( item . values ) <EOL> entry_types . append ( item . entry_type ) <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( sig_items ) <EOL> if is_input : <EOL> kwargs [ '<STR_LIT>' ] = labels <EOL> kwargs [ '<STR_LIT>' ] = defaults <EOL> kwargs [ '<STR_LIT>' ] = values <EOL> kwargs [ '<STR_LIT>' ] = entry_types <EOL> return port_name , port_sig , kwargs <EOL> def decode_input_port ( self , port_info ) : <EOL> return self . decode_port ( <EOL> port_info , <EOL> InputPort , CompoundInputPort , DeprecatedInputPort , <EOL> True ) <EOL> def decode_output_port ( self , port_info ) : <EOL> return self . decode_port ( <EOL> port_info , <EOL> OutputPort , CompoundOutputPort , OutputPort , <EOL> False ) <EOL> def auto_add_ports ( self , module ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in module . __dict__ : <EOL> for port_info in module . _input_ports : <EOL> name = None <EOL> try : <EOL> name , sig , kwargs = self . decode_input_port ( port_info ) <EOL> self . add_input_port ( module , name , sig , ** kwargs ) <EOL> except Exception , e : <EOL> debug . unexpected_exception ( e ) <EOL> debug . critical ( <EOL> "<STR_LIT>" % ( <EOL> '<STR_LIT>' % name if name is not None <EOL> else "<STR_LIT>" , module . __name__ ) , <EOL> e ) <EOL> raise <EOL> if '<STR_LIT>' in module . __dict__ : <EOL> for port_info in module . _output_ports : <EOL> name = None <EOL> try : <EOL> name , sig , kwargs = self . decode_output_port ( port_info ) <EOL> self . add_output_port ( module , name , sig , ** kwargs ) <EOL> except Exception , e : <EOL> debug . unexpected_exception ( e ) <EOL> debug . critical ( <EOL> "<STR_LIT>" % ( <EOL> '<STR_LIT>' % name if name is not None <EOL> else "<STR_LIT>" , module . __name__ ) , <EOL> e ) <EOL> raise <EOL> def auto_add_module ( self , module ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( module , type ) : <EOL> return self . add_module ( module ) <EOL> elif ( isinstance ( module , tuple ) and <EOL> len ( module ) == <NUM_LIT:2> and <EOL> isinstance ( module [ <NUM_LIT:0> ] , type ) and <EOL> isinstance ( module [ <NUM_LIT:1> ] , dict ) ) : <EOL> descriptor = self . add_module ( module [ <NUM_LIT:0> ] , ** module [ <NUM_LIT:1> ] ) <EOL> return descriptor <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def add_module ( self , module , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def remap_dict ( d ) : <EOL> remap = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> remapped_d = { } <EOL> for k , v in d . iteritems ( ) : <EOL> if k in remap : <EOL> remapped_d [ remap [ k ] ] = v <EOL> else : <EOL> remapped_d [ k ] = v <EOL> return remapped_d <EOL> module_settings = None <EOL> if '<STR_LIT>' in module . __dict__ : <EOL> settings = module . __dict__ [ '<STR_LIT>' ] <EOL> if isinstance ( settings , ModuleSettings ) : <EOL> module_settings = settings <EOL> elif isinstance ( settings , dict ) : <EOL> module_settings = ModuleSettings ( ** remap_dict ( settings ) ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> remapped_kwargs = remap_dict ( kwargs ) <EOL> if module_settings is not None : <EOL> module_settings = module_settings . _replace ( ** remapped_kwargs ) <EOL> else : <EOL> module_settings = ModuleSettings ( ** remapped_kwargs ) <EOL> return self . add_module_from_settings ( module , module_settings ) <EOL> def add_module_from_settings ( self , module , settings ) : <EOL> """<STR_LIT>""" <EOL> def get_setting ( attr , default_val ) : <EOL> val = getattr ( settings , attr ) <EOL> if val is None : <EOL> return default_val <EOL> return val <EOL> name = get_setting ( '<STR_LIT:name>' , module . __name__ ) <EOL> default_identifier = None <EOL> default_version = "<STR_LIT>" <EOL> if self . _current_package is not None : <EOL> default_identifier = self . _current_package . identifier <EOL> default_version = self . _current_package . version <EOL> identifier = get_setting ( '<STR_LIT>' , default_identifier ) <EOL> package_version = get_setting ( '<STR_LIT>' , default_version ) <EOL> namespace = settings . namespace <EOL> version = settings . version <EOL> if identifier is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> package = self . package_versions [ ( identifier , package_version ) ] <EOL> desc_key = ( name , namespace , version ) <EOL> if desc_key in package . descriptor_versions : <EOL> raise ModuleAlreadyExists ( identifier , name ) <EOL> if settings . is_root : <EOL> base_descriptor = None <EOL> else : <EOL> candidates = self . get_subclass_candidates ( module ) <EOL> if len ( candidates ) != <NUM_LIT:1> : <EOL> raise InvalidModuleClass ( module ) <EOL> base_class = candidates [ <NUM_LIT:0> ] <EOL> if base_class not in self . _module_key_map : <EOL> raise MissingBaseClass ( base_class ) <EOL> base_descriptor = self . get_descriptor ( base_class ) <EOL> if module in self . _module_key_map : <EOL> if identifier != '<STR_LIT>' : <EOL> raise DuplicateModule ( self . get_descriptor ( module ) , identifier , <EOL> name , namespace ) <EOL> elif self . has_descriptor_with_name ( identifier , name , namespace , <EOL> package_version , version ) : <EOL> raise DuplicateIdentifier ( identifier , name , namespace , <EOL> package_version , version ) <EOL> descriptor = self . update_registry ( base_descriptor , module , identifier , <EOL> name , namespace , package_version , <EOL> version ) <EOL> if settings . is_root : <EOL> self . root_descriptor = descriptor <EOL> descriptor . set_module_abstract ( settings . abstract ) <EOL> descriptor . set_configuration_widget ( settings . configure_widget ) <EOL> descriptor . is_hidden = settings . hide_descriptor <EOL> descriptor . namespace_hidden = settings . hide_namespace <EOL> if settings . signature : <EOL> descriptor . set_hasher_callable ( settings . signature ) <EOL> if settings . constant_signature : <EOL> if not self . is_constant_module ( module ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> hash_key = ( identifier , name , namespace ) <EOL> self . _constant_hasher_map [ hash_key ] = settings . constant_signature <EOL> constant_widgets = [ ] <EOL> if settings . constant_widget : <EOL> constant_widgets += [ settings . constant_widget ] <EOL> if settings . constant_widgets is not None : <EOL> constant_widgets += settings . constant_widgets <EOL> if len ( constant_widgets ) > <NUM_LIT:0> : <EOL> if not self . is_constant_module ( module ) : <EOL> raise TypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> for widget_t in constant_widgets : <EOL> if isinstance ( widget_t , tuple ) : <EOL> widget_t = ConstantWidgetConfig ( * widget_t ) <EOL> else : <EOL> widget_t = ConstantWidgetConfig ( widget_t ) <EOL> if widget_t . widget is not None : <EOL> self . set_constant_config_widget ( descriptor , <EOL> widget_t . widget , <EOL> widget_t . widget_type , <EOL> widget_t . widget_use ) <EOL> descriptor . set_module_color ( settings . color ) <EOL> if settings . fringe : <EOL> _check_fringe ( settings . fringe ) <EOL> left_fringe = list ( reversed ( [ ( - x , <NUM_LIT:1.0> - y ) for ( x , y ) in settings . fringe ] ) ) <EOL> descriptor . set_module_fringe ( left_fringe , settings . fringe ) <EOL> elif settings . left_fringe and settings . right_fringe : <EOL> _check_fringe ( settings . left_fringe ) <EOL> _check_fringe ( settings . right_fringe ) <EOL> descriptor . set_module_fringe ( settings . left_fringe , <EOL> settings . right_fringe ) <EOL> if settings . ghost_package : <EOL> descriptor . ghost_identifier = settings . ghost_package <EOL> if settings . ghost_package_version : <EOL> descriptor . ghost_package_version = settings . ghost_package_version <EOL> if settings . ghost_namespace : <EOL> descriptor . ghost_namespace = settings . ghost_namespace <EOL> self . signals . emit_new_module ( descriptor ) <EOL> if self . is_abstraction ( descriptor ) : <EOL> self . signals . emit_new_abstraction ( descriptor ) <EOL> return descriptor <EOL> def auto_add_subworkflow ( self , subworkflow ) : <EOL> if isinstance ( subworkflow , str ) : <EOL> return self . add_subworkflow ( subworkflow ) <EOL> elif ( isinstance ( subworkflow , tuple ) and <EOL> len ( subworkflow ) == <NUM_LIT:2> and <EOL> isinstance ( subworkflow [ <NUM_LIT:0> ] , str ) and <EOL> isinstance ( subworkflow [ <NUM_LIT:1> ] , dict ) ) : <EOL> descriptor = self . add_subworkflow ( subworkflow [ <NUM_LIT:0> ] , ** subworkflow [ <NUM_LIT:1> ] ) <EOL> return descriptor <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def add_subworkflow ( self , vt_fname , ** kwargs ) : <EOL> from vistrails . core . modules . sub_module import new_abstraction , read_vistrail , get_next_abs_annotation_key <EOL> if '<STR_LIT>' in kwargs : <EOL> identifier = kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> identifier = self . _current_package . identifier <EOL> if '<STR_LIT>' in kwargs : <EOL> package_version = kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> package_version = self . _current_package . version <EOL> if '<STR_LIT:version>' in kwargs : <EOL> version = kwargs [ '<STR_LIT:version>' ] <EOL> else : <EOL> version = - <NUM_LIT:1> L <EOL> if '<STR_LIT:name>' in kwargs : <EOL> name = kwargs [ '<STR_LIT:name>' ] <EOL> else : <EOL> name = _parse_abstraction_name ( vt_fname ) <EOL> kwargs [ '<STR_LIT:name>' ] = name <EOL> package = self . package_versions [ ( identifier , package_version ) ] <EOL> if not os . path . isabs ( vt_fname ) : <EOL> vt_fname = os . path . join ( package . package_dir , vt_fname ) <EOL> else : <EOL> debug . warning ( "<STR_LIT>" % vt_fname ) <EOL> vistrail = read_vistrail ( vt_fname ) <EOL> namespace = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> module = None <EOL> is_upgraded_abstraction = False <EOL> try : <EOL> module = new_abstraction ( name , vistrail , vt_fname , version ) <EOL> except InvalidPipeline , e : <EOL> import vistrails . core . vistrail . controller <EOL> from vistrails . core . db . io import save_vistrail_to_xml <EOL> from vistrails . core . modules . abstraction import identifier as abstraction_pkg , version as abstraction_ver <EOL> controller = vistrails . core . vistrail . controller . VistrailController ( vistrail ) <EOL> if version == - <NUM_LIT:1> L : <EOL> version = vistrail . get_latest_version ( ) <EOL> ( new_version , new_pipeline ) = controller . handle_invalid_pipeline ( e , long ( version ) , vistrail , <EOL> False , True ) <EOL> del controller <EOL> vistrail . set_annotation ( '<STR_LIT>' , <EOL> ( identifier , name , namespace , <EOL> package_version , str ( version ) ) ) <EOL> vt_save_dir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> vt_fname = os . path . join ( vt_save_dir , os . path . basename ( vt_fname ) ) <EOL> new_namespace = str ( uuid . uuid1 ( ) ) <EOL> annotation_key = get_next_abs_annotation_key ( vistrail ) <EOL> vistrail . set_annotation ( annotation_key , new_namespace ) <EOL> save_vistrail_to_xml ( vistrail , vt_fname ) <EOL> module = new_abstraction ( name , vistrail , vt_fname , new_version , <EOL> new_pipeline ) <EOL> kwargs [ '<STR_LIT>' ] = abstraction_pkg <EOL> kwargs [ '<STR_LIT>' ] = abstraction_ver <EOL> kwargs [ '<STR_LIT>' ] = new_namespace <EOL> kwargs [ '<STR_LIT>' ] = identifier <EOL> kwargs [ '<STR_LIT>' ] = package_version <EOL> kwargs [ '<STR_LIT>' ] = namespace <EOL> is_upgraded_abstraction = True <EOL> module . internal_version = str ( module . internal_version ) <EOL> kwargs [ '<STR_LIT:version>' ] = module . internal_version <EOL> descriptor = None <EOL> if kwargs : <EOL> descriptor = self . add_module ( module , ** kwargs ) <EOL> else : <EOL> descriptor = self . add_module ( module ) <EOL> if is_upgraded_abstraction : <EOL> descriptor_info = ( identifier , name , namespace , <EOL> package_version , str ( version ) ) <EOL> if identifier != abstraction_pkg : <EOL> info_exc = ModuleRegistryException ( * descriptor_info ) <EOL> debug . critical ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( info_exc . _module_name , <EOL> info_exc . _package_name ) ) <EOL> package . add_abs_upgrade ( descriptor , name , namespace , str ( version ) ) <EOL> self . auto_add_ports ( descriptor . module ) <EOL> return descriptor <EOL> def has_input_port ( self , module , portName ) : <EOL> descriptor = self . get_descriptor ( module ) <EOL> return ( portName , '<STR_LIT:input>' ) in descriptor . port_specs <EOL> def has_output_port ( self , module , portName ) : <EOL> descriptor = self . get_descriptor ( module ) <EOL> return ( portName , '<STR_LIT>' ) in descriptor . port_specs <EOL> def create_port_spec ( self , name , type , signature = None , sigstring = None , <EOL> optional = False , sort_key = - <NUM_LIT:1> , labels = None , <EOL> defaults = None , values = None , entry_types = None , <EOL> docstring = None , shape = None , <EOL> min_conns = <NUM_LIT:0> , max_conns = - <NUM_LIT:1> , depth = <NUM_LIT:0> ) : <EOL> if signature is None and sigstring is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> spec_id = self . idScope . getNewId ( PortSpec . vtType ) <EOL> if defaults is not None or values is not None : <EOL> parse_port_spec_string = vistrails . core . modules . utils . parse_port_spec_string <EOL> if sigstring is not None : <EOL> sigstrings = parse_port_spec_string ( sigstring ) <EOL> sig_cls_list = [ None , ] * len ( sigstrings ) <EOL> else : <EOL> if isinstance ( signature , collections . Sequence ) : <EOL> sig_cls_list = signature <EOL> sigstrings = [ None , ] * len ( sig_cls_list ) <EOL> else : <EOL> sig_cls_list = [ signature ] <EOL> sigstrings = [ None , ] <EOL> if defaults is not None : <EOL> new_defaults = [ ] <EOL> if isinstance ( defaults , basestring ) : <EOL> defaults = literal_eval ( defaults ) <EOL> if not isinstance ( defaults , list ) : <EOL> raise ValueError ( '<STR_LIT>' % <EOL> name ) <EOL> for i , default_val in enumerate ( defaults ) : <EOL> if default_val is not None : <EOL> default_conv = self . convert_port_val ( default_val , <EOL> sigstrings [ i ] , <EOL> sig_cls_list [ i ] ) <EOL> if default_conv is not None : <EOL> new_defaults . append ( default_conv ) <EOL> else : <EOL> new_defaults . append ( None ) <EOL> else : <EOL> new_defaults . append ( None ) <EOL> defaults = new_defaults <EOL> if values is not None : <EOL> new_values = [ ] <EOL> if isinstance ( values , basestring ) : <EOL> values = literal_eval ( values ) <EOL> if not isinstance ( values , list ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % name ) <EOL> for i , values_list in enumerate ( values ) : <EOL> if isinstance ( values_list , basestring ) : <EOL> values_list = literal_eval ( values_list ) <EOL> if values_list is not None : <EOL> if not isinstance ( values_list , list ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % name ) <EOL> new_values_list = [ ] <EOL> for val in values_list : <EOL> if val is not None : <EOL> val_conv = self . convert_port_val ( val , <EOL> sigstrings [ i ] , <EOL> sig_cls_list [ i ] ) <EOL> if val_conv is not None : <EOL> new_values_list . append ( val_conv ) <EOL> new_values . append ( new_values_list ) <EOL> else : <EOL> new_values . append ( None ) <EOL> values = new_values <EOL> spec = PortSpec ( id = spec_id , <EOL> name = name , <EOL> type = type , <EOL> signature = signature , <EOL> sigstring = sigstring , <EOL> optional = optional , <EOL> sort_key = sort_key , <EOL> labels = labels , <EOL> defaults = defaults , <EOL> values = values , <EOL> entry_types = entry_types , <EOL> docstring = docstring , <EOL> shape = shape , <EOL> min_conns = min_conns , <EOL> max_conns = max_conns , <EOL> depth = depth ) <EOL> for psi in spec . port_spec_items : <EOL> psi . id = self . idScope . getNewId ( PortSpecItem . vtType ) <EOL> return spec <EOL> def add_port_spec ( self , descriptor , spec ) : <EOL> try : <EOL> spec . descriptors ( ) <EOL> except ModuleRegistryException , e : <EOL> raise InvalidPortSpec ( descriptor , spec . name , spec . type , e ) <EOL> descriptor . add_port_spec ( spec ) <EOL> if spec . type == '<STR_LIT:input>' : <EOL> self . signals . emit_new_input_port ( descriptor . identifier , <EOL> descriptor . name , spec . name , spec ) <EOL> elif spec . type == '<STR_LIT>' : <EOL> self . signals . emit_new_output_port ( descriptor . identifier , <EOL> descriptor . name , spec . name , spec ) <EOL> def get_port_spec_from_descriptor ( self , desc , port_name , port_type ) : <EOL> for d in self . get_module_hierarchy ( desc ) : <EOL> if d . has_port_spec ( port_name , port_type ) : <EOL> return d . get_port_spec ( port_name , port_type ) <EOL> raise MissingPort ( desc , port_name , port_type ) <EOL> def get_port_spec ( self , package , module_name , namespace , <EOL> port_name , port_type ) : <EOL> desc = self . get_descriptor_by_name ( package , module_name , namespace ) <EOL> return self . get_port_spec_from_descriptor ( desc , port_name , <EOL> port_type ) <EOL> def has_port_spec_from_descriptor ( self , desc , port_name , port_type ) : <EOL> for d in self . get_module_hierarchy ( desc ) : <EOL> if d . has_port_spec ( port_name , port_type ) : <EOL> return True <EOL> return False <EOL> def has_port_spec ( self , package , module_name , namespace , <EOL> port_name , port_type ) : <EOL> desc = self . get_descriptor_by_name ( package , module_name , namespace ) <EOL> return self . has_port_spec_from_descriptor ( desc , port_name , <EOL> port_type ) <EOL> def add_port ( self , descriptor , port_name , port_type , port_sig = None , <EOL> port_sigstring = None , optional = False , sort_key = - <NUM_LIT:1> , <EOL> labels = None , defaults = None , values = None , entry_types = None , <EOL> docstring = None , shape = None , min_conns = <NUM_LIT:0> , max_conns = - <NUM_LIT:1> , <EOL> depth = <NUM_LIT:0> ) : <EOL> spec = self . create_port_spec ( port_name , port_type , port_sig , <EOL> port_sigstring , optional , sort_key , <EOL> labels , defaults , values , entry_types , <EOL> docstring , shape , <EOL> min_conns , max_conns , depth ) <EOL> self . add_port_spec ( descriptor , spec ) <EOL> def add_input_port ( self , module , portName , portSignature , optional = False , <EOL> sort_key = - <NUM_LIT:1> , labels = None , defaults = None , <EOL> values = None , entry_types = None , docstring = None , <EOL> shape = None , min_conns = <NUM_LIT:0> , max_conns = - <NUM_LIT:1> , depth = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> descriptor = self . get_descriptor ( module ) <EOL> if isinstance ( portSignature , basestring ) : <EOL> self . add_port ( descriptor , portName , '<STR_LIT:input>' , None , portSignature , <EOL> optional , sort_key , labels , defaults , values , <EOL> entry_types , docstring , shape , min_conns , max_conns , <EOL> depth ) <EOL> else : <EOL> self . add_port ( descriptor , portName , '<STR_LIT:input>' , portSignature , None , <EOL> optional , sort_key , labels , defaults , values , <EOL> entry_types , docstring , shape , min_conns , max_conns , <EOL> depth ) <EOL> def add_output_port ( self , module , portName , portSignature , optional = False , <EOL> sort_key = - <NUM_LIT:1> , docstring = None , shape = None , <EOL> min_conns = <NUM_LIT:0> , max_conns = - <NUM_LIT:1> , depth = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> descriptor = self . get_descriptor ( module ) <EOL> if isinstance ( portSignature , basestring ) : <EOL> self . add_port ( descriptor , portName , '<STR_LIT>' , None , portSignature , <EOL> optional , sort_key , None , None , None , None , <EOL> docstring , shape , min_conns , max_conns , depth ) <EOL> else : <EOL> self . add_port ( descriptor , portName , '<STR_LIT>' , portSignature , None , <EOL> optional , sort_key , None , None , None , None , <EOL> docstring , shape , min_conns , max_conns , depth ) <EOL> def create_package ( self , codepath , load_configuration = True , prefix = None ) : <EOL> package_id = self . idScope . getNewId ( Package . vtType ) <EOL> package = Package ( id = package_id , <EOL> codepath = codepath , <EOL> load_configuration = load_configuration ) <EOL> if prefix is not None : <EOL> package . prefix = prefix <EOL> return package <EOL> def initialize_package ( self , package ) : <EOL> if package . initialized ( ) : <EOL> return <EOL> debug . splashMessage ( "<STR_LIT>" + package . codepath + "<STR_LIT>" ) <EOL> debug . log ( "<STR_LIT>" + package . codepath ) <EOL> if ( package . identifier , package . version ) not in self . package_versions : <EOL> self . add_package ( package ) <EOL> self . set_current_package ( package ) <EOL> try : <EOL> package . initialize ( ) <EOL> if hasattr ( package . module , '<STR_LIT>' ) : <EOL> modules = package . module . _modules <EOL> if isinstance ( modules , dict ) : <EOL> module_list = [ ] <EOL> for namespace , m_list in modules . iteritems ( ) : <EOL> for module in m_list : <EOL> m_dict = { '<STR_LIT>' : namespace } <EOL> if isinstance ( module , tuple ) : <EOL> m_dict . update ( module [ <NUM_LIT:1> ] ) <EOL> module_list . append ( ( module [ <NUM_LIT:0> ] , m_dict ) ) <EOL> elif '<STR_LIT>' in module . __dict__ : <EOL> kwargs = module . _settings . _asdict ( ) <EOL> kwargs . update ( m_dict ) <EOL> module . _settings = ModuleSettings ( ** kwargs ) <EOL> module_list . append ( module ) <EOL> else : <EOL> module_list . append ( ( module , m_dict ) ) <EOL> else : <EOL> module_list = modules <EOL> modules = _toposort_modules ( module_list ) <EOL> for module in modules : <EOL> self . auto_add_module ( module ) <EOL> added_descriptors = set ( ) <EOL> for descriptor in package . descriptor_list : <EOL> if hasattr ( descriptor , '<STR_LIT>' ) : <EOL> self . auto_add_ports ( descriptor . module ) <EOL> added_descriptors . add ( descriptor ) <EOL> if hasattr ( package . module , '<STR_LIT>' ) : <EOL> subworkflows = _toposort_abstractions ( package , <EOL> package . module . _subworkflows ) <EOL> for subworkflow in subworkflows : <EOL> self . auto_add_subworkflow ( subworkflow ) <EOL> for descriptor in package . descriptor_list : <EOL> if descriptor not in added_descriptors : <EOL> if hasattr ( descriptor , '<STR_LIT>' ) : <EOL> self . auto_add_ports ( descriptor . module ) <EOL> added_descriptors . add ( descriptor ) <EOL> except MissingRequirement : <EOL> raise <EOL> except Exception , e : <EOL> raise package . InitializationFailed ( package , <EOL> [ traceback . format_exc ( ) ] ) <EOL> finally : <EOL> self . set_current_package ( None ) <EOL> debug . splashMessage ( "<STR_LIT>" + package . codepath + '<STR_LIT>' ) <EOL> package . _initialized = True <EOL> def delete_module ( self , identifier , module_name , namespace = None ) : <EOL> """<STR_LIT>""" <EOL> descriptor = self . get_descriptor_by_name ( identifier , module_name , <EOL> namespace ) <EOL> assert len ( descriptor . children ) == <NUM_LIT:0> <EOL> converter_desc = self . get_descriptor ( <EOL> vistrails . core . modules . vistrails_module . Converter ) <EOL> if self . is_descriptor_subclass ( descriptor , converter_desc ) : <EOL> self . _conversions = dict ( ) <EOL> self . _converters . remove ( descriptor ) <EOL> self . signals . emit_deleted_module ( descriptor ) <EOL> if self . is_abstraction ( descriptor ) : <EOL> self . signals . emit_deleted_abstraction ( descriptor ) <EOL> package = self . packages [ descriptor . identifier ] <EOL> self . delete_descriptor ( descriptor , package ) <EOL> if descriptor . module is not None : <EOL> del self . _module_key_map [ descriptor . module ] <EOL> def remove_package ( self , package ) : <EOL> """<STR_LIT>""" <EOL> graph = Graph ( ) <EOL> if package . identifier not in self . packages : <EOL> raise MissingPackage ( package . identifier ) <EOL> package = self . packages [ package . identifier ] <EOL> for descriptor in package . descriptor_list : <EOL> graph . add_vertex ( descriptor . sigstring ) <EOL> for descriptor in package . descriptor_list : <EOL> base_id = descriptor . base_descriptor_id <EOL> if base_id in package . descriptors_by_id : <EOL> base_descriptor = package . descriptors_by_id [ descriptor . base_descriptor_id ] <EOL> graph . add_edge ( descriptor . sigstring , base_descriptor . sigstring ) <EOL> top_sort = graph . vertices_topological_sort ( ) <EOL> for sigstring in top_sort : <EOL> self . delete_module ( <EOL> * vistrails . core . modules . utils . parse_descriptor_string ( sigstring ) ) <EOL> for key , version_dict in package . _abs_pkg_upgrades . iteritems ( ) : <EOL> for version , descriptor in version_dict . iteritems ( ) : <EOL> self . delete_module ( descriptor . identifier , descriptor . name , <EOL> descriptor . namespace ) <EOL> package . _abs_pkg_upgrades . clear ( ) <EOL> package . unload ( ) <EOL> self . delete_package ( package ) <EOL> self . signals . emit_deleted_package ( package ) <EOL> def delete_input_port ( self , descriptor , port_name ) : <EOL> """<STR_LIT>""" <EOL> descriptor . delete_input_port ( port_name ) <EOL> def delete_output_port ( self , descriptor , port_name ) : <EOL> """<STR_LIT>""" <EOL> descriptor . delete_output_port ( port_name ) <EOL> def source_ports_from_descriptor ( self , descriptor , sorted = True ) : <EOL> ports = [ p [ <NUM_LIT:1> ] for p in self . module_ports ( '<STR_LIT>' , descriptor ) ] <EOL> if sorted : <EOL> ports . sort ( key = lambda x : x . name ) <EOL> return ports <EOL> def destination_ports_from_descriptor ( self , descriptor , sorted = True ) : <EOL> ports = [ p [ <NUM_LIT:1> ] for p in self . module_ports ( '<STR_LIT:input>' , descriptor ) ] <EOL> if sorted : <EOL> ports . sort ( key = lambda x : x . name ) <EOL> return ports <EOL> def all_destination_ports ( self , descriptor , sorted = True ) : <EOL> """<STR_LIT>""" <EOL> getter = self . destination_ports_from_descriptor <EOL> return [ ( desc . name , getter ( desc , sorted ) ) <EOL> for desc in self . get_module_hierarchy ( descriptor ) ] <EOL> def all_source_ports ( self , descriptor , sorted = True ) : <EOL> """<STR_LIT>""" <EOL> getter = self . source_ports_from_descriptor <EOL> return [ ( desc . name , getter ( desc , sorted ) ) <EOL> for desc in self . get_module_hierarchy ( descriptor ) ] <EOL> def get_port_from_all_destinations ( self , descriptor , name ) : <EOL> """<STR_LIT>""" <EOL> all_ports = self . all_destination_ports ( descriptor ) <EOL> for ( klass , port_list ) in all_ports : <EOL> for port in port_list : <EOL> if port . name == name : <EOL> return port <EOL> else : <EOL> return None <EOL> def is_method ( self , port_spec ) : <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> constant_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> return port_spec . type == '<STR_LIT:input>' and all ( self . is_descriptor_subclass ( d , constant_desc ) <EOL> for d in port_spec . descriptors ( ) ) <EOL> is_constant = is_method <EOL> def is_constant_module ( self , module ) : <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> constant_cls = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) . module <EOL> return issubclass ( module , constant_cls ) <EOL> def method_ports ( self , module_descriptor ) : <EOL> """<STR_LIT>""" <EOL> getter = self . module_destination_ports_from_descriptor <EOL> return [ spec for spec in sorted ( getter ( False , module_descriptor ) , <EOL> key = lambda x : x . name ) <EOL> if self . is_method ( spec ) ] <EOL> def port_and_port_spec_match ( self , port , port_spec ) : <EOL> """<STR_LIT>""" <EOL> if port . type in PortSpec . port_type_map : <EOL> port_type = port . type <EOL> elif port . type in PortSpec . port_type_map . inverse : <EOL> port_type = PortSpec . port_type_map . inverse [ port . type ] <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' % str ( port . type ) ) <EOL> if port_type != port_spec . type : <EOL> return False <EOL> if port . name != port_spec . name : <EOL> return False <EOL> if port . sigstring == port_spec . sigstring : <EOL> return True <EOL> return self . are_specs_matched ( port , port_spec ) <EOL> def ports_can_connect ( self , sourceModulePort , destinationModulePort , <EOL> allow_conversion = False , out_converters = None ) : <EOL> """<STR_LIT>""" <EOL> if sourceModulePort . type == destinationModulePort . type : <EOL> return False <EOL> return self . are_specs_matched ( sourceModulePort , destinationModulePort , <EOL> allow_conversion = allow_conversion , <EOL> out_converters = out_converters ) <EOL> def is_port_sub_type ( self , sub , super ) : <EOL> """<STR_LIT>""" <EOL> if sub . type != super . type : <EOL> return False <EOL> if sub . name != super . name : <EOL> return False <EOL> return self . are_specs_matched ( sub , super ) <EOL> def get_converters ( self , sub_descs , super_descs ) : <EOL> key = ( tuple ( sub_descs ) , tuple ( super_descs ) ) <EOL> try : <EOL> return self . _conversions [ key ] <EOL> except KeyError : <EOL> pass <EOL> converters = [ ] <EOL> for converter in self . _converters : <EOL> if converter . module is ( <EOL> vistrails . core . modules . vistrails_module . Converter ) : <EOL> continue <EOL> if converter . module . can_convert ( sub_descs , super_descs ) : <EOL> converters . append ( converter ) <EOL> self . _conversions [ key ] = converters <EOL> return converters <EOL> def is_descriptor_list_subclass ( self , sub_descs , super_descs ) : <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> variant_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> module_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> for ( sub_desc , super_desc ) in izip ( sub_descs , super_descs ) : <EOL> if sub_desc == variant_desc or super_desc == variant_desc : <EOL> continue <EOL> if super_desc == module_desc and sub_desc != module_desc : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> category = VistrailsDeprecation ) <EOL> if not self . is_descriptor_subclass ( sub_desc , super_desc ) : <EOL> return False <EOL> return True <EOL> def are_specs_matched ( self , sub , super , allow_conversion = False , <EOL> out_converters = None ) : <EOL> """<STR_LIT>""" <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> variant_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> list_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> sub_descs = [ ] <EOL> if sub : <EOL> sub_descs = sub . descriptors ( ) <EOL> if sub_descs is None : <EOL> return False <EOL> elif sub_descs == [ variant_desc ] : <EOL> return True <EOL> super_descs = [ ] <EOL> if super : <EOL> super_descs = super . descriptors ( ) <EOL> if super_descs is None : <EOL> return False <EOL> elif super_descs == [ variant_desc ] : <EOL> return True <EOL> elif [ list_desc ] in [ super_descs , sub_descs ] : <EOL> return True <EOL> if ( len ( sub_descs ) == len ( super_descs ) and <EOL> self . is_descriptor_list_subclass ( sub_descs , super_descs ) ) : <EOL> return True <EOL> if allow_conversion : <EOL> converters = self . get_converters ( sub_descs , super_descs ) <EOL> if converters : <EOL> if out_converters is not None : <EOL> out_converters . extend ( converters ) <EOL> return True <EOL> return False <EOL> def get_module_hierarchy ( self , descriptor ) : <EOL> """<STR_LIT>""" <EOL> if descriptor . module is None : <EOL> descriptors = [ descriptor ] <EOL> base_id = descriptor . base_descriptor_id <EOL> while base_id >= <NUM_LIT:0> : <EOL> descriptor = self . descriptors_by_id [ base_id ] <EOL> descriptors . append ( descriptor ) <EOL> base_id = descriptor . base_descriptor_id <EOL> return descriptors <EOL> return [ self . get_descriptor ( klass ) <EOL> for klass in descriptor . module . mro ( ) <EOL> if issubclass ( klass , vistrails . core . modules . vistrails_module . Module ) ] <EOL> def get_descriptor_subclasses ( self , descriptor ) : <EOL> """<STR_LIT>""" <EOL> sub_list = [ ] <EOL> for pkg in self . package_versions . itervalues ( ) : <EOL> for d in pkg . descriptor_list : <EOL> if self . is_descriptor_subclass ( d , descriptor ) : <EOL> sub_list . append ( d ) <EOL> return sub_list <EOL> def get_input_port_spec ( self , module , portName ) : <EOL> """<STR_LIT>""" <EOL> if module . has_port_spec ( portName , '<STR_LIT:input>' ) : <EOL> return module . get_port_spec ( portName , '<STR_LIT:input>' ) <EOL> return None <EOL> def get_output_port_spec ( self , module , portName ) : <EOL> """<STR_LIT>""" <EOL> if module . has_port_spec ( portName , '<STR_LIT>' ) : <EOL> return module . get_port_spec ( portName , '<STR_LIT>' ) <EOL> return None <EOL> @ staticmethod <EOL> def get_subclass_candidates ( module ) : <EOL> """<STR_LIT>""" <EOL> return [ klass <EOL> for klass in module . __bases__ <EOL> if issubclass ( klass , vistrails . core . modules . vistrails_module . Module ) ] <EOL> def set_current_package ( self , package ) : <EOL> """<STR_LIT>""" <EOL> if package is None : <EOL> package = self . _default_package <EOL> self . _current_package = package <EOL> def get_configuration_widget ( self , identifier , name , namespace ) : <EOL> descriptor = self . get_descriptor_by_name ( identifier , name , namespace ) <EOL> package = self . get_package_by_name ( identifier ) <EOL> prefix = None <EOL> if package . prefix is not None and package . codepath is not None : <EOL> prefix = package . prefix + package . codepath <EOL> cls = descriptor . configuration_widget ( ) <EOL> return vistrails . core . modules . utils . load_cls ( cls , prefix ) <EOL> def get_constant_config_params ( self , widget_type = None , widget_use = None ) : <EOL> if widget_type is None : <EOL> widget_type = '<STR_LIT:default>' <EOL> if widget_use is None : <EOL> widget_use = '<STR_LIT:default>' <EOL> return ( widget_type , widget_use ) <EOL> def get_constant_config_widget ( self , descriptor , widget_type = None , <EOL> widget_use = None ) : <EOL> widget_type , widget_use = self . get_constant_config_params ( widget_type , <EOL> widget_use ) <EOL> for desc in self . get_module_hierarchy ( descriptor ) : <EOL> if desc . has_constant_config_widget ( widget_use , widget_type ) : <EOL> return desc . get_constant_config_widget ( widget_use , widget_type ) <EOL> return None <EOL> def get_all_constant_config_widgets ( self , descriptor , widget_use = None ) : <EOL> widget_use = self . get_constant_config_params ( None , widget_use ) [ <NUM_LIT:1> ] <EOL> widgets = { } <EOL> for desc in reversed ( self . get_module_hierarchy ( descriptor ) ) : <EOL> widgets . update ( desc . get_all_constant_config_widgets ( widget_use ) ) <EOL> return widgets . values ( ) <EOL> def set_constant_config_widget ( self , descriptor , widget_class , <EOL> widget_type = None , widget_use = None ) : <EOL> widget_type , widget_use = self . get_constant_config_params ( widget_type , <EOL> widget_use ) <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> constant_desc = self . get_descriptor_by_name ( basic_pkg , '<STR_LIT>' ) <EOL> if not self . is_descriptor_subclass ( descriptor , constant_desc ) : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' % descriptor . sigstring ) <EOL> descriptor . set_constant_config_widget ( widget_class , <EOL> widget_use , widget_type ) <EOL> def is_descriptor_subclass ( self , sub , super ) : <EOL> """<STR_LIT>""" <EOL> if sub . module is not None and super . module is not None : <EOL> return issubclass ( sub . module , super . module ) <EOL> if sub == super : <EOL> return True <EOL> while sub != self . root_descriptor : <EOL> sub = sub . base_descriptor <EOL> if sub == super : <EOL> return True <EOL> return False <EOL> def find_descriptor_subclass ( self , d1 , d2 ) : <EOL> if self . is_descriptor_subclass ( d1 , d2 ) : <EOL> return d1 <EOL> elif self . is_descriptor_subclass ( d2 , d1 ) : <EOL> return d2 <EOL> return None <EOL> def find_descriptor_superclass ( self , d1 , d2 ) : <EOL> """<STR_LIT>""" <EOL> if self . is_descriptor_subclass ( d1 , d2 ) : <EOL> return d2 <EOL> elif self . is_descriptor_subclass ( d2 , d1 ) : <EOL> return d1 <EOL> d1_list = [ d1 ] <EOL> while d1 != self . root_descriptor : <EOL> d1 = d1 . base_descriptor <EOL> d1_list . append ( d1 ) <EOL> d1_idx = - <NUM_LIT:1> <EOL> while self . is_descriptor_subclass ( d2 , d1_list [ d1_idx ] ) : <EOL> d1_idx -= <NUM_LIT:1> <EOL> if d1_idx == - <NUM_LIT:1> : <EOL> return None <EOL> return d1_list [ d1_idx + <NUM_LIT:1> ] <EOL> def is_abstraction ( self , descriptor ) : <EOL> basic_pkg = get_vistrails_basic_pkg_id ( ) <EOL> try : <EOL> abstraction_desc = self . get_descriptor_by_name ( basic_pkg , <EOL> '<STR_LIT>' ) <EOL> except MissingModule : <EOL> return False <EOL> return abstraction_desc != descriptor and self . is_descriptor_subclass ( descriptor , abstraction_desc ) <EOL> def show_module ( self , descriptor ) : <EOL> self . signals . emit_show_module ( descriptor ) <EOL> def hide_module ( self , descriptor ) : <EOL> self . signals . emit_hide_module ( descriptor ) <EOL> def update_module ( self , old_descriptor , new_descriptor ) : <EOL> self . signals . emit_module_updated ( old_descriptor , new_descriptor ) <EOL> def expand_port_spec_string ( self , p_string , cur_package = None , <EOL> old_style = False ) : <EOL> return vistrails . core . modules . utils . expand_port_spec_string ( p_string , cur_package , <EOL> old_style ) <EOL> def get_module_registry ( ) : <EOL> if not registry : <EOL> raise VistrailsInternalError ( "<STR_LIT>" ) <EOL> return registry <EOL> def module_registry_loaded ( ) : <EOL> return registry is not None <EOL> class TestModuleRegistry ( unittest . TestCase ) : <EOL> def test_portspec_construction ( self ) : <EOL> from vistrails . core . modules . basic_modules import Float , Integer <EOL> t1 = PortSpec ( signature = Float ) <EOL> t2 = PortSpec ( signature = [ Float ] ) <EOL> self . assertEquals ( t1 , t2 ) <EOL> t1 = PortSpec ( signature = [ Float , Integer ] ) <EOL> t2 = PortSpec ( signature = [ Integer , Float ] ) <EOL> self . assertNotEquals ( t1 , t2 ) </s>
