<s> from __future__ import division <EOL> import copy <EOL> from itertools import izip <EOL> import os <EOL> import uuid <EOL> import re <EOL> import shutil <EOL> import tempfile <EOL> from vistrails . core . configuration import get_vistrails_configuration <EOL> import vistrails . core . db . action <EOL> import vistrails . core . db . io <EOL> import vistrails . core . db . locator <EOL> from vistrails . core import debug <EOL> from vistrails . core . data_structures . graph import Graph <EOL> from vistrails . core . interpreter . default import get_default_interpreter <EOL> from vistrails . core . vistrail . job import JobMonitor <EOL> from vistrails . core . layout . workflow_layout import WorkflowLayout , Pipeline as LayoutPipeline , Defaults as LayoutDefaults <EOL> from vistrails . core . log . controller import LogController , DummyLogController <EOL> from vistrails . core . log . log import Log <EOL> from vistrails . core . modules . abstraction import identifier as abstraction_pkg , version as abstraction_ver <EOL> from vistrails . core . modules . basic_modules import identifier as basic_pkg <EOL> from vistrails . core . modules . module_descriptor import ModuleDescriptor <EOL> import vistrails . core . modules . module_registry <EOL> from vistrails . core . modules . module_registry import ModuleRegistryException , MissingModuleVersion , MissingModule , MissingPackageVersion , MissingPort , MissingPackage , PortsIncompatible <EOL> from vistrails . core . modules . package import Package <EOL> from vistrails . core . modules . sub_module import new_abstraction , read_vistrail , get_all_abs_namespaces , get_cur_abs_namespace , get_next_abs_annotation_key , save_abstraction , parse_abstraction_name <EOL> from vistrails . core . packagemanager import get_package_manager <EOL> import vistrails . core . packagerepository <EOL> from vistrails . core . thumbnails import ThumbnailCache <EOL> from vistrails . core . upgradeworkflow import UpgradeWorkflowHandler , UpgradeWorkflowError <EOL> from vistrails . core . utils import VistrailsInternalError , PortAlreadyExists , DummyView , InvalidPipeline <EOL> from vistrails . core . system import vistrails_default_file_type , get_vistrails_directory <EOL> from vistrails . core . vistrail . abstraction import Abstraction <EOL> from vistrails . core . vistrail . action import Action <EOL> from vistrails . core . vistrail . annotation import Annotation <EOL> from vistrails . core . vistrail . connection import Connection <EOL> from vistrails . core . vistrail . group import Group <EOL> from vistrails . core . vistrail . location import Location <EOL> from vistrails . core . vistrail . module import Module <EOL> from vistrails . core . vistrail . module_control_param import ModuleControlParam <EOL> from vistrails . core . vistrail . module_function import ModuleFunction <EOL> from vistrails . core . vistrail . module_param import ModuleParam <EOL> from vistrails . core . vistrail . pipeline import Pipeline <EOL> from vistrails . core . vistrail . port import Port <EOL> from vistrails . core . vistrail . port_spec import PortSpec <EOL> from vistrails . core . vistrail . port_spec_item import PortSpecItem <EOL> from vistrails . core . vistrail . vistrail import Vistrail <EOL> from vistrails . core . theme import DefaultCoreTheme <EOL> from vistrails . db import VistrailsDBException <EOL> from vistrails . db . domain import IdScope , DBWorkflowExec <EOL> from vistrails . db . services . io import create_temp_folder , remove_temp_folder <EOL> from vistrails . db . services . io import SaveBundle , open_vt_log_from_db <EOL> from vistrails . db . services . vistrail import getSharedRoot <EOL> from vistrails . core . utils import any <EOL> def vt_action ( description_or_f = None ) : <EOL> def get_f ( f , description = None ) : <EOL> def new_f ( self , * args , ** kwargs ) : <EOL> self . flush_delayed_actions ( ) <EOL> action = f ( self , * args , ** kwargs ) <EOL> if action is not None : <EOL> self . add_new_action ( action , description ) <EOL> self . perform_action ( action ) <EOL> return action <EOL> return new_f <EOL> if isinstance ( description_or_f , basestring ) : <EOL> d = description_or_f <EOL> def wrap ( f ) : <EOL> return get_f ( f , d ) <EOL> return wrap <EOL> else : <EOL> return get_f ( description_or_f ) <EOL> class CompareThumbnailsError ( Exception ) : <EOL> def __init__ ( self , msg , first = None , second = None ) : <EOL> Exception . __init__ ( self , msg ) <EOL> self . _msg = msg <EOL> self . _first = first <EOL> self . _second = second <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _msg , self . _first , self . _second ) <EOL> def dot_escape ( s ) : <EOL> return '<STR_LIT>' % s . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> custom_color_key = '<STR_LIT>' <EOL> custom_color_fmt = re . compile ( r'<STR_LIT>' ) <EOL> def parse_custom_color ( color ) : <EOL> m = custom_color_fmt . match ( color ) <EOL> if not m : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return tuple ( int ( m . group ( i ) ) for i in xrange ( <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> class VistrailController ( object ) : <EOL> def __init__ ( self , vistrail = None , locator = None , abstractions = None , <EOL> thumbnails = None , mashups = None , id_scope = None , <EOL> set_log_on_vt = True , auto_save = True ) : <EOL> self . vistrail = None <EOL> self . locator = None <EOL> self . _auto_save = auto_save <EOL> self . name = '<STR_LIT>' <EOL> self . file_name = '<STR_LIT>' <EOL> self . is_abstraction = False <EOL> self . changed = False <EOL> self . _upgrade_rev_map = None <EOL> self . _cache_pipelines = True <EOL> self . flush_pipeline_cache ( ) <EOL> self . _current_full_graph = None <EOL> self . _current_terse_graph = None <EOL> self . show_upgrades = False <EOL> self . delayed_update = False <EOL> self . num_versions_always_shown = <NUM_LIT:1> <EOL> self . search = None <EOL> self . search_str = None <EOL> self . refine = False <EOL> self . full_tree = False <EOL> self . _asked_packages = set ( ) <EOL> self . _delayed_actions = [ ] <EOL> self . _delayed_paramexps = [ ] <EOL> self . _delayed_mashups = [ ] <EOL> self . _loaded_abstractions = { } <EOL> self . _mashups = [ ] <EOL> self . current_parameter_exploration = None <EOL> self . layoutTheme = DefaultCoreTheme ( ) <EOL> self . set_vistrail ( vistrail , locator , <EOL> abstractions = abstractions , <EOL> thumbnails = thumbnails , <EOL> mashups = mashups , <EOL> id_scope = id_scope , <EOL> set_log_on_vt = set_log_on_vt ) <EOL> def _get_current_base_version ( self ) : <EOL> version = self . current_version <EOL> if self . _upgrade_rev_map : <EOL> return self . _upgrade_rev_map . get ( version , version ) <EOL> else : <EOL> return version <EOL> current_base_version = property ( _get_current_base_version ) <EOL> def flush_pipeline_cache ( self ) : <EOL> self . _pipelines = { <NUM_LIT:0> : Pipeline ( ) } <EOL> def logging_on ( self ) : <EOL> return get_vistrails_configuration ( ) . check ( '<STR_LIT>' ) <EOL> def get_logger ( self ) : <EOL> if self . logging_on ( ) : <EOL> return LogController ( self . log ) <EOL> else : <EOL> return DummyLogController <EOL> def get_locator ( self ) : <EOL> return self . locator <EOL> def set_vistrail ( self , vistrail , locator , abstractions = None , <EOL> thumbnails = None , mashups = None , id_scope = None , <EOL> set_log_on_vt = True ) : <EOL> self . vistrail = vistrail <EOL> self . id_scope = id_scope <EOL> self . current_session = - <NUM_LIT:1> <EOL> self . log = Log ( ) <EOL> self . flush_pipeline_cache ( ) <EOL> self . clear_delayed_actions ( ) <EOL> if self . vistrail is not None : <EOL> self . id_scope = self . vistrail . idScope <EOL> self . current_session = self . vistrail . idScope . getNewId ( "<STR_LIT>" ) <EOL> self . vistrail . current_session = self . current_session <EOL> if set_log_on_vt : <EOL> self . vistrail . log = self . log <EOL> if abstractions is not None : <EOL> self . ensure_abstractions_loaded ( self . vistrail , abstractions ) <EOL> if thumbnails is not None : <EOL> ThumbnailCache . getInstance ( ) . add_entries_from_files ( thumbnails ) <EOL> if mashups is not None : <EOL> self . _mashups = mashups <EOL> job_annotation = vistrail . get_annotation ( '<STR_LIT>' ) <EOL> self . jobMonitor = JobMonitor ( job_annotation and job_annotation . value ) <EOL> else : <EOL> self . jobMonitor = JobMonitor ( ) <EOL> self . current_version = - <NUM_LIT:1> <EOL> self . current_pipeline = Pipeline ( ) <EOL> if self . locator != locator and self . locator is not None : <EOL> self . locator . clean_temporaries ( ) <EOL> self . locator = locator <EOL> if self . locator is not None : <EOL> self . set_file_name ( locator . name ) <EOL> else : <EOL> self . set_file_name ( '<STR_LIT>' ) <EOL> if self . locator and self . locator . has_temporaries ( ) : <EOL> self . set_changed ( True ) <EOL> if self . vistrail is not None : <EOL> self . recompute_terse_graph ( ) <EOL> def close_vistrail ( self , locator ) : <EOL> if not self . vistrail . is_abstraction : <EOL> self . unload_abstractions ( ) <EOL> if locator is not None : <EOL> locator . clean_temporaries ( ) <EOL> locator . close ( ) <EOL> def cleanup ( self ) : <EOL> pass <EOL> def set_id_scope ( self , id_scope ) : <EOL> self . id_scope = id_scope <EOL> def set_changed ( self , changed ) : <EOL> """<STR_LIT>""" <EOL> if changed != self . changed : <EOL> self . changed = changed <EOL> def set_file_name ( self , file_name ) : <EOL> """<STR_LIT>""" <EOL> if file_name is None : <EOL> file_name = '<STR_LIT>' <EOL> if self . file_name != file_name : <EOL> self . file_name = file_name <EOL> self . name = os . path . split ( file_name ) [ <NUM_LIT:1> ] <EOL> if self . name == '<STR_LIT>' : <EOL> self . name = '<STR_LIT>' % vistrails_default_file_type ( ) <EOL> def check_alias ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . current_pipeline . has_alias ( name ) <EOL> def check_vistrail_variable ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if self . vistrail : <EOL> return self . vistrail . has_vistrail_var ( name ) <EOL> return False <EOL> def set_vistrail_variable ( self , name , value = None , set_changed = True ) : <EOL> """<STR_LIT>""" <EOL> if self . vistrail : <EOL> changed = self . vistrail . set_vistrail_var ( name , value ) <EOL> if changed and set_changed : <EOL> self . set_changed ( changed ) <EOL> return changed <EOL> return False <EOL> def get_vistrail_variable ( self , name ) : <EOL> if self . vistrail : <EOL> return self . vistrail . get_vistrail_var ( name ) <EOL> return None <EOL> def has_vistrail_variable_with_uuid ( self , uuid ) : <EOL> if self . vistrail : <EOL> return self . vistrail . db_has_vistrailVariable_with_uuid ( uuid ) <EOL> return None <EOL> def get_vistrail_variable_by_uuid ( self , uuid ) : <EOL> if self . vistrail : <EOL> return self . vistrail . db_get_vistrailVariable_by_uuid ( uuid ) <EOL> return None <EOL> def get_vistrail_variables ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . vistrail : <EOL> return self . vistrail . vistrail_vars <EOL> return [ ] <EOL> def find_vistrail_var_module ( self , var_uuid ) : <EOL> for m in self . current_pipeline . modules . itervalues ( ) : <EOL> if m . is_vistrail_var ( ) and m . get_vistrail_var ( ) == var_uuid : <EOL> return m <EOL> return None <EOL> def get_vistrail_var_pairs ( self , to_module , port_name , var_uuid = None ) : <EOL> connections = self . get_connections_to ( self . current_pipeline , <EOL> [ to_module . id ] , port_name ) <EOL> pipeline = self . current_pipeline <EOL> v_pairs = { } <EOL> for connection in connections : <EOL> m = pipeline . modules [ connection . source . moduleId ] <EOL> if m . is_vistrail_var ( ) : <EOL> if var_uuid is None or m . get_vistrail_var ( ) == var_uuid : <EOL> if m . id not in v_pairs : <EOL> v_pairs [ m . id ] = [ ] <EOL> v_pairs [ m . id ] . append ( connection ) <EOL> return v_pairs <EOL> def create_vistrail_var_module ( self , descriptor , x , y , var_uuid ) : <EOL> m = self . create_module_from_descriptor ( descriptor , x , y ) <EOL> a = Annotation ( id = self . id_scope . getNewId ( Annotation . vtType ) , <EOL> key = Module . VISTRAIL_VAR_ANNOTATION , <EOL> value = var_uuid ) <EOL> m . add_annotation ( a ) <EOL> f = self . create_function ( m , "<STR_LIT:value>" ) <EOL> m . add_function ( f ) <EOL> return m <EOL> def check_vistrail_var_connected ( self , v_module , to_module , to_port ) : <EOL> connections = self . get_connections_to ( self . current_pipeline , <EOL> [ to_module . id ] , to_port ) <EOL> for connection in connections : <EOL> if connection . source . moduleId == v_module . id : <EOL> return True <EOL> return False <EOL> def check_has_vistrail_var_connected ( self , to_module , port_name ) : <EOL> connections = self . get_connections_to ( self . current_pipeline , <EOL> [ to_module . id ] , port_name ) <EOL> pipeline = self . current_pipeline <EOL> for connection in connections : <EOL> if pipeline . modules [ connection . source . moduleId ] . is_vistrail_var ( ) : <EOL> return True <EOL> return False <EOL> @ vt_action ( "<STR_LIT>" ) <EOL> def connect_vistrail_var_action ( self , connection , module = None ) : <EOL> ops = [ ] <EOL> if module is not None : <EOL> ops . append ( ( '<STR_LIT>' , module ) ) <EOL> ops . append ( ( '<STR_LIT>' , connection ) ) <EOL> action = vistrails . core . db . action . create_action ( ops ) <EOL> return action <EOL> def connect_vistrail_var ( self , descriptor , var_uuid , <EOL> to_module , to_port , x , y ) : <EOL> ops = [ ] <EOL> new_module = None <EOL> v_module = self . find_vistrail_var_module ( var_uuid ) <EOL> if v_module is None : <EOL> v_module = self . create_vistrail_var_module ( descriptor , x , y , <EOL> var_uuid ) <EOL> new_module = v_module <EOL> elif self . check_vistrail_var_connected ( v_module , to_module , to_port ) : <EOL> return ( None , None ) <EOL> c = self . create_connection ( v_module , "<STR_LIT:value>" , to_module , to_port ) <EOL> action = self . connect_vistrail_var_action ( c , new_module ) <EOL> return ( c , new_module ) <EOL> def delete_modules_and_connections ( self , modules , connections ) : <EOL> ops = [ ] <EOL> ops . extend ( [ ( '<STR_LIT>' , c ) for c in connections ] ) <EOL> ops . extend ( [ ( '<STR_LIT>' , m ) for m in modules ] ) <EOL> if len ( ops ) > <NUM_LIT:0> : <EOL> action = vistrails . core . db . action . create_action ( ops ) <EOL> return action <EOL> return None <EOL> @ vt_action ( "<STR_LIT>" ) <EOL> def disconnect_vistrail_vars ( self , modules , connections ) : <EOL> return self . delete_modules_and_connections ( modules , connections ) <EOL> def get_disconnect_vistrail_vars ( self , to_module , to_port , <EOL> to_var_uuid = None ) : <EOL> to_delete_modules = [ ] <EOL> to_delete_conns = [ ] <EOL> v_pairs = self . get_vistrail_var_pairs ( to_module , to_port , to_var_uuid ) <EOL> for ( v_module_id , v_conns ) in v_pairs . iteritems ( ) : <EOL> to_delete_conns . extend ( v_conns ) <EOL> total_conns = self . get_connections_from ( self . current_pipeline , <EOL> [ v_module_id ] ) <EOL> if ( len ( total_conns ) - len ( v_conns ) ) < <NUM_LIT:1> : <EOL> to_delete_modules . append ( <EOL> self . current_pipeline . modules [ v_module_id ] ) <EOL> return ( to_delete_modules , to_delete_conns ) <EOL> def get_connected_vistrail_vars ( self , module_ids , to_delete = False ) : <EOL> """<STR_LIT>""" <EOL> vv_modules = { } <EOL> connections = self . get_connections_to ( self . current_pipeline , <EOL> module_ids ) <EOL> pipeline = self . current_pipeline <EOL> final_connections = [ ] <EOL> for connection in connections : <EOL> m = pipeline . modules [ connection . source . moduleId ] <EOL> if m . is_vistrail_var ( ) : <EOL> if m . id not in vv_modules : <EOL> vv_modules [ m . id ] = [ ] <EOL> vv_modules [ m . id ] . append ( connection ) <EOL> final_connections . append ( connection . id ) <EOL> if to_delete : <EOL> for module_id , connections in vv_modules . items ( ) : <EOL> total_conns = self . get_connections_from ( self . current_pipeline , <EOL> [ module_id ] ) <EOL> if len ( total_conns ) != len ( connections ) : <EOL> del vv_modules [ module_id ] <EOL> return vv_modules . keys ( ) , final_connections <EOL> def getParameterExplorationById ( self , id ) : <EOL> """<STR_LIT>""" <EOL> if self . vistrail and self . vistrail . db_has_parameter_exploration_with_id ( id ) : <EOL> return self . vistrail . db_get_parameter_exploration_by_id ( id ) <EOL> return None <EOL> def getLatestParameterExplorationByVersion ( self , id ) : <EOL> """<STR_LIT>""" <EOL> for i in xrange ( len ( self . vistrail . db_parameter_explorations ) ) : <EOL> pe = self . vistrail . db_parameter_explorations [ i ] <EOL> if pe . action_id == id and not pe . name : <EOL> return pe <EOL> return None <EOL> def invalidate_version_tree ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def has_move_actions ( self ) : <EOL> return False <EOL> def flush_move_actions ( self ) : <EOL> return False <EOL> def migrate_tags ( self , from_version , to_version , vistrail = None ) : <EOL> if vistrail is None : <EOL> vistrail = self . vistrail <EOL> tag = vistrail . get_tag ( from_version ) <EOL> if tag : <EOL> vistrail . set_tag ( from_version , "<STR_LIT>" ) <EOL> vistrail . set_tag ( to_version , tag ) <EOL> notes = vistrail . get_notes ( from_version ) <EOL> if notes : <EOL> vistrail . set_notes ( from_version , "<STR_LIT>" ) <EOL> vistrail . set_notes ( to_version , notes ) <EOL> def flush_delayed_actions ( self , delay_update = False ) : <EOL> start_version = self . current_version <EOL> desc_key = Action . ANNOTATION_DESCRIPTION <EOL> added_upgrade = False <EOL> should_migrate_tags = get_vistrails_configuration ( ) . check ( "<STR_LIT>" ) <EOL> for action in self . _delayed_actions : <EOL> self . vistrail . add_action ( action , start_version , <EOL> self . current_session ) <EOL> if ( action . has_annotation_with_key ( desc_key ) and <EOL> action . get_annotation_by_key ( desc_key ) . value == '<STR_LIT>' ) : <EOL> self . vistrail . set_upgrade ( start_version , str ( action . id ) ) <EOL> if should_migrate_tags : <EOL> self . migrate_tags ( start_version , action . id ) <EOL> self . current_version = action . id <EOL> start_version = action . id <EOL> added_upgrade = True <EOL> for pe in self . _delayed_paramexps : <EOL> pe . action_id = self . current_version <EOL> self . vistrail . db_add_parameter_exploration ( pe ) <EOL> for mashup in self . _delayed_mashups : <EOL> mashup . vtVersion = self . current_version <EOL> for action in mashup . actions : <EOL> action . mashup . version = self . current_version <EOL> self . _mashups . append ( mashup ) <EOL> added_moves = self . flush_move_actions ( ) <EOL> self . clear_delayed_actions ( ) <EOL> if added_upgrade or added_moves : <EOL> if delay_update : <EOL> self . delayed_update = True <EOL> else : <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False ) <EOL> def clear_delayed_actions ( self ) : <EOL> self . _delayed_actions = [ ] <EOL> self . _delayed_paramexps = [ ] <EOL> self . _delayed_mashups = [ ] <EOL> def perform_action ( self , action , do_validate = True , raise_exception = False ) : <EOL> """<STR_LIT>""" <EOL> if action is not None : <EOL> self . current_pipeline . perform_action ( action ) <EOL> self . current_version = action . db_id <EOL> if do_validate : <EOL> self . validate ( self . current_pipeline , raise_exception ) <EOL> return action . db_id <EOL> return None <EOL> def add_new_action ( self , action , description = None ) : <EOL> """<STR_LIT>""" <EOL> if action is not None : <EOL> if self . current_version == - <NUM_LIT:1> : <EOL> self . change_selected_version ( <NUM_LIT:0> ) <EOL> self . vistrail . add_action ( action , self . current_version , <EOL> self . current_session ) <EOL> if description is not None : <EOL> self . vistrail . change_description ( description , action . id ) <EOL> self . current_version = action . db_id <EOL> self . set_changed ( True ) <EOL> self . recompute_terse_graph ( ) <EOL> def create_module_from_descriptor ( self , * args , ** kwargs ) : <EOL> return self . create_module_from_descriptor_static ( self . id_scope , <EOL> * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_module_from_descriptor_static ( id_scope , descriptor , <EOL> x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> , <EOL> internal_version = - <NUM_LIT:1> , <EOL> use_desc_pkg_version = False ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> if not use_desc_pkg_version : <EOL> package = reg . get_package_by_name ( descriptor . identifier ) <EOL> pkg_version = package . version <EOL> else : <EOL> pkg_version = descriptor . package_version <EOL> loc_id = id_scope . getNewId ( Location . vtType ) <EOL> location = Location ( id = loc_id , <EOL> x = x , <EOL> y = y , <EOL> ) <EOL> if internal_version > - <NUM_LIT:1> : <EOL> if descriptor . identifier == abstraction_pkg : <EOL> namespace = get_cur_abs_namespace ( descriptor . module . vistrail ) <EOL> else : <EOL> namespace = descriptor . namespace <EOL> abstraction_id = id_scope . getNewId ( Abstraction . vtType ) <EOL> module = Abstraction ( id = abstraction_id , <EOL> name = descriptor . name , <EOL> package = descriptor . identifier , <EOL> namespace = namespace , <EOL> version = pkg_version , <EOL> location = location , <EOL> internal_version = internal_version , <EOL> ) <EOL> elif descriptor . identifier == basic_pkg and descriptor . name == '<STR_LIT>' : <EOL> group_id = id_scope . getNewId ( Group . vtType ) <EOL> module = Group ( id = group_id , <EOL> name = descriptor . name , <EOL> package = descriptor . identifier , <EOL> namespace = descriptor . namespace , <EOL> version = pkg_version , <EOL> location = location , <EOL> ) <EOL> else : <EOL> module_id = id_scope . getNewId ( Module . vtType ) <EOL> module = Module ( id = module_id , <EOL> name = descriptor . name , <EOL> package = descriptor . identifier , <EOL> namespace = descriptor . namespace , <EOL> version = pkg_version , <EOL> location = location , <EOL> ) <EOL> module . is_valid = True <EOL> return module <EOL> def create_module ( self , * args , ** kwargs ) : <EOL> return self . create_module_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_module_static ( id_scope , identifier , name , namespace = '<STR_LIT>' , <EOL> x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> , internal_version = - <NUM_LIT:1> ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> d = reg . get_descriptor_by_name ( identifier , name , namespace ) <EOL> static_call = VistrailController . create_module_from_descriptor_static <EOL> return static_call ( id_scope , d , x , y , internal_version ) <EOL> def create_old_module ( self , * args , ** kwargs ) : <EOL> return self . create_old_module_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_old_module_static ( id_scope , identifier , name , namespace = '<STR_LIT>' , <EOL> version = '<STR_LIT>' , x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> , internal_version = - <NUM_LIT:1> ) : <EOL> dummy_d = ModuleDescriptor ( name = name , <EOL> package = identifier , <EOL> namespace = namespace , <EOL> package_version = version , <EOL> internal_version = internal_version ) <EOL> return VistrailController . create_module_from_descriptor_static ( <EOL> id_scope , dummy_d , x , y , internal_version , True ) <EOL> def create_connection_from_ids ( self , output_id , output_port_spec , <EOL> input_id , input_port_spec ) : <EOL> output_module = self . current_pipeline . modules [ output_id ] <EOL> input_module = self . current_pipeline . modules [ input_id ] <EOL> return self . create_connection ( output_module , output_port_spec , <EOL> input_module , input_port_spec ) <EOL> def create_connection ( self , * args , ** kwargs ) : <EOL> return self . create_connection_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_connection_static ( id_scope , output_module , output_port_spec , <EOL> input_module , input_port_spec ) : <EOL> if isinstance ( output_port_spec , basestring ) : <EOL> output_port_spec = output_module . get_port_spec ( output_port_spec , '<STR_LIT>' ) <EOL> if isinstance ( input_port_spec , basestring ) : <EOL> input_port_spec = input_module . get_port_spec ( input_port_spec , '<STR_LIT:input>' ) <EOL> if output_port_spec is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" ) <EOL> if input_port_spec is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" ) <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> if not reg . ports_can_connect ( output_port_spec , input_port_spec ) : <EOL> raise PortsIncompatible ( output_module . package , <EOL> output_module . name , <EOL> output_module . namespace , <EOL> output_port_spec . name , <EOL> input_module . package , <EOL> input_module . name , <EOL> input_module . namespace , <EOL> input_port_spec . name ) <EOL> output_port_id = id_scope . getNewId ( Port . vtType ) <EOL> output_port = Port ( id = output_port_id , <EOL> spec = output_port_spec , <EOL> moduleId = output_module . id , <EOL> moduleName = output_module . name ) <EOL> input_port_id = id_scope . getNewId ( Port . vtType ) <EOL> input_port = Port ( id = input_port_id , <EOL> spec = input_port_spec , <EOL> moduleId = input_module . id , <EOL> moduleName = input_module . name ) <EOL> conn_id = id_scope . getNewId ( Connection . vtType ) <EOL> connection = Connection ( id = conn_id , <EOL> ports = [ input_port , output_port ] ) <EOL> return connection <EOL> def create_param ( self , * args , ** kwargs ) : <EOL> return self . create_param_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_param_static ( id_scope , port_spec , pos , value , alias = '<STR_LIT>' , <EOL> query_method = None ) : <EOL> param_id = id_scope . getNewId ( ModuleParam . vtType ) <EOL> descriptor = port_spec . descriptors ( ) [ pos ] <EOL> param_type = descriptor . sigstring <EOL> new_param = ModuleParam ( id = param_id , <EOL> pos = pos , <EOL> name = '<STR_LIT>' , <EOL> alias = alias , <EOL> val = value , <EOL> type = param_type , <EOL> ) <EOL> new_param . queryMethod = query_method <EOL> return new_param <EOL> def create_params ( self , * args , ** kwargs ) : <EOL> return self . create_params_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_params_static ( id_scope , port_spec , values , aliases = [ ] , <EOL> query_methods = [ ] ) : <EOL> params = [ ] <EOL> for i in xrange ( len ( port_spec . descriptors ( ) ) ) : <EOL> if i < len ( values ) and values [ i ] is not None : <EOL> value = str ( values [ i ] ) <EOL> else : <EOL> value = None <EOL> if i < len ( aliases ) : <EOL> alias = str ( aliases [ i ] ) <EOL> else : <EOL> alias = '<STR_LIT>' <EOL> if i < len ( query_methods ) : <EOL> query_method = query_methods [ i ] <EOL> else : <EOL> query_method = None <EOL> param = VistrailController . create_param_static ( id_scope , port_spec , <EOL> i , value , alias , <EOL> query_method ) <EOL> params . append ( param ) <EOL> return params <EOL> def create_function ( self , * args , ** kwargs ) : <EOL> return self . create_function_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_function_static ( id_scope , module , port_spec , <EOL> param_values = [ ] , aliases = [ ] , query_methods = [ ] ) : <EOL> if isinstance ( port_spec , basestring ) : <EOL> port_spec = module . get_port_spec ( port_spec , '<STR_LIT:input>' ) <EOL> if ( len ( param_values ) <= <NUM_LIT:0> and port_spec . defaults is not None and <EOL> any ( d is not None for d in port_spec . defaults ) ) : <EOL> param_values = port_spec . defaults <EOL> f_id = id_scope . getNewId ( ModuleFunction . vtType ) <EOL> new_function = ModuleFunction ( id = f_id , <EOL> pos = module . getNumFunctions ( ) , <EOL> name = port_spec . name , <EOL> ) <EOL> new_function . is_valid = True <EOL> new_params = VistrailController . create_params_static ( id_scope , port_spec , <EOL> param_values , aliases , <EOL> query_methods ) <EOL> new_function . add_parameters ( new_params ) <EOL> return new_function <EOL> def create_functions ( self , * args , ** kwargs ) : <EOL> return self . create_functions_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_functions_static ( id_scope , module , functions ) : <EOL> """<STR_LIT>""" <EOL> static_call = VistrailController . create_function_static <EOL> return [ static_call ( id_scope , module , * f ) for f in functions ] <EOL> def create_port_spec ( self , * args , ** kwargs ) : <EOL> return self . create_port_spec_static ( self . id_scope , * args , ** kwargs ) <EOL> @ staticmethod <EOL> def create_port_spec_static ( id_scope , module , port_type , port_name , <EOL> port_sigstring , port_sort_key = - <NUM_LIT:1> , <EOL> port_depth = <NUM_LIT:0> ) : <EOL> p_id = id_scope . getNewId ( PortSpec . vtType ) <EOL> port_spec = PortSpec ( id = p_id , <EOL> type = port_type , <EOL> name = port_name , <EOL> sigstring = port_sigstring , <EOL> sort_key = port_sort_key , <EOL> depth = port_depth <EOL> ) <EOL> for psi in port_spec . port_spec_items : <EOL> psi . id = id_scope . getNewId ( PortSpecItem . vtType ) <EOL> return port_spec <EOL> def get_module_connection_ids ( self , module_ids , graph ) : <EOL> connection_ids = set ( ) <EOL> for module_id in module_ids : <EOL> for v , id in graph . edges_from ( module_id ) : <EOL> connection_ids . add ( id ) <EOL> for v , id in graph . edges_to ( module_id ) : <EOL> connection_ids . add ( id ) <EOL> return connection_ids <EOL> def delete_module_list_ops ( self , pipeline , module_ids ) : <EOL> graph = pipeline . graph <EOL> connect_ids = self . get_module_connection_ids ( module_ids , graph ) <EOL> ops = [ ] <EOL> for c_id in connect_ids : <EOL> ops . append ( ( '<STR_LIT>' , pipeline . connections [ c_id ] ) ) <EOL> for m_id in module_ids : <EOL> ops . append ( ( '<STR_LIT>' , pipeline . modules [ m_id ] ) ) <EOL> return ops <EOL> def update_port_spec_ops ( self , module , deleted_ports , added_ports ) : <EOL> op_list = [ ] <EOL> deleted_port_info = set ( ) <EOL> changed_port_info = set ( ) <EOL> for p in deleted_ports : <EOL> port_info = ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) <EOL> if module . has_portSpec_with_name ( port_info ) : <EOL> port = module . get_portSpec_by_name ( port_info ) <EOL> deleted_port_info . add ( port_info + ( port . sigstring , ) ) <EOL> for p in added_ports : <EOL> port_info = ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] , p [ <NUM_LIT:2> ] ) <EOL> if port_info in deleted_port_info : <EOL> changed_port_info . add ( port_info [ : <NUM_LIT:2> ] ) <EOL> for c in self . current_pipeline . connections . itervalues ( ) : <EOL> if ( ( c . sourceId == module . id and <EOL> any ( c . source . name == p [ <NUM_LIT:1> ] for p in deleted_ports <EOL> if ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) not in changed_port_info ) ) or <EOL> ( c . destinationId == module . id and <EOL> any ( c . destination . name == p [ <NUM_LIT:1> ] for p in deleted_ports <EOL> if ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) not in changed_port_info ) ) ) : <EOL> op_list . append ( ( '<STR_LIT>' , c ) ) <EOL> for p in deleted_ports : <EOL> if ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) not in changed_port_info : <EOL> for function in module . functions : <EOL> if function . name == p [ <NUM_LIT:1> ] : <EOL> op_list . append ( ( '<STR_LIT>' , function , <EOL> Module . vtType , module . id ) ) <EOL> deleted_port_info = set ( ) <EOL> for p in deleted_ports : <EOL> port_info = ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) <EOL> if module . has_portSpec_with_name ( port_info ) : <EOL> port_spec = module . get_portSpec_by_name ( port_info ) <EOL> op_list . append ( ( '<STR_LIT>' , port_spec , Module . vtType , module . id ) ) <EOL> deleted_port_info . add ( port_info ) <EOL> for p in added_ports : <EOL> if ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) not in deleted_port_info and module . has_port_spec ( p [ <NUM_LIT:1> ] , p [ <NUM_LIT:0> ] ) : <EOL> raise PortAlreadyExists ( module . package , module . name , p [ <NUM_LIT:0> ] , p [ <NUM_LIT:1> ] ) <EOL> port_spec = self . create_port_spec ( module , * p ) <EOL> op_list . append ( ( '<STR_LIT>' , port_spec , Module . vtType , module . id ) ) <EOL> return op_list <EOL> def update_function_ops ( self , module , function_name , param_values = [ ] , <EOL> old_id = - <NUM_LIT:1> L , should_replace = True , aliases = [ ] , <EOL> query_methods = [ ] ) : <EOL> """<STR_LIT>""" <EOL> op_list = [ ] <EOL> port_spec = module . get_port_spec ( function_name , '<STR_LIT:input>' ) <EOL> if should_replace and old_id < <NUM_LIT:0> : <EOL> for old_function in module . functions : <EOL> if old_function . name == function_name : <EOL> old_id = old_function . real_id <EOL> if should_replace and old_id >= <NUM_LIT:0> : <EOL> function = module . function_idx [ old_id ] <EOL> if param_values is None : <EOL> op_list . append ( ( '<STR_LIT>' , function , module . vtType , module . id ) ) <EOL> else : <EOL> for i , new_param_value in enumerate ( param_values ) : <EOL> old_param = function . params [ i ] <EOL> if ( ( len ( aliases ) > i and old_param . alias != aliases [ i ] ) or <EOL> ( len ( query_methods ) > i and <EOL> old_param . queryMethod != query_methods [ i ] ) or <EOL> ( old_param . strValue != new_param_value ) ) : <EOL> if len ( aliases ) > i : <EOL> alias = aliases [ i ] <EOL> else : <EOL> alias = '<STR_LIT>' <EOL> if len ( query_methods ) > i : <EOL> query_method = query_methods [ i ] <EOL> else : <EOL> query_method = None <EOL> new_param = self . create_param ( port_spec , i , <EOL> new_param_value , alias , <EOL> query_method ) <EOL> op_list . append ( ( '<STR_LIT>' , old_param , new_param , <EOL> function . vtType , function . real_id ) ) <EOL> elif param_values is not None : <EOL> if len ( param_values ) < <NUM_LIT:1> : <EOL> new_function = self . create_function ( module , function_name , <EOL> param_values , aliases , <EOL> query_methods ) <EOL> op_list . append ( ( '<STR_LIT>' , new_function , <EOL> module . vtType , module . id ) ) <EOL> else : <EOL> psis = port_spec . port_spec_items <EOL> found = False <EOL> for param_value , psi in izip ( param_values , psis ) : <EOL> if param_value != psi . default : <EOL> found = True <EOL> break <EOL> if found : <EOL> new_function = self . create_function ( module , function_name , <EOL> param_values , aliases , <EOL> query_methods ) <EOL> op_list . append ( ( '<STR_LIT>' , new_function , <EOL> module . vtType , module . id ) ) <EOL> return op_list <EOL> def update_functions_ops ( self , module , functions ) : <EOL> """<STR_LIT>""" <EOL> op_list = [ ] <EOL> for f in functions : <EOL> op_list . extend ( self . update_function_ops ( module , * f ) ) <EOL> return op_list <EOL> def create_updated_parameter ( self , old_param , new_value ) : <EOL> """<STR_LIT>""" <EOL> if old_param . strValue == new_value : <EOL> return None <EOL> param_id = self . id_scope . getNewId ( ModuleParam . vtType ) <EOL> new_param = ModuleParam ( id = param_id , <EOL> pos = old_param . pos , <EOL> name = old_param . name , <EOL> alias = old_param . alias , <EOL> val = new_value , <EOL> type = old_param . typeStr , <EOL> ) <EOL> return new_param <EOL> def update_annotation_ops ( self , module , annotations ) : <EOL> """<STR_LIT>""" <EOL> op_list = [ ] <EOL> for ( key , value ) in annotations : <EOL> a_id = self . id_scope . getNewId ( Annotation . vtType ) <EOL> annotation = Annotation ( id = a_id , <EOL> key = key , <EOL> value = value , <EOL> ) <EOL> if module . has_annotation_with_key ( key ) : <EOL> old_annotation = module . get_annotation_by_key ( key ) <EOL> op_list . append ( ( '<STR_LIT>' , old_annotation , annotation , <EOL> module . vtType , module . id ) ) <EOL> else : <EOL> op_list . append ( ( '<STR_LIT>' , annotation , module . vtType , module . id ) ) <EOL> return op_list <EOL> def check_subworkflow_versions ( self , changed_subworkflow_desc ) : <EOL> if self . current_pipeline is not None : <EOL> self . current_pipeline . check_subworkflow_versions ( ) <EOL> @ vt_action <EOL> def add_module_action ( self , module ) : <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , module ) ] ) <EOL> return action <EOL> def add_module_from_descriptor ( self , descriptor , x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> , <EOL> internal_version = - <NUM_LIT:1> ) : <EOL> module = self . create_module_from_descriptor ( descriptor , x , y , <EOL> internal_version ) <EOL> action = self . add_module_action ( module ) <EOL> return module <EOL> def add_module ( self , identifier , name , namespace = '<STR_LIT>' , x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> , <EOL> internal_version = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> module = self . create_module ( identifier , name , namespace , x , y , <EOL> internal_version ) <EOL> action = self . add_module_action ( module ) <EOL> return module <EOL> def delete_module ( self , module_id ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_module_list ( [ module_id ] ) <EOL> def create_module_list_deletion_action ( self , pipeline , module_ids ) : <EOL> """<STR_LIT>""" <EOL> ops = self . delete_module_list_ops ( pipeline , module_ids ) <EOL> return vistrails . core . db . action . create_action ( ops ) <EOL> @ vt_action <EOL> def delete_module_list ( self , module_ids ) : <EOL> """<STR_LIT>""" <EOL> action = self . create_module_list_deletion_action ( self . current_pipeline , <EOL> module_ids ) <EOL> return action <EOL> def move_modules_ops ( self , move_list ) : <EOL> """<STR_LIT>""" <EOL> operations = [ ] <EOL> for ( id , x , y ) in move_list : <EOL> module = self . current_pipeline . get_module_by_id ( id ) <EOL> if module . location : <EOL> if module . location . x == x and module . location . y == y : <EOL> continue <EOL> loc_id = self . vistrail . idScope . getNewId ( Location . vtType ) <EOL> location = Location ( id = loc_id , x = x , y = y ) <EOL> if module . location and module . location . id != - <NUM_LIT:1> : <EOL> old_location = module . location <EOL> operations . append ( ( '<STR_LIT>' , old_location , location , <EOL> module . vtType , module . id ) ) <EOL> else : <EOL> operations . append ( ( '<STR_LIT>' , location , module . vtType , module . id ) ) <EOL> return operations <EOL> def move_module_list ( self , move_list ) : <EOL> """<STR_LIT>""" <EOL> action_list = self . move_modules_ops ( move_list ) <EOL> action = vistrails . core . db . action . create_action ( action_list ) <EOL> self . add_new_action ( action ) <EOL> return self . perform_action ( action ) <EOL> @ vt_action <EOL> def add_connection_action ( self , connection ) : <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , connection ) ] ) <EOL> return action <EOL> def add_connection ( self , output_id , output_port_spec , <EOL> input_id , input_port_spec ) : <EOL> """<STR_LIT>""" <EOL> connection = self . create_connection_from_ids ( output_id , output_port_spec , <EOL> input_id , input_port_spec ) <EOL> action = self . add_connection_action ( connection ) <EOL> return connection <EOL> def delete_connection ( self , id ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_connection_list ( [ id ] ) <EOL> @ vt_action <EOL> def delete_connection_list ( self , connect_ids ) : <EOL> """<STR_LIT>""" <EOL> action_list = [ ] <EOL> for c_id in connect_ids : <EOL> action_list . append ( ( '<STR_LIT>' , <EOL> self . current_pipeline . connections [ c_id ] ) ) <EOL> action = vistrails . core . db . action . create_action ( action_list ) <EOL> return action <EOL> @ vt_action <EOL> def add_function_action ( self , module , function ) : <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , function , <EOL> module . vtType , module . id ) ] ) <EOL> return action <EOL> def add_function ( self , module , function_name ) : <EOL> function = self . create_function ( module , function_name ) <EOL> action = self . add_function_action ( module , function ) <EOL> return function <EOL> @ vt_action <EOL> def update_function ( self , module , function_name , param_values , old_id = - <NUM_LIT:1> L , <EOL> aliases = [ ] , query_methods = [ ] , should_replace = True ) : <EOL> op_list = self . update_function_ops ( module , function_name , param_values , <EOL> old_id , aliases = aliases , <EOL> query_methods = query_methods , <EOL> should_replace = should_replace ) <EOL> if len ( op_list ) > <NUM_LIT:0> : <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> return action <EOL> return None <EOL> @ vt_action <EOL> def update_parameter ( self , function , old_param_id , new_value ) : <EOL> old_param = function . parameter_idx [ old_param_id ] <EOL> new_param = self . create_updated_parameter ( old_param , new_value ) <EOL> if new_param is None : <EOL> return None <EOL> op = ( '<STR_LIT>' , old_param , new_param , <EOL> function . vtType , function . real_id ) <EOL> action = vistrails . core . db . action . create_action ( [ op ] ) <EOL> return action <EOL> @ vt_action <EOL> def delete_method ( self , function_pos , module_id ) : <EOL> """<STR_LIT>""" <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> function = module . functions [ function_pos ] <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , function , <EOL> module . vtType , module . id ) ] ) <EOL> return action <EOL> @ vt_action <EOL> def delete_function ( self , real_id , module_id ) : <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> function = module . get_function_by_real_id ( real_id ) <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , function , <EOL> module . vtType , module . id ) ] ) <EOL> return action <EOL> @ vt_action <EOL> def delete_annotation ( self , key , module_id ) : <EOL> """<STR_LIT>""" <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> annotation = module . get_annotation_by_key ( key ) <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , annotation , <EOL> module . vtType , module . id ) ] ) <EOL> return action <EOL> @ vt_action <EOL> def add_annotation ( self , pair , module_id ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( pair [ <NUM_LIT:0> ] , basestring ) <EOL> assert isinstance ( pair [ <NUM_LIT:1> ] , basestring ) <EOL> if pair [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' : <EOL> return <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> a_id = self . vistrail . idScope . getNewId ( Annotation . vtType ) <EOL> annotation = Annotation ( id = a_id , <EOL> key = pair [ <NUM_LIT:0> ] , <EOL> value = pair [ <NUM_LIT:1> ] , <EOL> ) <EOL> if module . has_annotation_with_key ( pair [ <NUM_LIT:0> ] ) : <EOL> old_annotation = module . get_annotation_by_key ( pair [ <NUM_LIT:0> ] ) <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , old_annotation , <EOL> annotation , <EOL> module . vtType , module . id ) ] ) <EOL> else : <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , annotation , <EOL> module . vtType , <EOL> module . id ) ] ) <EOL> return action <EOL> @ vt_action <EOL> def delete_control_parameter ( self , name , module_id ) : <EOL> """<STR_LIT>""" <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> control_parameter = module . get_control_parameter_by_name ( name ) <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , control_parameter , <EOL> module . vtType , module . id ) ] ) <EOL> return action <EOL> @ vt_action <EOL> def add_control_parameter ( self , pair , module_id ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( pair [ <NUM_LIT:0> ] , basestring ) <EOL> assert isinstance ( pair [ <NUM_LIT:1> ] , basestring ) <EOL> if pair [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' : <EOL> return <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> a_id = self . vistrail . idScope . getNewId ( ModuleControlParam . vtType ) <EOL> control_parameter = ModuleControlParam ( id = a_id , <EOL> name = pair [ <NUM_LIT:0> ] , <EOL> value = pair [ <NUM_LIT:1> ] , <EOL> ) <EOL> if module . has_control_parameter_with_name ( pair [ <NUM_LIT:0> ] ) : <EOL> old_control_parameter = module . get_control_parameter_by_name ( pair [ <NUM_LIT:0> ] ) <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , old_control_parameter , <EOL> control_parameter , <EOL> module . vtType , module . id ) ] ) <EOL> else : <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , control_parameter , <EOL> module . vtType , <EOL> module . id ) ] ) <EOL> return action <EOL> def update_functions_ops_from_ids ( self , module_id , functions ) : <EOL> module = self . current_pipeline . modules [ module_id ] <EOL> return self . update_functions_ops ( module , functions ) <EOL> def update_port_spec_ops_from_ids ( self , module_id , deleted_ports , <EOL> added_ports ) : <EOL> module = self . current_pipeline . modules [ module_id ] <EOL> return self . update_port_spec_ops ( module , deleted_ports , added_ports ) <EOL> @ vt_action <EOL> def update_functions ( self , module , functions ) : <EOL> op_list = self . update_functions_ops ( module , functions ) <EOL> if len ( op_list ) > <NUM_LIT:0> : <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> else : <EOL> action = None <EOL> return action <EOL> @ vt_action <EOL> def update_ports_and_functions ( self , module_id , deleted_ports , added_ports , <EOL> functions ) : <EOL> op_list = self . update_port_spec_ops_from_ids ( module_id , deleted_ports , <EOL> added_ports ) <EOL> op_list . extend ( self . update_functions_ops_from_ids ( module_id , functions ) ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> return action <EOL> @ vt_action <EOL> def update_ports ( self , module_id , deleted_ports , added_ports ) : <EOL> op_list = self . update_port_spec_ops_from_ids ( module_id , deleted_ports , <EOL> added_ports ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> return action <EOL> def has_module_port ( self , module_id , port_tuple ) : <EOL> """<STR_LIT>""" <EOL> ( type , name ) = port_tuple <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> return len ( [ x for x in module . db_portSpecs <EOL> if x . name == name and x . type == type ] ) > <NUM_LIT:0> <EOL> @ vt_action <EOL> def add_module_port ( self , module_id , port_tuple ) : <EOL> """<STR_LIT>""" <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> p_id = self . vistrail . idScope . getNewId ( PortSpec . vtType ) <EOL> port_spec = PortSpec ( id = p_id , <EOL> type = port_tuple [ <NUM_LIT:0> ] , <EOL> name = port_tuple [ <NUM_LIT:1> ] , <EOL> sigstring = port_tuple [ <NUM_LIT:2> ] , <EOL> ) <EOL> for psi in port_spec . port_spec_items : <EOL> psi . id = self . vistrail . idScope . getNewId ( PortSpecItem . vtType ) <EOL> action = vistrails . core . db . action . create_action ( [ ( '<STR_LIT>' , port_spec , <EOL> module . vtType , module . id ) ] ) <EOL> return action <EOL> @ vt_action <EOL> def delete_module_port ( self , module_id , port_tuple ) : <EOL> """<STR_LIT>""" <EOL> spec_id = - <NUM_LIT:1> <EOL> module = self . current_pipeline . get_module_by_id ( module_id ) <EOL> port_spec = module . get_portSpec_by_name ( ( port_tuple [ <NUM_LIT:1> ] , port_tuple [ <NUM_LIT:0> ] ) ) <EOL> action_list = [ ( '<STR_LIT>' , port_spec , module . vtType , module . id ) ] <EOL> for function in module . functions : <EOL> if function . name == port_spec . name : <EOL> action_list . append ( ( '<STR_LIT>' , function , <EOL> module . vtType , module . id ) ) <EOL> action = vistrails . core . db . action . create_action ( action_list ) <EOL> return action <EOL> def create_group ( self , module_ids , connection_ids ) : <EOL> self . flush_delayed_actions ( ) <EOL> ( group , connections ) = self . build_group ( self . current_pipeline , <EOL> module_ids , connection_ids ) <EOL> op_list = [ ] <EOL> op_list . extend ( ( '<STR_LIT>' , self . current_pipeline . connections [ c_id ] ) <EOL> for c_id in connection_ids ) <EOL> op_list . extend ( ( '<STR_LIT>' , self . current_pipeline . modules [ m_id ] ) <EOL> for m_id in module_ids ) <EOL> op_list . append ( ( '<STR_LIT>' , group ) ) <EOL> op_list . extend ( ( '<STR_LIT>' , c ) for c in connections ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> self . set_action_annotation ( action , Action . ANNOTATION_DESCRIPTION , <EOL> "<STR_LIT>" ) <EOL> self . add_new_action ( action ) <EOL> result = self . perform_action ( action ) <EOL> return group <EOL> def create_abstraction ( self , module_ids , connection_ids , name ) : <EOL> self . flush_delayed_actions ( ) <EOL> ( abstraction , connections ) = self . build_abstraction ( self . current_pipeline , <EOL> module_ids , connection_ids , name ) <EOL> op_list = [ ] <EOL> op_list . extend ( ( '<STR_LIT>' , self . current_pipeline . connections [ c_id ] ) <EOL> for c_id in connection_ids ) <EOL> op_list . extend ( ( '<STR_LIT>' , self . current_pipeline . modules [ m_id ] ) <EOL> for m_id in module_ids ) <EOL> op_list . append ( ( '<STR_LIT>' , abstraction ) ) <EOL> op_list . extend ( ( '<STR_LIT>' , c ) for c in connections ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> self . add_new_action ( action ) <EOL> result = self . perform_action ( action ) <EOL> return abstraction <EOL> def ungroup_set ( self , module_ids ) : <EOL> self . flush_delayed_actions ( ) <EOL> for m_id in module_ids : <EOL> self . create_ungroup ( m_id ) <EOL> def create_ungroup ( self , module_id ) : <EOL> ( modules , connections ) = self . build_ungroup ( self . current_pipeline , module_id ) <EOL> pipeline = self . current_pipeline <EOL> old_conn_ids = self . get_module_connection_ids ( [ module_id ] , <EOL> pipeline . graph ) <EOL> op_list = [ ] <EOL> op_list . extend ( ( '<STR_LIT>' , pipeline . connections [ c_id ] ) <EOL> for c_id in old_conn_ids ) <EOL> op_list . append ( ( '<STR_LIT>' , pipeline . modules [ module_id ] ) ) <EOL> op_list . extend ( ( '<STR_LIT>' , m ) for m in modules ) <EOL> op_list . extend ( ( '<STR_LIT>' , c ) for c in connections ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> self . set_action_annotation ( action , Action . ANNOTATION_DESCRIPTION , <EOL> "<STR_LIT>" ) <EOL> self . add_new_action ( action ) <EOL> res = self . perform_action ( action ) <EOL> self . validate ( self . current_pipeline , False ) <EOL> return res <EOL> def get_connections_to ( self , pipeline , module_ids , port_name = None ) : <EOL> connection_ids = set ( ) <EOL> graph = pipeline . graph <EOL> for m_id in module_ids : <EOL> for _ , id in graph . edges_to ( m_id ) : <EOL> connection_ids . add ( id ) <EOL> return [ pipeline . connections [ c_id ] for c_id in connection_ids <EOL> if port_name is None or pipeline . connections [ c_id ] . destination . name == port_name ] <EOL> def get_connections_from ( self , pipeline , module_ids , port_name = None ) : <EOL> connection_ids = set ( ) <EOL> graph = pipeline . graph <EOL> for m_id in module_ids : <EOL> for _ , id in graph . edges_from ( m_id ) : <EOL> connection_ids . add ( id ) <EOL> return [ pipeline . connections [ c_id ] for c_id in connection_ids <EOL> if port_name is None or pipeline . connections [ c_id ] . source . name == port_name ] <EOL> def get_connections_to_and_from ( self , pipeline , module_ids ) : <EOL> connection_ids = set ( ) <EOL> graph = pipeline . graph <EOL> for m_id in module_ids : <EOL> for _ , id in graph . edges_from ( m_id ) : <EOL> connection_ids . add ( id ) <EOL> for _ , id in graph . edges_to ( m_id ) : <EOL> connection_ids . add ( id ) <EOL> return [ pipeline . connections [ c_id ] for c_id in connection_ids ] <EOL> def get_avg_location ( self , modules ) : <EOL> if len ( modules ) < <NUM_LIT:1> : <EOL> return ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> sum_x = <NUM_LIT:0.0> <EOL> sum_y = <NUM_LIT:0.0> <EOL> for module in modules : <EOL> sum_x += module . location . x <EOL> sum_y += module . location . y <EOL> return ( sum_x / len ( modules ) , sum_y / len ( modules ) ) <EOL> def translate_modules ( self , modules , x , y ) : <EOL> for module in modules : <EOL> module . location . x -= x <EOL> module . location . y -= y <EOL> def center_modules ( self , modules ) : <EOL> ( avg_x , avg_y ) = self . get_avg_location ( modules ) <EOL> self . translate_modules ( modules , avg_x , avg_y ) <EOL> @ staticmethod <EOL> def get_neighbors ( pipeline , module , upstream = True ) : <EOL> neighbors = [ ] <EOL> if upstream : <EOL> get_edges = pipeline . graph . edges_to <EOL> get_port_name = lambda x : pipeline . connections [ x ] . source . name <EOL> else : <EOL> get_edges = pipeline . graph . edges_from <EOL> get_port_name = lambda x : pipeline . connections [ x ] . destination . name <EOL> for ( m_id , conn_id ) in get_edges ( module . id ) : <EOL> neighbors . append ( ( pipeline . modules [ m_id ] , get_port_name ( conn_id ) ) ) <EOL> return neighbors <EOL> @ staticmethod <EOL> def get_upstream_neighbors ( pipeline , module ) : <EOL> return VistrailController . get_neighbors ( pipeline , module , True ) <EOL> @ staticmethod <EOL> def get_downstream_neighbors ( pipeline , module ) : <EOL> return VistrailController . get_neighbors ( pipeline , module , False ) <EOL> def check_subpipeline_port_names ( self ) : <EOL> def create_name ( base_name , names ) : <EOL> if base_name in names : <EOL> port_name = base_name + '<STR_LIT:_>' + str ( names [ base_name ] ) <EOL> names [ base_name ] += <NUM_LIT:1> <EOL> else : <EOL> port_name = base_name <EOL> names [ base_name ] = <NUM_LIT:2> <EOL> return port_name <EOL> in_names = { } <EOL> out_names = { } <EOL> in_cur_names = [ ] <EOL> out_cur_names = [ ] <EOL> in_process_list = [ ] <EOL> out_process_list = [ ] <EOL> pipeline = self . current_pipeline <EOL> for m in pipeline . module_list : <EOL> if m . package == basic_pkg and ( m . name == '<STR_LIT>' or <EOL> m . name == '<STR_LIT>' ) : <EOL> if m . name == '<STR_LIT>' : <EOL> neighbors = self . get_downstream_neighbors ( pipeline , m ) <EOL> names = in_names <EOL> cur_names = in_cur_names <EOL> process_list = in_process_list <EOL> else : <EOL> neighbors = self . get_upstream_neighbors ( pipeline , m ) <EOL> names = out_names <EOL> cur_names = out_cur_names <EOL> process_list = out_process_list <EOL> if len ( neighbors ) < <NUM_LIT:1> : <EOL> continue <EOL> name_function = None <EOL> base_name = None <EOL> for function in m . functions : <EOL> if function . name == '<STR_LIT:name>' : <EOL> name_function = function <EOL> if len ( function . params ) > <NUM_LIT:0> : <EOL> base_name = function . params [ <NUM_LIT:0> ] . strValue <EOL> if base_name is not None : <EOL> cur_names . append ( base_name ) <EOL> else : <EOL> base_name = neighbors [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> if base_name == '<STR_LIT>' : <EOL> base_name = neighbors [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . name <EOL> process_list . append ( ( m , base_name ) ) <EOL> op_list = [ ] <EOL> for ( port_type , names , cur_names , process_list ) in [ ( "<STR_LIT:input>" , in_names , in_cur_names , in_process_list ) , ( "<STR_LIT>" , out_names , out_cur_names , out_process_list ) ] : <EOL> cur_names . sort ( ) <EOL> last_name = None <EOL> for name in cur_names : <EOL> if name == last_name : <EOL> msg = '<STR_LIT>' '<STR_LIT>' % ( name , port_type ) <EOL> raise RuntimeError ( msg ) <EOL> last_name = name <EOL> idx = name . rfind ( "<STR_LIT:_>" ) <EOL> if idx < <NUM_LIT:0> : <EOL> names [ name ] = <NUM_LIT:2> <EOL> else : <EOL> base_name = None <EOL> try : <EOL> val = int ( name [ idx + <NUM_LIT:1> : ] ) <EOL> base_name = name [ : idx ] <EOL> except ValueError : <EOL> pass <EOL> if base_name is not None and base_name in names : <EOL> cur_val = names [ base_name ] <EOL> if val >= cur_val : <EOL> names [ base_name ] = val + <NUM_LIT:1> <EOL> else : <EOL> names [ name ] = <NUM_LIT:2> <EOL> for ( m , base_name ) in process_list : <EOL> port_name = create_name ( base_name , names ) <EOL> ops = self . update_function_ops ( m , '<STR_LIT:name>' , <EOL> [ port_name ] ) <EOL> op_list . extend ( ops ) <EOL> self . flush_delayed_actions ( ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> if action is not None : <EOL> self . add_new_action ( action ) <EOL> self . perform_action ( action ) <EOL> return action <EOL> def create_subpipeline ( self , full_pipeline , module_ids , connection_ids , <EOL> id_remap , id_scope = None ) : <EOL> if not id_scope : <EOL> id_scope = IdScope ( <NUM_LIT:1> , { Group . vtType : Module . vtType , <EOL> Abstraction . vtType : Module . vtType } ) <EOL> old_id_scope = self . id_scope <EOL> self . set_id_scope ( id_scope ) <EOL> connections = [ full_pipeline . connections [ c_id ] <EOL> for c_id in connection_ids ] <EOL> pipeline = Pipeline ( ) <EOL> pipeline . id = None <EOL> in_names = { } <EOL> out_names = { } <EOL> def create_name ( base_name , names ) : <EOL> if base_name in names : <EOL> port_name = base_name + '<STR_LIT:_>' + str ( names [ base_name ] ) <EOL> names [ base_name ] += <NUM_LIT:1> <EOL> else : <EOL> port_name = base_name <EOL> names [ base_name ] = <NUM_LIT:2> <EOL> return port_name <EOL> for m in full_pipeline . module_list : <EOL> if m . id not in module_ids : <EOL> continue <EOL> if m . package == basic_pkg and ( m . name == '<STR_LIT>' or <EOL> m . name == '<STR_LIT>' ) : <EOL> if m . name == '<STR_LIT>' : <EOL> neighbors = self . get_downstream_neighbors ( full_pipeline , m ) <EOL> names = in_names <EOL> else : <EOL> neighbors = self . get_upstream_neighbors ( full_pipeline , m ) <EOL> names = out_names <EOL> if len ( neighbors ) < <NUM_LIT:1> : <EOL> continue <EOL> m = m . do_copy ( True , id_scope , id_remap ) <EOL> name_function = None <EOL> for function in m . functions : <EOL> if function . name == '<STR_LIT:name>' : <EOL> name_function = function <EOL> base_name = function . params [ <NUM_LIT:0> ] . strValue <EOL> if name_function is None : <EOL> base_name = neighbors [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> if base_name == '<STR_LIT>' : <EOL> base_name = neighbors [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . name <EOL> port_name = create_name ( base_name , names ) <EOL> if name_function is not None : <EOL> name_function . params [ <NUM_LIT:0> ] . strValue = port_name <EOL> else : <EOL> functions = [ ( '<STR_LIT:name>' , [ port_name ] ) ] <EOL> for f in self . create_functions ( m , functions ) : <EOL> m . add_function ( f ) <EOL> pipeline . add_module ( m ) <EOL> else : <EOL> pipeline . add_module ( m . do_copy ( True , id_scope , id_remap ) ) <EOL> ( avg_x , avg_y ) = self . get_avg_location ( pipeline . module_list ) <EOL> self . translate_modules ( pipeline . module_list , avg_x , avg_y ) <EOL> module_index = dict ( [ ( m . id , m ) for m in pipeline . module_list ] ) <EOL> def create_port ( port_type , other_port , other_module , old_module , names ) : <EOL> x = old_module . location . x <EOL> y = old_module . location . y <EOL> module_name = port_type . capitalize ( ) + '<STR_LIT>' <EOL> base_name = other_port . name <EOL> if base_name == '<STR_LIT>' : <EOL> base_name = other_module . name <EOL> port_name = create_name ( base_name , names ) <EOL> module = self . create_module ( basic_pkg , module_name , '<STR_LIT>' , <EOL> x - avg_x , y - avg_y ) <EOL> functions = [ ( '<STR_LIT:name>' , [ port_name ] ) ] <EOL> for f in self . create_functions ( module , functions ) : <EOL> module . add_function ( f ) <EOL> return ( module , '<STR_LIT>' , port_name ) <EOL> def add_to_pipeline ( port_type , port , other_port , names ) : <EOL> old_module = full_pipeline . modules [ port . moduleId ] <EOL> old_port_name = port . name <EOL> port_name = other_port . name <EOL> module_id = id_remap [ ( Module . vtType , other_port . moduleId ) ] <EOL> module = module_index [ module_id ] <EOL> key = ( module_id , port_name , port_type ) <EOL> if key in existing_ports : <EOL> ( new_module , new_port , new_name ) = existing_ports [ key ] <EOL> else : <EOL> ( new_module , new_port , new_name ) = create_port ( port_type , other_port , module , <EOL> old_module , names ) <EOL> existing_ports [ key ] = ( new_module , new_port , new_name ) <EOL> pipeline . add_module ( new_module ) <EOL> if port_type == '<STR_LIT:input>' : <EOL> new_conn = self . create_connection ( new_module , new_port , <EOL> module , port_name ) <EOL> elif port_type == '<STR_LIT>' : <EOL> new_conn = self . create_connection ( module , port_name , <EOL> new_module , new_port ) <EOL> else : <EOL> raise VistrailsInternalError ( "<STR_LIT>" ) <EOL> pipeline . add_connection ( new_conn ) <EOL> return ( old_module , old_port_name , new_name ) <EOL> outside_connections = [ ] <EOL> existing_ports = { } <EOL> for connection in connections : <EOL> all_inside = True <EOL> all_outside = True <EOL> for port in connection . ports : <EOL> if not ( Module . vtType , port . moduleId ) in id_remap : <EOL> all_inside = False <EOL> else : <EOL> all_outside = False <EOL> if all_inside : <EOL> pipeline . add_connection ( connection . do_copy ( True , id_scope , <EOL> id_remap ) ) <EOL> else : <EOL> old_in_module = None <EOL> old_out_module = None <EOL> if ( Module . vtType , connection . source . moduleId ) not in id_remap : <EOL> ( old_out_module , old_out_port , old_in_port ) = add_to_pipeline ( '<STR_LIT:input>' , connection . source , <EOL> connection . destination , in_names ) <EOL> elif ( Module . vtType , connection . destination . moduleId ) not in id_remap : <EOL> ( old_in_module , old_in_port , old_out_port ) = add_to_pipeline ( '<STR_LIT>' , connection . destination , <EOL> connection . source , out_names ) <EOL> outside_connections . append ( ( old_out_module , old_out_port , <EOL> old_in_module , old_in_port ) ) <EOL> self . set_id_scope ( old_id_scope ) <EOL> return ( pipeline , outside_connections ) <EOL> def get_connections_to_subpipeline ( self , module , partial_connections ) : <EOL> connections = [ ] <EOL> for ( out_module , out_port , in_module , in_port ) in partial_connections : <EOL> if out_module is None : <EOL> out_module = module <EOL> if in_module is None : <EOL> in_module = module <EOL> connections . append ( self . create_connection ( out_module , out_port , <EOL> in_module , in_port ) ) <EOL> return connections <EOL> def build_group ( self , full_pipeline , module_ids , connection_ids ) : <EOL> id_remap = { } <EOL> ( pipeline , outside_connections ) = self . create_subpipeline ( full_pipeline , module_ids , connection_ids , <EOL> id_remap ) <EOL> ( avg_x , avg_y ) = self . get_avg_location ( [ full_pipeline . modules [ m_id ] <EOL> for m_id in module_ids ] ) <EOL> group = self . create_module ( basic_pkg , '<STR_LIT>' , '<STR_LIT>' , avg_x , avg_y ) <EOL> group . pipeline = pipeline <EOL> connections = self . get_connections_to_subpipeline ( group , outside_connections ) <EOL> return ( group , connections ) <EOL> def build_abstraction ( self , full_pipeline , module_ids , <EOL> connection_ids , name ) : <EOL> id_remap = { } <EOL> ( pipeline , outside_connections ) = self . create_subpipeline ( full_pipeline , module_ids , connection_ids , <EOL> id_remap ) <EOL> abs_vistrail = self . create_vistrail_from_pipeline ( pipeline ) <EOL> abs_vistrail . name = name <EOL> abs_vistrail . change_description ( "<STR_LIT>" , <NUM_LIT:1> L ) <EOL> abs_fname = self . save_abstraction ( abs_vistrail ) <EOL> self . add_abstraction_to_registry ( abs_vistrail , abs_fname , name , <EOL> None , "<STR_LIT:1>" ) <EOL> namespace = get_cur_abs_namespace ( abs_vistrail ) <EOL> ( avg_x , avg_y ) = self . get_avg_location ( [ full_pipeline . modules [ m_id ] <EOL> for m_id in module_ids ] ) <EOL> abstraction = self . create_module ( abstraction_pkg , name , namespace , <EOL> avg_x , avg_y , <NUM_LIT:1> L ) <EOL> connections = self . get_connections_to_subpipeline ( abstraction , <EOL> outside_connections ) <EOL> return ( abstraction , connections ) <EOL> def build_abstraction_from_group ( self , full_pipeline , group_id , name ) : <EOL> if name is None : <EOL> return <EOL> group = self . current_pipeline . modules [ group_id ] <EOL> abs_vistrail = self . create_vistrail_from_pipeline ( group . pipeline ) <EOL> abs_vistrail . name = name <EOL> abs_vistrail . change_description ( "<STR_LIT>" , <NUM_LIT:1> L ) <EOL> abs_fname = self . save_abstraction ( abs_vistrail ) <EOL> group_connections = self . get_connections_to_and_from ( full_pipeline , <EOL> [ group_id ] ) <EOL> outside_connections = [ ] <EOL> for c in group_connections : <EOL> out_module = full_pipeline . modules [ c . source . moduleId ] <EOL> out_port = c . source . name <EOL> in_module = full_pipeline . modules [ c . destination . moduleId ] <EOL> in_port = c . destination . name <EOL> if c . source . moduleId == group_id : <EOL> out_module = None <EOL> if c . destination . moduleId == group . id : <EOL> in_module = None <EOL> outside_connections . append ( ( out_module , out_port , <EOL> in_module , in_port ) ) <EOL> self . add_abstraction_to_registry ( abs_vistrail , abs_fname , name , <EOL> None , "<STR_LIT:1>" ) <EOL> namespace = get_cur_abs_namespace ( abs_vistrail ) <EOL> abstraction = self . create_module ( abstraction_pkg , name , namespace , <EOL> group . location . x , group . location . y , <EOL> <NUM_LIT:1> L ) <EOL> connections = self . get_connections_to_subpipeline ( abstraction , <EOL> outside_connections ) <EOL> return ( abstraction , connections ) <EOL> def create_vistrail_from_pipeline ( self , pipeline ) : <EOL> abs_vistrail = Vistrail ( ) <EOL> id_remap = { } <EOL> action = vistrails . core . db . action . create_paste_action ( pipeline , <EOL> abs_vistrail . idScope , <EOL> id_remap ) <EOL> abs_vistrail . add_action ( action , <NUM_LIT:0> L , <NUM_LIT:0> ) <EOL> return abs_vistrail <EOL> def get_abstraction_dir ( self ) : <EOL> conf = get_vistrails_configuration ( ) <EOL> abstraction_dir = get_vistrails_directory ( "<STR_LIT>" ) <EOL> if abstraction_dir is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> elif not os . path . exists ( abstraction_dir ) : <EOL> raise VistrailsInternalError ( "<STR_LIT>" % abstraction_dir ) <EOL> return abstraction_dir <EOL> def get_abstraction_desc ( self , package , name , namespace , module_version = None ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> if reg . has_descriptor_with_name ( package , name , namespace , <EOL> None , module_version ) : <EOL> return reg . get_descriptor_by_name ( package , name , <EOL> namespace , None , module_version ) <EOL> return None <EOL> def add_abstraction_to_registry ( self , abs_vistrail , abs_fname , name , <EOL> namespace = None , module_version = None , <EOL> is_global = True , avail_fnames = [ ] ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> cur_namespace = get_cur_abs_namespace ( abs_vistrail ) <EOL> if namespace is None : <EOL> namespace = cur_namespace <EOL> if module_version is None : <EOL> module_version = - <NUM_LIT:1> L <EOL> self . ensure_abstractions_loaded ( abs_vistrail , avail_fnames ) <EOL> try : <EOL> abstraction = new_abstraction ( name , abs_vistrail , abs_fname , <EOL> long ( module_version ) ) <EOL> except InvalidPipeline , e : <EOL> abs_controller = self . __class__ ( abs_vistrail , auto_save = False ) <EOL> ( new_version , new_pipeline ) = abs_controller . handle_invalid_pipeline ( e , long ( module_version ) , <EOL> force_no_delay = True ) <EOL> try : <EOL> abstraction = new_abstraction ( name , abs_vistrail , abs_fname , <EOL> new_version ) <EOL> except InvalidPipeline , e : <EOL> ( new_version , new_pipeline ) = abs_controller . handle_invalid_pipeline ( e , new_version , <EOL> force_no_delay = True ) <EOL> del abs_controller <EOL> save_abstraction ( abs_vistrail , abs_fname ) <EOL> self . set_changed ( True ) <EOL> abstraction = new_abstraction ( name , abs_vistrail , abs_fname , <EOL> new_version , new_pipeline ) <EOL> module_version = str ( new_version ) <EOL> all_namespaces = get_all_abs_namespaces ( abs_vistrail ) <EOL> old_desc = None <EOL> for ns in all_namespaces : <EOL> try : <EOL> desc = reg . get_similar_descriptor ( abstraction_pkg , <EOL> name , <EOL> ns ) <EOL> if not desc . is_hidden : <EOL> old_desc = desc <EOL> break <EOL> except ModuleRegistryException , e : <EOL> pass <EOL> global_hide = not is_global or old_desc is not None <EOL> newest_desc = None <EOL> requested_desc = None <EOL> for ns in all_namespaces : <EOL> hide_descriptor = ( ns != cur_namespace ) or global_hide <EOL> if reg . has_descriptor_with_name ( abstraction_pkg , <EOL> name , <EOL> ns , <EOL> abstraction_ver , <EOL> str ( module_version ) ) : <EOL> continue <EOL> new_desc = reg . auto_add_module ( ( abstraction , <EOL> { '<STR_LIT>' : abstraction_pkg , <EOL> '<STR_LIT>' : abstraction_ver , <EOL> '<STR_LIT>' : ns , <EOL> '<STR_LIT:version>' : str ( module_version ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : hide_descriptor , <EOL> } ) ) <EOL> if ns == cur_namespace : <EOL> newest_desc = new_desc <EOL> if ns == namespace : <EOL> requested_desc = new_desc <EOL> reg . auto_add_ports ( abstraction ) <EOL> if old_desc is not None : <EOL> reg . update_module ( old_desc , newest_desc ) <EOL> return requested_desc <EOL> def abstraction_exists ( self , name ) : <EOL> abstraction_dir = self . get_abstraction_dir ( ) <EOL> vt_fname = os . path . join ( abstraction_dir , name + '<STR_LIT>' ) <EOL> return os . path . exists ( vt_fname ) <EOL> def load_abstraction ( self , abs_fname , is_global = True , abs_name = None , <EOL> module_version = None , avail_fnames = [ ] ) : <EOL> if abs_name is None : <EOL> abs_name = parse_abstraction_name ( abs_fname ) <EOL> if abs_fname in self . _loaded_abstractions : <EOL> abs_vistrail = self . _loaded_abstractions [ abs_fname ] <EOL> else : <EOL> abs_vistrail = read_vistrail ( abs_fname ) <EOL> self . _loaded_abstractions [ abs_fname ] = abs_vistrail <EOL> abstraction_uuid = get_cur_abs_namespace ( abs_vistrail ) <EOL> if abstraction_uuid is None : <EOL> abstraction_uuid = str ( uuid . uuid1 ( ) ) <EOL> abs_vistrail . set_annotation ( '<STR_LIT>' , abstraction_uuid ) <EOL> origin_uuid = abs_vistrail . get_annotation ( '<STR_LIT>' ) <EOL> if origin_uuid is None : <EOL> origin_uuid = abstraction_uuid <EOL> abs_vistrail . set_annotation ( '<STR_LIT>' , origin_uuid ) <EOL> else : <EOL> origin_uuid = origin_uuid . value <EOL> if module_version is None : <EOL> module_version = str ( abs_vistrail . get_latest_version ( ) ) <EOL> elif isinstance ( module_version , ( int , long ) ) : <EOL> module_version = str ( module_version ) <EOL> upgrade_version = abs_vistrail . get_upgrade ( long ( module_version ) ) <EOL> if upgrade_version is not None : <EOL> old_version = module_version <EOL> module_version = str ( upgrade_version ) <EOL> desc = self . get_abstraction_desc ( abstraction_pkg , abs_name , <EOL> abstraction_uuid , module_version ) <EOL> if desc is None : <EOL> desc = self . add_abstraction_to_registry ( abs_vistrail , abs_fname , <EOL> abs_name , None , <EOL> module_version , <EOL> is_global , avail_fnames ) <EOL> return desc <EOL> def unload_abstractions ( self ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> for abs_fname , abs_vistrail in self . _loaded_abstractions . iteritems ( ) : <EOL> abs_name = parse_abstraction_name ( abs_fname ) <EOL> for namespace in get_all_abs_namespaces ( abs_vistrail ) : <EOL> try : <EOL> reg . delete_module ( abstraction_pkg , abs_name , namespace ) <EOL> except Exception : <EOL> pass <EOL> self . _loaded_abstractions . clear ( ) <EOL> def manage_package_names ( self , vistrail , package ) : <EOL> vistrail = copy . copy ( vistrail ) <EOL> dependencies = [ ] <EOL> for action in vistrail . actions : <EOL> for operation in action . operations : <EOL> if ( operation . vtType == '<STR_LIT>' or <EOL> operation . vtType == '<STR_LIT>' ) : <EOL> if ( operation . what == '<STR_LIT>' and <EOL> operation . data . package == abstraction_pkg ) : <EOL> operation . data . package = package <EOL> elif ( operation . what == '<STR_LIT>' or <EOL> operation . what == '<STR_LIT>' or <EOL> operation . what == '<STR_LIT>' ) : <EOL> dependencies . append ( operation . data . package ) <EOL> return ( vistrail , dependencies ) <EOL> def save_abstraction ( self , vistrail , name = None , package = None , <EOL> save_dir = None , overwrite = False ) : <EOL> if ( package is None ) != ( save_dir is None ) : <EOL> raise VistrailsInternalError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if name is None : <EOL> name = vistrail . name <EOL> if package is None and self . abstraction_exists ( name ) : <EOL> raise VistrailsInternalError ( "<STR_LIT>" <EOL> "<STR_LIT>" % name ) <EOL> new_uuid = str ( uuid . uuid1 ( ) ) <EOL> if vistrail . get_annotation ( '<STR_LIT>' ) is None : <EOL> current_uuid = vistrail . get_annotation ( '<STR_LIT>' ) <EOL> if current_uuid is None : <EOL> vistrail . set_annotation ( '<STR_LIT>' , new_uuid ) <EOL> else : <EOL> vistrail . set_annotation ( '<STR_LIT>' , <EOL> current_uuid . value ) <EOL> annotation_key = get_next_abs_annotation_key ( vistrail ) <EOL> vistrail . set_annotation ( annotation_key , new_uuid ) <EOL> if save_dir is None : <EOL> save_dir = self . get_abstraction_dir ( ) <EOL> vt_fname = os . path . join ( save_dir , name + '<STR_LIT>' ) <EOL> if not overwrite and os . path . exists ( vt_fname ) : <EOL> raise VistrailsInternalError ( "<STR_LIT>" % vt_fname ) <EOL> vistrails . core . db . io . save_vistrail_to_xml ( vistrail , vt_fname ) <EOL> return vt_fname <EOL> def upgrade_abstraction_module ( self , module_id , test_only = False ) : <EOL> """<STR_LIT>""" <EOL> invalid_module = self . current_pipeline . modules [ module_id ] <EOL> invalid_module . _module_descriptor = None <EOL> abs_fname = invalid_module . module_descriptor . module . vt_fname <EOL> ( path , prefix , abs_name , abs_namespace , suffix ) = parse_abstraction_name ( abs_fname , True ) <EOL> abs_vistrail = read_vistrail ( abs_fname ) <EOL> abs_namespace = get_cur_abs_namespace ( abs_vistrail ) <EOL> lookup = { ( abs_name , abs_namespace ) : abs_fname } <EOL> descriptor_info = invalid_module . descriptor_info <EOL> newest_version = str ( abs_vistrail . get_latest_version ( ) ) <EOL> d = self . check_abstraction ( ( descriptor_info [ <NUM_LIT:0> ] , <EOL> descriptor_info [ <NUM_LIT:1> ] , <EOL> abs_namespace , <EOL> descriptor_info [ <NUM_LIT:3> ] , <EOL> newest_version ) , <EOL> lookup ) <EOL> failed = True <EOL> src_ports_gone = { } <EOL> dst_ports_gone = { } <EOL> fns_gone = { } <EOL> missing_ports = [ ] <EOL> check_upgrade = UpgradeWorkflowHandler . check_upgrade <EOL> while failed : <EOL> try : <EOL> check_upgrade ( self . current_pipeline , module_id , d , <EOL> function_remap = fns_gone , <EOL> src_port_remap = src_ports_gone , <EOL> dst_port_remap = dst_ports_gone ) <EOL> if test_only : <EOL> return ( len ( missing_ports ) == <NUM_LIT:0> , missing_ports ) <EOL> failed = False <EOL> except UpgradeWorkflowError , e : <EOL> if test_only : <EOL> missing_ports . append ( ( e . _port_type , e . _port_name ) ) <EOL> if e . _module is None or e . _port_type is None or e . _port_name is None : <EOL> raise e <EOL> if e . _port_type == '<STR_LIT>' : <EOL> src_ports_gone [ e . _port_name ] = None <EOL> elif e . _port_type == '<STR_LIT:input>' : <EOL> dst_ports_gone [ e . _port_name ] = None <EOL> fns_gone [ e . _port_name ] = None <EOL> else : <EOL> raise e <EOL> upgrade_action = UpgradeWorkflowHandler . replace_module ( self , self . current_pipeline , <EOL> module_id , d , <EOL> fns_gone , <EOL> src_ports_gone , <EOL> dst_ports_gone ) [ <NUM_LIT:0> ] <EOL> self . flush_delayed_actions ( ) <EOL> self . add_new_action ( upgrade_action ) <EOL> self . perform_action ( upgrade_action ) <EOL> self . vistrail . change_description ( "<STR_LIT>" , <EOL> self . current_version ) <EOL> def get_abstraction_descriptor ( self , name , namespace = None ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> return reg . get_descriptor_by_name ( abstraction_pkg , name , namespace ) <EOL> def import_abstraction ( self , new_name , package , name , namespace , <EOL> module_version = None ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> descriptor = self . get_abstraction_desc ( package , name , namespace , str ( module_version ) ) <EOL> if descriptor is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" % ( name , namespace , package ) ) <EOL> abs_vistrail = descriptor . module . vistrail <EOL> abs_desc_info = abs_vistrail . get_annotation ( '<STR_LIT>' ) <EOL> if abs_desc_info is not None : <EOL> abs_vistrail . set_annotation ( '<STR_LIT>' , None ) <EOL> abs_fname = self . save_abstraction ( abs_vistrail , new_name ) <EOL> imported_vistrail = read_vistrail ( abs_fname ) <EOL> annotation_key = get_next_abs_annotation_key ( abs_vistrail ) <EOL> abs_vistrail . set_annotation ( annotation_key , namespace ) <EOL> if abs_desc_info is not None : <EOL> abs_vistrail . set_annotation ( '<STR_LIT>' , abs_desc_info . value ) <EOL> new_desc = self . add_abstraction_to_registry ( imported_vistrail , abs_fname , new_name , <EOL> None , str ( module_version ) ) <EOL> reg . show_module ( new_desc ) <EOL> def export_abstraction ( self , new_name , pkg_name , dir , package , name , namespace , <EOL> module_version ) : <EOL> descriptor = self . get_abstraction_desc ( package , name , namespace , module_version ) <EOL> if descriptor is None : <EOL> raise VistrailsInternalError ( "<STR_LIT>" % ( name , namespace , package ) ) <EOL> abs_vistrail = descriptor . module . vistrail <EOL> ( abs_vistrail , dependencies ) = self . manage_package_names ( abs_vistrail , <EOL> pkg_name ) <EOL> abs_fname = self . save_abstraction ( abs_vistrail , new_name , pkg_name , <EOL> dir ) <EOL> return ( os . path . basename ( abs_fname ) , dependencies ) <EOL> def find_abstractions ( self , vistrail , recurse = False ) : <EOL> abstractions = { } <EOL> for action in vistrail . actions : <EOL> for operation in action . operations : <EOL> if operation . vtType == '<STR_LIT>' or operation . vtType == '<STR_LIT>' : <EOL> if operation . data is not None and operation . data . vtType == Abstraction . vtType : <EOL> abstraction = operation . data <EOL> if abstraction . package == abstraction_pkg : <EOL> key = abstraction . descriptor_info <EOL> if key not in abstractions : <EOL> abstractions [ key ] = [ ] <EOL> abstractions [ key ] . append ( abstraction ) <EOL> if recurse : <EOL> for abstraction_list in abstractions . values ( ) : <EOL> for abstraction in abstraction_list [ : ] : <EOL> try : <EOL> vistrail = abstraction . vistrail <EOL> except MissingPackageVersion , e : <EOL> try : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> abstraction . _module_descriptor = reg . get_similar_descriptor ( <EOL> * abstraction . descriptor_info ) <EOL> vistrail = abstraction . vistrail <EOL> except Exception , e : <EOL> continue <EOL> except Exception , e : <EOL> continue <EOL> r_abstractions = self . find_abstractions ( vistrail , recurse ) <EOL> for k , v in r_abstractions . iteritems ( ) : <EOL> if k not in abstractions : <EOL> abstractions [ k ] = [ ] <EOL> abstractions [ k ] . extend ( v ) <EOL> return abstractions <EOL> def check_abstraction ( self , descriptor_tuple , lookup ) : <EOL> reg = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> try : <EOL> descriptor = reg . get_descriptor_by_name ( * descriptor_tuple ) <EOL> if not os . path . exists ( descriptor . module . vt_fname ) : <EOL> reg . delete_descriptor ( descriptor ) <EOL> raise MissingModule ( descriptor_tuple [ <NUM_LIT:0> ] , <EOL> descriptor_tuple [ <NUM_LIT:1> ] , <EOL> descriptor_tuple [ <NUM_LIT:2> ] , <EOL> descriptor_tuple [ <NUM_LIT:4> ] ) <EOL> return descriptor <EOL> except MissingPackageVersion , e : <EOL> if descriptor_tuple [ <NUM_LIT:3> ] != '<STR_LIT>' : <EOL> new_desc = ( descriptor_tuple [ <NUM_LIT:0> ] , <EOL> descriptor_tuple [ <NUM_LIT:1> ] , <EOL> descriptor_tuple [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' , <EOL> descriptor_tuple [ <NUM_LIT:4> ] ) <EOL> return self . check_abstraction ( new_desc , lookup ) <EOL> else : <EOL> raise <EOL> except MissingModuleVersion , e : <EOL> if descriptor_tuple [ <NUM_LIT:4> ] != '<STR_LIT>' : <EOL> other_desc = reg . get_descriptor_by_name ( descriptor_tuple [ <NUM_LIT:0> ] , <EOL> descriptor_tuple [ <NUM_LIT:1> ] , <EOL> descriptor_tuple [ <NUM_LIT:2> ] , <EOL> descriptor_tuple [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' ) <EOL> new_desc = self . load_abstraction ( other_desc . module . vt_fname , <EOL> False , descriptor_tuple [ <NUM_LIT:1> ] , <EOL> descriptor_tuple [ <NUM_LIT:4> ] ) <EOL> descriptor_tuple = ( new_desc . package , new_desc . name , <EOL> new_desc . namespace , new_desc . package_version , <EOL> str ( new_desc . version ) ) <EOL> return self . check_abstraction ( descriptor_tuple , lookup ) <EOL> else : <EOL> raise <EOL> except MissingModule , e : <EOL> if ( descriptor_tuple [ <NUM_LIT:1> ] , descriptor_tuple [ <NUM_LIT:2> ] ) not in lookup : <EOL> if ( descriptor_tuple [ <NUM_LIT:1> ] , None ) not in lookup : <EOL> raise <EOL> abs_fnames = lookup [ ( descriptor_tuple [ <NUM_LIT:1> ] , None ) ] <EOL> else : <EOL> abs_fnames = [ lookup [ ( descriptor_tuple [ <NUM_LIT:1> ] , descriptor_tuple [ <NUM_LIT:2> ] ) ] ] <EOL> for abs_fname in abs_fnames : <EOL> new_desc = self . load_abstraction ( abs_fname , False , <EOL> descriptor_tuple [ <NUM_LIT:1> ] , <EOL> descriptor_tuple [ <NUM_LIT:4> ] , <EOL> [ v for k , v in lookup . iteritems ( ) <EOL> if k [ <NUM_LIT:1> ] is not None ] ) <EOL> descriptor_tuple = ( new_desc . package , new_desc . name , <EOL> new_desc . namespace , new_desc . package_version , <EOL> str ( new_desc . version ) ) <EOL> return self . check_abstraction ( descriptor_tuple , lookup ) <EOL> def ensure_abstractions_loaded ( self , vistrail , abs_fnames ) : <EOL> lookup = { } <EOL> for abs_fname in abs_fnames : <EOL> path , prefix , abs_name , abs_namespace , suffix = parse_abstraction_name ( abs_fname , True ) <EOL> lookup [ ( abs_name , abs_namespace ) ] = abs_fname <EOL> if ( abs_name , None ) not in lookup : <EOL> lookup [ ( abs_name , None ) ] = [ ] <EOL> lookup [ ( abs_name , None ) ] . append ( abs_fname ) <EOL> abstractions = self . find_abstractions ( vistrail ) <EOL> for descriptor_info , abstraction_list in abstractions . iteritems ( ) : <EOL> try : <EOL> descriptor = self . check_abstraction ( descriptor_info , <EOL> lookup ) <EOL> for abstraction in abstraction_list : <EOL> abstraction . module_descriptor = descriptor <EOL> except InvalidPipeline , e : <EOL> debug . critical ( "<STR_LIT>" % <EOL> descriptor_info [ <NUM_LIT:1> ] , e ) <EOL> def build_ungroup ( self , full_pipeline , module_id ) : <EOL> group = full_pipeline . modules [ module_id ] <EOL> if group . vtType == Group . vtType : <EOL> pipeline = group . pipeline <EOL> elif group . vtType == Abstraction . vtType : <EOL> pipeline = group . summon ( ) . pipeline <EOL> else : <EOL> print '<STR_LIT>' <EOL> return <EOL> pipeline . ensure_connection_specs ( ) <EOL> port_modules = set ( ) <EOL> modules = [ ] <EOL> connections = [ ] <EOL> id_remap = { } <EOL> for module in pipeline . module_list : <EOL> if module . package == basic_pkg and ( module . name == '<STR_LIT>' or <EOL> module . name == '<STR_LIT>' ) : <EOL> if module . name == '<STR_LIT>' : <EOL> port_modules . add ( ( module , '<STR_LIT:input>' ) ) <EOL> else : <EOL> port_modules . add ( ( module , '<STR_LIT>' ) ) <EOL> else : <EOL> modules . append ( module . do_copy ( True , self . id_scope , id_remap ) ) <EOL> module_index = dict ( [ ( m . id , m ) for m in modules ] ) <EOL> open_ports = { } <EOL> unconnected_port_modules = { } <EOL> for port_module , port_type in port_modules : <EOL> ( port_name , _ , _ , _ , neighbors ) = group . get_port_spec_info ( port_module ) <EOL> new_neighbors = [ ( module_index [ id_remap [ ( Module . vtType , m . id ) ] ] , n ) <EOL> for ( m , n ) in neighbors <EOL> if ( Module . vtType , m . id ) in id_remap ] <EOL> open_ports [ ( port_name , port_type ) ] = new_neighbors <EOL> unconnected_port_modules [ ( port_name , port_type ) ] = port_module <EOL> for connection in full_pipeline . connection_list : <EOL> if connection . source . moduleId == group . id : <EOL> key = ( connection . source . name , '<STR_LIT>' ) <EOL> try : <EOL> del unconnected_port_modules [ key ] <EOL> except KeyError : <EOL> pass <EOL> if key not in open_ports : <EOL> continue <EOL> neighbors = open_ports [ key ] <EOL> input_module = full_pipeline . modules [ connection . destination . moduleId ] <EOL> input_port = connection . destination . name <EOL> for ( output_module , output_port ) in neighbors : <EOL> connections . append ( self . create_connection ( output_module , <EOL> output_port , <EOL> input_module , <EOL> input_port ) ) <EOL> elif connection . destination . moduleId == group . id : <EOL> key = ( connection . destination . name , '<STR_LIT:input>' ) <EOL> try : <EOL> del unconnected_port_modules [ key ] <EOL> except KeyError : <EOL> pass <EOL> if key not in open_ports : <EOL> continue <EOL> neighbors = open_ports [ key ] <EOL> output_module = full_pipeline . modules [ connection . source . moduleId ] <EOL> output_port = connection . source . name <EOL> for ( input_module , input_port ) in neighbors : <EOL> connections . append ( self . create_connection ( output_module , <EOL> output_port , <EOL> input_module , <EOL> input_port ) ) <EOL> for key , port_module in unconnected_port_modules . iteritems ( ) : <EOL> modules . append ( port_module . do_copy ( True , self . id_scope , id_remap ) ) <EOL> self . translate_modules ( modules , - group . location . x , - group . location . y ) <EOL> for connection in pipeline . connection_list : <EOL> all_inside = all ( ( Module . vtType , port . moduleId ) in id_remap <EOL> for port in connection . ports ) <EOL> if all_inside : <EOL> connections . append ( connection . do_copy ( True , self . id_scope , <EOL> id_remap ) ) <EOL> return ( modules , connections ) <EOL> def find_thumbnails ( self , tags_only = True ) : <EOL> thumbnails = [ ] <EOL> thumb_cache = ThumbnailCache . getInstance ( ) <EOL> for action in self . vistrail . actions : <EOL> if self . vistrail . has_thumbnail ( action . id ) : <EOL> thumbnail = self . vistrail . get_thumbnail ( action . id ) <EOL> if tags_only and not self . vistrail . has_tag ( action . timestep ) : <EOL> thumb_cache . remove ( thumbnail ) <EOL> self . vistrail . set_thumbnail ( action . timestep , "<STR_LIT>" ) <EOL> else : <EOL> abs_fname = thumb_cache . get_abs_name_entry ( thumbnail ) <EOL> if abs_fname is not None : <EOL> thumbnails . append ( abs_fname ) <EOL> else : <EOL> self . vistrail . set_thumbnail ( action . timestep , "<STR_LIT>" ) <EOL> return thumbnails <EOL> def add_parameter_changes_from_execution ( self , pipeline , version , <EOL> parameter_changes ) : <EOL> """<STR_LIT>""" <EOL> current_pipeline = self . current_pipeline <EOL> current_version = self . current_version <EOL> self . current_pipeline = pipeline <EOL> self . current_version = version <EOL> op_list = [ ] <EOL> for ( m_id , function_name , param_values ) in parameter_changes : <EOL> try : <EOL> param_values_len = len ( param_values ) <EOL> except TypeError : <EOL> param_values = [ param_values ] <EOL> param_values = [ str ( x ) for x in param_values ] <EOL> module = self . current_pipeline . modules [ m_id ] <EOL> old_id = - <NUM_LIT:1> <EOL> for old_function in module . functions : <EOL> if old_function . name == function_name : <EOL> old_id = old_function . real_id <EOL> aliases = [ ] <EOL> if old_id >= <NUM_LIT:0> : <EOL> function = module . function_idx [ old_id ] <EOL> for i in xrange ( len ( param_values ) ) : <EOL> aliases . append ( function . params [ i ] . alias ) <EOL> op_list . extend ( self . update_function_ops ( module , function_name , <EOL> param_values , <EOL> should_replace = True , <EOL> aliases = aliases ) ) <EOL> action = vistrails . core . db . action . create_action ( op_list ) <EOL> self . add_new_action ( action ) <EOL> self . current_pipeline = current_pipeline <EOL> self . current_version = current_version <EOL> return action . id <EOL> def execute_workflow_list ( self , vistrails ) : <EOL> """<STR_LIT>""" <EOL> stop_on_error = getattr ( get_vistrails_configuration ( ) , <EOL> '<STR_LIT>' ) <EOL> interpreter = get_default_interpreter ( ) <EOL> changed = False <EOL> results = [ ] <EOL> for vis in vistrails : <EOL> error = None <EOL> ( locator , version , pipeline , view , aliases , params , reason , sinks , extra_info ) = vis <EOL> temp_folder_used = False <EOL> if ( not extra_info or not extra_info . has_key ( '<STR_LIT>' ) or <EOL> not extra_info [ '<STR_LIT>' ] ) : <EOL> if extra_info is None : <EOL> extra_info = { } <EOL> extra_info [ '<STR_LIT>' ] = create_temp_folder ( prefix = '<STR_LIT>' ) <EOL> temp_folder_used = True <EOL> kwargs = { '<STR_LIT>' : locator , <EOL> '<STR_LIT>' : version , <EOL> '<STR_LIT>' : view if view is not None else DummyView ( ) , <EOL> '<STR_LIT>' : self . get_logger ( ) , <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : aliases , <EOL> '<STR_LIT>' : params , <EOL> '<STR_LIT>' : reason , <EOL> '<STR_LIT>' : sinks , <EOL> '<STR_LIT>' : extra_info , <EOL> '<STR_LIT>' : stop_on_error , <EOL> } <EOL> if self . get_vistrail_variables ( ) : <EOL> kwargs [ '<STR_LIT>' ] = self . get_vistrail_variable_by_uuid <EOL> result = interpreter . execute ( pipeline , ** kwargs ) <EOL> thumb_cache = ThumbnailCache . getInstance ( ) <EOL> if len ( result . errors ) == <NUM_LIT:0> and ( thumb_cache . conf . autoSave or '<STR_LIT>' in extra_info ) : <EOL> old_thumb_name = self . vistrail . get_thumbnail ( version ) <EOL> if '<STR_LIT>' in extra_info : <EOL> old_thumb_name = None <EOL> fname = thumb_cache . add_entry_from_cell_dump ( <EOL> extra_info [ '<STR_LIT>' ] , <EOL> old_thumb_name ) <EOL> if '<STR_LIT>' in extra_info : <EOL> prev = None <EOL> thumb_version = version <EOL> while not self . vistrail . has_thumbnail ( thumb_version ) and thumb_version in self . vistrail . actionMap and self . vistrail . has_upgrade ( self . vistrail . actionMap [ thumb_version ] . parent ) : <EOL> thumb_version = self . vistrail . actionMap [ thumb_version ] . parent <EOL> if self . vistrail . has_thumbnail ( thumb_version ) : <EOL> prev = thumb_cache . get_abs_name_entry ( self . vistrail . get_thumbnail ( thumb_version ) ) <EOL> else : <EOL> error = CompareThumbnailsError ( "<STR_LIT>" % thumb_version ) <EOL> if prev : <EOL> if not prev : <EOL> error = CompareThumbnailsError ( "<STR_LIT>" % thumb_version ) <EOL> elif not fname : <EOL> raise CompareThumbnailsError ( "<STR_LIT>" ) <EOL> else : <EOL> next = thumb_cache . get_abs_name_entry ( fname ) <EOL> if not next : <EOL> raise CompareThumbnailsError ( "<STR_LIT>" % thumb_version ) <EOL> else : <EOL> min_err = extra_info [ '<STR_LIT>' ] ( prev , next ) <EOL> treshold = <NUM_LIT:0.1> <EOL> if min_err > treshold : <EOL> raise CompareThumbnailsError ( "<STR_LIT>" % min_err , prev , next ) <EOL> if fname is not None : <EOL> self . vistrail . set_thumbnail ( version , fname ) <EOL> changed = True <EOL> if temp_folder_used : <EOL> remove_temp_folder ( extra_info [ '<STR_LIT>' ] ) <EOL> if result . parameter_changes : <EOL> l = result . parameter_changes <EOL> self . add_parameter_changes_from_execution ( pipeline , version , l ) <EOL> changed = True <EOL> results . append ( result ) <EOL> if error : <EOL> result . errors [ version ] = error <EOL> return ( [ result ] , False ) <EOL> if self . logging_on ( ) : <EOL> self . set_changed ( True ) <EOL> if interpreter . debugger : <EOL> interpreter . debugger . update_values ( ) <EOL> return ( results , changed ) <EOL> def execute_current_workflow ( self , custom_aliases = None , custom_params = None , <EOL> extra_info = None , reason = '<STR_LIT>' , <EOL> sinks = None ) : <EOL> """<STR_LIT>""" <EOL> self . flush_delayed_actions ( ) <EOL> if self . current_pipeline : <EOL> locator = self . get_locator ( ) <EOL> if locator : <EOL> locator . clean_temporaries ( ) <EOL> if self . _auto_save : <EOL> locator . save_temporary ( self . vistrail ) <EOL> try : <EOL> return self . execute_workflow_list ( [ ( self . locator , <EOL> self . current_version , <EOL> self . current_pipeline , <EOL> None , <EOL> custom_aliases , <EOL> custom_params , <EOL> reason , <EOL> sinks , <EOL> extra_info ) ] ) <EOL> except Exception , e : <EOL> debug . unexpected_exception ( e ) <EOL> raise <EOL> def prune_versions ( self , versions ) : <EOL> """<STR_LIT>""" <EOL> current = self . _current_terse_graph <EOL> if not current : <EOL> self . recompute_terse_graph ( ) <EOL> current , full = self . _current_terse_graph , self . _current_full_graph <EOL> else : <EOL> full = self . _current_full_graph <EOL> changed = False <EOL> new_current_version = None <EOL> for v in versions : <EOL> if v != <NUM_LIT:0> : <EOL> highest = v <EOL> while True : <EOL> p = full . parent ( highest ) <EOL> if p == - <NUM_LIT:1> : <EOL> break <EOL> if p in current . vertices : <EOL> break <EOL> highest = p <EOL> if highest != <NUM_LIT:0> : <EOL> changed = True <EOL> if highest == self . current_version : <EOL> new_current_version = full . parent ( highest ) <EOL> self . vistrail . pruneVersion ( highest ) <EOL> if changed : <EOL> self . set_changed ( True ) <EOL> if new_current_version is not None : <EOL> self . change_selected_version ( new_current_version ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False ) <EOL> def hide_versions_below ( self , v = None ) : <EOL> """<STR_LIT>""" <EOL> if v is None : <EOL> v = self . current_base_version <EOL> full = self . vistrail . getVersionGraph ( ) <EOL> x = [ v ] <EOL> am = self . vistrail . actionMap <EOL> changed = False <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> current = x . pop ( ) <EOL> except IndexError : <EOL> break <EOL> children = [ to for ( to , _ ) in full . adjacency_list [ current ] <EOL> if ( to in am ) and not self . vistrail . is_pruned ( to ) ] <EOL> self . vistrail . hideVersion ( current ) <EOL> changed = True <EOL> for child in children : <EOL> x . append ( child ) <EOL> if changed : <EOL> self . set_changed ( True ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False , False ) <EOL> def show_all_versions ( self ) : <EOL> """<STR_LIT>""" <EOL> am = self . vistrail . actionMap <EOL> for a in am . iterkeys ( ) : <EOL> self . vistrail . showVersion ( a ) <EOL> self . set_changed ( True ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False , False ) <EOL> def expand_versions ( self , v1 , v2 ) : <EOL> """<STR_LIT>""" <EOL> full = self . vistrail . getVersionGraph ( ) <EOL> p = full . parent ( v2 ) <EOL> while p > v1 : <EOL> self . vistrail . expandVersion ( p ) <EOL> p = full . parent ( p ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False , True ) <EOL> def collapse_versions ( self , v ) : <EOL> """<STR_LIT>""" <EOL> full = self . vistrail . getVersionGraph ( ) <EOL> x = [ v ] <EOL> am = self . vistrail . actionMap <EOL> tm = self . vistrail . get_tagMap ( ) <EOL> upgrades = set ( ) <EOL> for ann in self . vistrail . action_annotations : <EOL> if ann . key != Vistrail . UPGRADE_ANNOTATION : <EOL> continue <EOL> upgrades . add ( int ( ann . value ) ) <EOL> while x : <EOL> current = x . pop ( ) <EOL> all_children = [ to for to , _ in full . adjacency_list [ current ] <EOL> if to in am ] <EOL> children = [ ] <EOL> while all_children : <EOL> child = all_children . pop ( ) <EOL> if self . vistrail . is_pruned ( child ) : <EOL> pass <EOL> elif ( not self . show_upgrades and child in upgrades and <EOL> child not in tm ) : <EOL> all_children . extend ( <EOL> to for to , _ in full . adjacency_list [ child ] <EOL> if to in am ) <EOL> else : <EOL> children . append ( child ) <EOL> if len ( children ) > <NUM_LIT:1> : <EOL> break <EOL> self . vistrail . collapseVersion ( current ) <EOL> for child in children : <EOL> if ( not child in tm and <EOL> child != self . current_base_version ) : <EOL> x . append ( child ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False , True ) <EOL> def expand_or_collapse_all_versions_below ( self , v = None , expand = True ) : <EOL> """<STR_LIT>""" <EOL> if v is None : <EOL> v = self . current_base_version <EOL> full = self . vistrail . getVersionGraph ( ) <EOL> x = [ v ] <EOL> am = self . vistrail . actionMap <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> current = x . pop ( ) <EOL> except IndexError : <EOL> break <EOL> children = [ to for ( to , _ ) in full . adjacency_list [ current ] <EOL> if ( to in am ) and not self . vistrail . is_pruned ( to ) ] <EOL> if expand : <EOL> self . vistrail . expandVersion ( current ) <EOL> else : <EOL> self . vistrail . collapseVersion ( current ) <EOL> for child in children : <EOL> x . append ( child ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False , True ) <EOL> def expand_all_versions_below ( self , v = None ) : <EOL> self . expand_or_collapse_all_versions_below ( v , True ) <EOL> def collapse_all_versions_below ( self , v = None ) : <EOL> self . expand_or_collapse_all_versions_below ( v , False ) <EOL> def collapse_all_versions ( self ) : <EOL> """<STR_LIT>""" <EOL> am = self . vistrail . actionMap <EOL> for a in am . iterkeys ( ) : <EOL> self . vistrail . collapseVersion ( a ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False , True ) <EOL> def recompute_terse_graph ( self , show_upgrades = None ) : <EOL> if show_upgrades is None : <EOL> show_upgrades = not getattr ( get_vistrails_configuration ( ) , <EOL> '<STR_LIT>' , True ) <EOL> self . show_upgrades = show_upgrades <EOL> fullVersionTree = self . vistrail . tree . getVersionTree ( ) <EOL> open_list = [ ( <NUM_LIT:0> , None , False , False ) ] <EOL> tersedVersionTree = Graph ( ) <EOL> am = self . vistrail . actionMap <EOL> tm = self . vistrail . get_tagMap ( ) <EOL> last_n = self . vistrail . getLastActions ( self . num_versions_always_shown ) <EOL> upgrades = set ( ) <EOL> upgrade_rev_map = { } <EOL> current_version = self . current_version <EOL> def rev_map ( v ) : <EOL> return upgrade_rev_map . get ( v , v ) <EOL> if not self . show_upgrades : <EOL> for ann in self . vistrail . action_annotations : <EOL> if ann . key != Vistrail . UPGRADE_ANNOTATION : <EOL> continue <EOL> upgrades . add ( int ( ann . value ) ) <EOL> upgrade_rev_map [ int ( ann . value ) ] = ann . action_id <EOL> current_version = rev_map ( current_version ) <EOL> tm , orig_tm = { } , tm <EOL> for version , name in sorted ( orig_tm . iteritems ( ) , <EOL> key = lambda p : p [ <NUM_LIT:0> ] ) : <EOL> v = version <EOL> while v in upgrade_rev_map : <EOL> v = upgrade_rev_map [ v ] <EOL> if v in orig_tm : <EOL> v = version <EOL> break <EOL> tm [ v ] = name <EOL> del orig_tm <EOL> for k , v in upgrade_rev_map . iteritems ( ) : <EOL> while v in upgrade_rev_map : <EOL> v = upgrade_rev_map [ v ] <EOL> upgrade_rev_map [ k ] = v <EOL> while open_list : <EOL> current , parent , expandable , collapsible = open_list . pop ( ) <EOL> all_children = [ <EOL> to for to , _ in fullVersionTree . adjacency_list [ current ] <EOL> if to in am ] <EOL> children = [ ] <EOL> while all_children : <EOL> child = all_children . pop ( ) <EOL> if self . vistrail . is_pruned ( child ) : <EOL> pass <EOL> elif ( not self . show_upgrades and <EOL> ( child in upgrades or <EOL> am [ child ] . description == '<STR_LIT>' ) and <EOL> child not in tm ) : <EOL> all_children . extend ( <EOL> to for to , _ in fullVersionTree . adjacency_list [ child ] <EOL> if to in am ) <EOL> else : <EOL> children . append ( child ) <EOL> display = ( self . full_tree or <EOL> current == <NUM_LIT:0> or <EOL> current in tm or <EOL> current in last_n or <EOL> current == current_version or <EOL> len ( children ) != <NUM_LIT:1> ) <EOL> if ( display or am [ current ] . expand ) : <EOL> if ( not self . refine or <EOL> ( self . refine and not self . search ) or <EOL> current == <NUM_LIT:0> or <EOL> ( self . refine and self . search and <EOL> self . search . match ( self . vistrail , am [ current ] ) ) or <EOL> current == current_version ) : <EOL> tersedVersionTree . add_vertex ( current , tm . get ( current ) ) <EOL> if parent is not None : <EOL> collapse_here = not collapsible and not display <EOL> tersedVersionTree . add_edge ( parent , current , <EOL> ( expandable , collapse_here ) ) <EOL> collapsible = collapsible or collapse_here <EOL> parentToChildren = current <EOL> expandable = False <EOL> else : <EOL> parentToChildren = parent <EOL> expandable = True <EOL> else : <EOL> parentToChildren = parent <EOL> expandable = True <EOL> if collapsible and len ( children ) > <NUM_LIT:1> : <EOL> collapsible = False <EOL> for child in children : <EOL> open_list . append ( ( child , parentToChildren , <EOL> expandable , collapsible ) ) <EOL> self . _current_terse_graph = tersedVersionTree <EOL> self . _current_full_graph = self . vistrail . tree . getVersionTree ( ) <EOL> self . _upgrade_rev_map = upgrade_rev_map <EOL> def save_version_graph ( self , filename , tersed = True , highlight = None ) : <EOL> if tersed : <EOL> graph = copy . copy ( self . _current_terse_graph ) <EOL> else : <EOL> graph = copy . copy ( self . _current_full_graph ) <EOL> tm = self . vistrail . get_tagMap ( ) <EOL> vs = graph . vertices . keys ( ) <EOL> vs . sort ( ) <EOL> al = [ ( vfrom , vto , edgeid ) <EOL> for vfrom , lto in graph . adjacency_list . iteritems ( ) <EOL> for vto , edgeid in lto ] <EOL> al . sort ( ) <EOL> configuration = get_vistrails_configuration ( ) <EOL> use_custom_colors = configuration . check ( '<STR_LIT>' ) <EOL> if isinstance ( filename , basestring ) : <EOL> fp = open ( filename , '<STR_LIT:wb>' ) <EOL> cleanup = lambda : fp . close ( ) <EOL> else : <EOL> fp = filename <EOL> cleanup = lambda : None <EOL> try : <EOL> fp . write ( '<STR_LIT>' ) <EOL> for v in vs : <EOL> descr = tm . get ( v , None ) or self . vistrail . get_description ( v ) <EOL> if use_custom_colors : <EOL> color = self . vistrail . get_action_annotation ( <EOL> v , <EOL> custom_color_key ) <EOL> else : <EOL> color = None <EOL> if color : <EOL> color = '<STR_LIT>' % tuple ( <EOL> '<STR_LIT>' % c <EOL> for c in parse_custom_color ( color . value ) ) <EOL> fp . write ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> v , dot_escape ( descr ) , color , <EOL> '<STR_LIT>' if v == highlight else '<STR_LIT>' ) ) <EOL> else : <EOL> fp . write ( '<STR_LIT>' % ( <EOL> v , dot_escape ( descr ) , <EOL> '<STR_LIT>' if v == highlight else '<STR_LIT>' ) ) <EOL> fp . write ( '<STR_LIT:\n>' ) <EOL> for s in al : <EOL> vfrom , vto , vdata = s <EOL> fp . write ( '<STR_LIT>' % ( vfrom , vto ) ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> finally : <EOL> cleanup ( ) <EOL> def get_latest_version_in_graph ( self ) : <EOL> if not self . _current_terse_graph : <EOL> self . recompute_terse_graph ( ) <EOL> if self . _current_terse_graph : <EOL> return max ( self . _current_terse_graph . iter_vertices ( ) ) <EOL> return max ( self . actions ) <EOL> def select_latest_version ( self ) : <EOL> """<STR_LIT>""" <EOL> self . change_selected_version ( self . get_latest_version_in_graph ( ) ) <EOL> def enable_missing_package ( self , identifier , deps ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def install_missing_package ( self , identifier ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def try_to_enable_package ( self , identifier , confirmed = False ) : <EOL> """<STR_LIT>""" <EOL> pm = get_package_manager ( ) <EOL> pkg = pm . identifier_is_available ( identifier ) <EOL> if pkg is None or pm . has_package ( pkg . identifier ) : <EOL> return False <EOL> dep_graph = pm . build_dependency_graph ( [ identifier ] ) <EOL> deps = pm . get_ordered_dependencies ( dep_graph ) <EOL> other_deps = filter ( lambda i : i != identifier , deps ) <EOL> if pkg . identifier in self . _asked_packages : <EOL> return False <EOL> if not confirmed and not self . enable_missing_package ( pkg . identifier , other_deps ) : <EOL> self . _asked_packages . add ( pkg . identifier ) <EOL> return False <EOL> for pkg_id in deps : <EOL> if not self . do_enable_package ( pkg_id ) : <EOL> return False <EOL> return True <EOL> def do_enable_package ( self , identifier ) : <EOL> pm = get_package_manager ( ) <EOL> pkg = pm . identifier_is_available ( identifier ) <EOL> if pkg and not pm . has_package ( pkg . identifier ) : <EOL> try : <EOL> pm . late_enable_package ( pkg . codepath ) <EOL> pkg = pm . get_package_by_codepath ( pkg . codepath ) <EOL> if pkg . identifier != identifier : <EOL> if hasattr ( pkg . module , "<STR_LIT>" ) and pkg . module . can_handle_identifier ( identifier ) : <EOL> pkg . init_module . load_from_identifier ( identifier ) <EOL> except pkg . MissingDependency , e : <EOL> for dependency in e . dependencies : <EOL> print '<STR_LIT>' , dependency <EOL> return False <EOL> except pkg . InitializationFailed : <EOL> self . _asked_packages . add ( pkg . identifier ) <EOL> raise <EOL> self . _asked_packages . add ( pkg . identifier ) <EOL> return True <EOL> if pkg and pkg . identifier != identifier and hasattr ( pkg . module , "<STR_LIT>" ) and pkg . module . can_handle_identifier ( identifier ) and hasattr ( pkg . init_module , "<STR_LIT>" ) : <EOL> pkg . init_module . load_from_identifier ( identifier ) <EOL> return True <EOL> rep = vistrails . core . packagerepository . get_repository ( ) <EOL> if rep : <EOL> codepath = rep . find_package ( identifier ) <EOL> if codepath and self . install_missing_package ( identifier ) : <EOL> rep . install_package ( codepath ) <EOL> return self . try_to_enable_package ( identifier , True ) <EOL> self . _asked_packages . add ( identifier ) <EOL> return False <EOL> def set_action_annotation ( self , action , key , value , id_scope = None ) : <EOL> if id_scope is None : <EOL> id_scope = self . id_scope <EOL> if action . has_annotation_with_key ( key ) : <EOL> old_annotation = action . get_annotation_by_key ( key ) <EOL> if old_annotation . value == value : <EOL> return False <EOL> action . delete_annotation ( old_annotation ) <EOL> if value . strip ( ) != '<STR_LIT>' : <EOL> annotation = Annotation ( id = id_scope . getNewId ( Annotation . vtType ) , <EOL> key = key , <EOL> value = value , <EOL> ) <EOL> action . add_annotation ( annotation ) <EOL> def get_upgrade_module_remap ( self , actions ) : <EOL> """<STR_LIT>""" <EOL> is_full_remap = True <EOL> remap = { } <EOL> for action in actions : <EOL> d_module_ids = [ ] <EOL> a_module_ids = [ ] <EOL> for op in action . operations : <EOL> if op . vtType == '<STR_LIT>' and op . what == '<STR_LIT>' : <EOL> d_module_ids . append ( op . db_objectId ) <EOL> if op . vtType == '<STR_LIT>' and op . what == '<STR_LIT>' : <EOL> a_module_ids . append ( op . db_objectId ) <EOL> if len ( d_module_ids ) == <NUM_LIT:1> and len ( a_module_ids ) == <NUM_LIT:1> : <EOL> remap [ ( Module . vtType , d_module_ids [ <NUM_LIT:0> ] ) ] = a_module_ids [ <NUM_LIT:0> ] <EOL> elif len ( d_module_ids ) + len ( a_module_ids ) > <NUM_LIT:0> : <EOL> is_full_remap = False <EOL> return ( remap , is_full_remap ) <EOL> def get_simple_upgrade_remap ( self , actions ) : <EOL> """<STR_LIT>""" <EOL> is_full_remap = True <EOL> remap = { } <EOL> for action in actions : <EOL> delete_ops = [ ] <EOL> add_ops = [ ] <EOL> for op in action . operations : <EOL> if op . vtType == '<STR_LIT>' : <EOL> delete_ops . append ( op ) <EOL> if op . vtType == '<STR_LIT>' : <EOL> add_ops . append ( op ) <EOL> if len ( delete_ops ) != len ( add_ops ) : <EOL> return ( remap , False ) <EOL> add_ops . reverse ( ) <EOL> for deleted , added in zip ( delete_ops , add_ops ) : <EOL> if deleted . what != added . what : <EOL> return ( remap , False ) <EOL> if added . what == '<STR_LIT>' : <EOL> remap [ ( Module . vtType , deleted . db_objectId ) ] = added . db_objectId <EOL> if added . what == '<STR_LIT>' : <EOL> if len ( delete_ops ) != len ( add_ops ) : <EOL> return ( remap , False ) <EOL> remap [ ( ModuleFunction . vtType , deleted . db_objectId ) ] = added . db_objectId <EOL> if added . what == '<STR_LIT>' : <EOL> if len ( delete_ops ) != len ( add_ops ) : <EOL> return ( remap , False ) <EOL> remap [ ( ModuleParam . vtType , deleted . db_objectId ) ] = added . db_objectId <EOL> return ( remap , is_full_remap ) <EOL> def create_upgrade_action ( self , actions ) : <EOL> new_action = vistrails . core . db . action . merge_actions ( actions ) <EOL> self . set_action_annotation ( new_action , Action . ANNOTATION_DESCRIPTION , <EOL> "<STR_LIT>" ) <EOL> return new_action <EOL> def check_delayed_update ( self ) : <EOL> if self . delayed_update : <EOL> self . delayed_update = False <EOL> self . set_changed ( True ) <EOL> self . recompute_terse_graph ( ) <EOL> self . invalidate_version_tree ( False ) <EOL> def handle_invalid_pipeline ( self , e , new_version = - <NUM_LIT:1> , vistrail = None , <EOL> report_all_errors = False , force_no_delay = False , <EOL> delay_update = False , level = <NUM_LIT:0> , pipeline_only = False ) : <EOL> debug . debug ( '<STR_LIT>' % new_version ) <EOL> if delay_update : <EOL> force_no_delay = True <EOL> def check_exceptions ( exception_set ) : <EOL> unhandled_exceptions = [ ] <EOL> for err in exception_set : <EOL> if isinstance ( err , InvalidPipeline ) : <EOL> sub_exceptions = check_exceptions ( err . get_exception_set ( ) ) <EOL> if len ( sub_exceptions ) > <NUM_LIT:0> : <EOL> new_err = InvalidPipeline ( sub_exceptions , <EOL> err . _pipeline , <EOL> err . _version ) <EOL> unhandled_exceptions . append ( new_err ) <EOL> else : <EOL> if not err . _was_handled : <EOL> unhandled_exceptions . append ( err ) <EOL> return unhandled_exceptions <EOL> load_other_versions = False <EOL> if vistrail is None : <EOL> vistrail = self . vistrail <EOL> pm = get_package_manager ( ) <EOL> root_exceptions = e . get_exception_set ( ) <EOL> missing_packages = { } <EOL> def process_missing_packages ( exception_set ) : <EOL> for err in exception_set : <EOL> err . _was_handled = False <EOL> if isinstance ( err , InvalidPipeline ) : <EOL> process_missing_packages ( err . get_exception_set ( ) ) <EOL> elif isinstance ( err , MissingPackage ) : <EOL> if err . _identifier not in missing_packages : <EOL> missing_packages [ err . _identifier ] = [ ] <EOL> missing_packages [ err . _identifier ] . append ( err ) <EOL> process_missing_packages ( root_exceptions ) <EOL> new_exceptions = [ ] <EOL> dep_graph = pm . build_dependency_graph ( missing_packages . keys ( ) ) <EOL> deps = pm . get_ordered_dependencies ( dep_graph ) <EOL> missing = set ( missing_packages . iterkeys ( ) ) <EOL> enable_pkgs = reversed ( [ pkg_id <EOL> for pkg_id in deps <EOL> if pkg_id in missing ] ) <EOL> for identifier in enable_pkgs : <EOL> if not pm . has_package ( identifier ) : <EOL> try : <EOL> if self . try_to_enable_package ( identifier ) : <EOL> for err in missing_packages [ identifier ] : <EOL> err . _was_handled = True <EOL> except Exception , new_e : <EOL> debug . unexpected_exception ( new_e ) <EOL> new_exceptions . append ( new_e ) <EOL> if not report_all_errors : <EOL> raise new_e <EOL> else : <EOL> if identifier in missing_packages . iterkeys ( ) : <EOL> for err in missing_packages [ identifier ] : <EOL> err . _was_handled = True <EOL> if len ( new_exceptions ) > <NUM_LIT:0> : <EOL> raise InvalidPipeline ( check_exceptions ( root_exceptions ) + new_exceptions , <EOL> e . _pipeline , new_version ) <EOL> def process_package_versions ( exception_set ) : <EOL> for err in exception_set : <EOL> if err . _was_handled : <EOL> continue <EOL> if isinstance ( err , InvalidPipeline ) : <EOL> process_package_versions ( err . get_exception_set ( ) ) <EOL> if isinstance ( err , MissingPackageVersion ) : <EOL> err . _was_handled = True <EOL> pass <EOL> if load_other_versions : <EOL> process_package_versions ( root_exceptions ) <EOL> def process_package_exceptions ( exception_set , pipeline ) : <EOL> new_actions = [ ] <EOL> package_errs = { } <EOL> for err in exception_set : <EOL> if err . _was_handled : <EOL> continue <EOL> if isinstance ( err , InvalidPipeline ) : <EOL> id_scope = IdScope ( <NUM_LIT:1> , { Group . vtType : Module . vtType , <EOL> Abstraction . vtType : Module . vtType } ) <EOL> id_remap = { } <EOL> new_pipeline = err . _pipeline . do_copy ( True , id_scope , <EOL> id_remap ) <EOL> new_exception_set = [ ] <EOL> for sub_err in err . get_exception_set ( ) : <EOL> key = ( Module . vtType , sub_err . _module_id ) <EOL> if key in id_remap : <EOL> sub_err . _module_id = id_remap [ key ] <EOL> new_exception_set . append ( sub_err ) <EOL> else : <EOL> new_exception_set . append ( sub_err ) <EOL> new_pipeline . id = None <EOL> old_id_scope = self . id_scope <EOL> self . id_scope = id_scope <EOL> try : <EOL> _ , new_pipeline = self . handle_invalid_pipeline ( err , <EOL> report_all_errors = True , <EOL> pipeline_only = True ) <EOL> except InvalidPipeline , e : <EOL> debug . unexpected_exception ( e ) <EOL> raise e <EOL> finally : <EOL> self . id_scope = old_id_scope <EOL> if new_pipeline != err . _pipeline : <EOL> old_module = pipeline . modules [ err . _module_id ] <EOL> if old_module . is_group ( ) : <EOL> my_actions = UpgradeWorkflowHandler . replace_group ( <EOL> self , pipeline , old_module . id , new_pipeline ) <EOL> for action in my_actions : <EOL> pipeline . perform_action ( action ) <EOL> new_actions . extend ( my_actions ) <EOL> elif ( isinstance ( err , MissingModule ) or <EOL> isinstance ( err , MissingPackageVersion ) or <EOL> isinstance ( err , MissingModuleVersion ) ) : <EOL> if err . _identifier not in package_errs : <EOL> package_errs [ err . _identifier ] = [ ] <EOL> package_errs [ err . _identifier ] . append ( err ) <EOL> for identifier , err_list in package_errs . iteritems ( ) : <EOL> try : <EOL> pkg = pm . get_package ( identifier ) <EOL> except MissingPackage : <EOL> continue <EOL> details = '<STR_LIT:\n>' . join ( debug . format_exception ( e ) <EOL> for e in err_list ) <EOL> debug . debug ( '<STR_LIT>' % <EOL> identifier , details ) <EOL> if pkg . can_handle_all_errors ( ) : <EOL> try : <EOL> actions = pkg . handle_all_errors ( self , err_list , <EOL> pipeline ) <EOL> if actions is not None : <EOL> for action in actions : <EOL> pipeline . perform_action ( action ) <EOL> new_actions . extend ( actions ) <EOL> for err in err_list : <EOL> err . _was_handled = True <EOL> except Exception , new_e : <EOL> debug . unexpected_exception ( new_e ) <EOL> new_exceptions . append ( new_e ) <EOL> if not report_all_errors : <EOL> return new_actions <EOL> else : <EOL> for err in err_list : <EOL> try : <EOL> actions = UpgradeWorkflowHandler . dispatch_request ( <EOL> self , err . _module_id , pipeline ) <EOL> if actions is not None : <EOL> for action in actions : <EOL> pipeline . perform_action ( action ) <EOL> new_actions . extend ( actions ) <EOL> err . _was_handled = True <EOL> except Exception , new_e : <EOL> debug . unexpected_exception ( new_e ) <EOL> new_exceptions . append ( new_e ) <EOL> if pkg . can_handle_missing_modules ( ) : <EOL> for err in err_list + new_exceptions : <EOL> if hasattr ( err , '<STR_LIT>' ) and err . _was_handled : <EOL> continue <EOL> if isinstance ( err , MissingModule ) : <EOL> try : <EOL> res = pkg . handle_missing_module ( self , <EOL> err . _module_id , <EOL> pipeline ) <EOL> if res is True : <EOL> err . _was_handled = True <EOL> elif res is False : <EOL> pass <EOL> else : <EOL> actions = res <EOL> if actions is not None : <EOL> for action in actions : <EOL> pipeline . perform_action ( action ) <EOL> new_actions . extend ( actions ) <EOL> err . _was_handled = True <EOL> except Exception , new_e : <EOL> debug . unexpected_exception ( new_e ) <EOL> new_exceptions . append ( new_e ) <EOL> if not report_all_errors : <EOL> return new_actions <EOL> return new_actions <EOL> if get_vistrails_configuration ( ) . check ( '<STR_LIT>' ) : <EOL> cur_pipeline = copy . copy ( e . _pipeline ) <EOL> new_actions = process_package_exceptions ( root_exceptions , <EOL> cur_pipeline ) <EOL> else : <EOL> new_actions = [ ] <EOL> cur_pipeline = e . _pipeline <EOL> if not pipeline_only and len ( new_actions ) > <NUM_LIT:0> : <EOL> upgrade_action = self . create_upgrade_action ( new_actions ) <EOL> if ( get_vistrails_configuration ( ) . check ( '<STR_LIT>' ) and not force_no_delay <EOL> and self . _delayed_paramexps ) : <EOL> param_exps = self . _delayed_paramexps <EOL> self . _delayed_paramexps = [ ] <EOL> else : <EOL> param_exps = self . vistrail . get_paramexps ( new_version ) <EOL> new_param_exps = [ ] <EOL> if len ( param_exps ) > <NUM_LIT:0> : <EOL> ( module_remap , is_complete ) = self . get_upgrade_module_remap ( new_actions ) <EOL> if is_complete : <EOL> for pe in param_exps : <EOL> old_pe = None <EOL> while old_pe != pe : <EOL> old_pe = pe <EOL> pe = pe . do_copy ( True , self . id_scope , module_remap ) <EOL> new_param_exps . append ( pe ) <EOL> else : <EOL> debug . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> mashup = None <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> for mashuptrail in self . _mashups : <EOL> if mashuptrail . vtVersion == new_version : <EOL> mashup = mashuptrail <EOL> new_mashups = [ ] <EOL> if mashup : <EOL> force_no_delay = True <EOL> ( mfp_remap , is_complete ) = self . get_simple_upgrade_remap ( new_actions ) <EOL> if is_complete : <EOL> self . _mashups . remove ( mashup ) <EOL> for action in mashup . actions : <EOL> for alias in action . mashup . aliases : <EOL> c = alias . component <EOL> while ( Module . vtType , c . vtmid ) in mfp_remap : <EOL> c . vtmid = mfp_remap [ ( Module . vtType , c . vtmid ) ] <EOL> while ( ModuleFunction . vtType , <EOL> c . vtparent_id ) in mfp_remap : <EOL> c . vtparent_id = mfp_remap [ ( ModuleFunction . vtType , <EOL> c . vtparent_id ) ] <EOL> while ( ModuleParam . vtType , c . vtid ) in mfp_remap : <EOL> c . vtid = mfp_remap [ ( ModuleParam . vtType , <EOL> c . vtid ) ] <EOL> mashup . currentVersion = mashup . getLatestVersion ( ) <EOL> new_mashups . append ( mashup ) <EOL> else : <EOL> debug . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if get_vistrails_configuration ( ) . check ( '<STR_LIT>' ) and not force_no_delay : <EOL> self . _delayed_actions . append ( upgrade_action ) <EOL> self . _delayed_paramexps . extend ( new_param_exps ) <EOL> self . _delayed_mashups . extend ( new_mashups ) <EOL> else : <EOL> vistrail . add_action ( upgrade_action , new_version , <EOL> self . current_session ) <EOL> vistrail . set_upgrade ( new_version , str ( upgrade_action . id ) ) <EOL> if get_vistrails_configuration ( ) . check ( "<STR_LIT>" ) : <EOL> self . migrate_tags ( new_version , upgrade_action . id , vistrail ) <EOL> new_version = upgrade_action . id <EOL> for pe in new_param_exps : <EOL> pe . action_id = new_version <EOL> self . vistrail . db_add_parameter_exploration ( pe ) <EOL> for mashup in new_mashups : <EOL> mashup . vtVersion = new_version <EOL> for action in mashup . actions : <EOL> action . mashup . version = new_version <EOL> self . _mashups . append ( mashup ) <EOL> if delay_update : <EOL> self . delayed_update = True <EOL> else : <EOL> self . set_changed ( True ) <EOL> self . recompute_terse_graph ( ) <EOL> left_exceptions = check_exceptions ( root_exceptions ) <EOL> debug . debug ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( ( len ( root_exceptions ) - <EOL> len ( left_exceptions ) ) , <EOL> len ( left_exceptions ) , <EOL> len ( new_exceptions ) ) ) <EOL> if ( len ( left_exceptions ) == len ( root_exceptions ) and <EOL> len ( new_exceptions ) == <NUM_LIT:0> ) : <EOL> debug . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( new_version , <EOL> len ( root_exceptions ) ) ) <EOL> raise InvalidPipeline ( left_exceptions + new_exceptions , <EOL> cur_pipeline , new_version ) <EOL> new_err = None <EOL> if len ( left_exceptions ) > <NUM_LIT:0> or len ( new_exceptions ) > <NUM_LIT:0> : <EOL> new_err = InvalidPipeline ( left_exceptions + new_exceptions , <EOL> cur_pipeline , new_version ) <EOL> else : <EOL> try : <EOL> self . validate ( cur_pipeline ) <EOL> except InvalidPipeline , e : <EOL> e . _version = new_version <EOL> new_err = e <EOL> if new_err is not None : <EOL> level += <NUM_LIT:1> <EOL> max_loops = getattr ( get_vistrails_configuration ( ) , <EOL> '<STR_LIT>' , <NUM_LIT:50> ) <EOL> if level >= max_loops : <EOL> debug . critical ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % level ) <EOL> else : <EOL> debug . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( new_version , level ) ) <EOL> return self . handle_invalid_pipeline ( new_err , <EOL> new_version , <EOL> vistrail , <EOL> report_all_errors , <EOL> force_no_delay , <EOL> delay_update , <EOL> level , <EOL> pipeline_only ) <EOL> raise new_err <EOL> return new_version , cur_pipeline <EOL> def validate ( self , pipeline , raise_exception = True ) : <EOL> vistrail_vars = self . get_vistrail_variables ( ) <EOL> pipeline . validate ( raise_exception , vistrail_vars ) <EOL> def version_switch_cost ( self , descendant , ancestor ) : <EOL> """<STR_LIT>""" <EOL> cost = <NUM_LIT:0> <EOL> am = self . vistrail . actionMap <EOL> if descendant == - <NUM_LIT:1> : <EOL> descendant = <NUM_LIT:0> <EOL> while descendant != ancestor : <EOL> descendant = am [ descendant ] . parent <EOL> cost += <NUM_LIT:1> <EOL> return cost <EOL> def do_version_switch ( self , new_version , report_all_errors = False , <EOL> do_validate = True , from_root = False ) : <EOL> """<STR_LIT>""" <EOL> new_error = None <EOL> try : <EOL> self . current_pipeline = self . get_pipeline ( new_version , <EOL> do_validate = do_validate , <EOL> from_root = from_root , <EOL> use_current = True ) <EOL> self . current_version = new_version <EOL> except InvalidPipeline , e : <EOL> try : <EOL> self . current_version , self . current_pipeline = self . validate_version ( new_version , <EOL> report_all_errors , <EOL> from_root ) <EOL> except InvalidPipeline , e : <EOL> self . current_pipeline = e . _pipeline <EOL> self . current_version = e . _version <EOL> new_error = e <EOL> if new_version != self . current_version : <EOL> self . invalidate_version_tree ( False ) <EOL> if new_error is not None : <EOL> raise new_error <EOL> def validate_version ( self , version , report_all_errors = False , <EOL> from_root = False , delay_update = False , use_current = True ) : <EOL> """<STR_LIT>""" <EOL> def _validate_version ( version ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> pipeline = self . get_pipeline ( version , from_root = from_root , <EOL> use_current = use_current ) <EOL> except InvalidPipeline , e : <EOL> try : <EOL> version , pipeline = self . handle_invalid_pipeline ( e , version , <EOL> self . vistrail , <EOL> report_all_errors , <EOL> delay_update = delay_update ) <EOL> except InvalidPipeline , e : <EOL> debug . unexpected_exception ( e ) <EOL> raise e <EOL> return version , pipeline <EOL> try : <EOL> pipeline = self . get_pipeline ( version , from_root = from_root , <EOL> use_current = use_current ) <EOL> except InvalidPipeline : <EOL> upgrade_chain = self . vistrail . get_upgrade_chain ( version , True ) <EOL> upgrade_chain = [ v for v in upgrade_chain <EOL> if v in self . vistrail . actionMap and <EOL> not self . vistrail . is_pruned ( v ) ] <EOL> try : <EOL> return _validate_version ( upgrade_chain . pop ( ) ) <EOL> except InvalidPipeline , e : <EOL> while upgrade_chain : <EOL> try : <EOL> return _validate_version ( upgrade_chain . pop ( ) ) <EOL> except InvalidPipeline : <EOL> pass <EOL> raise e <EOL> return version , pipeline <EOL> def change_selected_version ( self , new_version , report_all_errors = True , <EOL> do_validate = True , from_root = False ) : <EOL> try : <EOL> self . do_version_switch ( new_version , report_all_errors , <EOL> do_validate , from_root ) <EOL> except InvalidPipeline , e : <EOL> def process_err ( err ) : <EOL> if isinstance ( err , Package . InitializationFailed ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % err . package . name ) <EOL> debug . critical ( msg ) <EOL> elif isinstance ( err , MissingPackage ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % err . _identifier ) <EOL> debug . critical ( msg ) <EOL> elif issubclass ( err . __class__ , MissingPort ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( err . _port_type , err . _port_name , <EOL> err . _module_name , err . _package_name ) <EOL> debug . critical ( msg ) <EOL> else : <EOL> debug . critical ( str ( err ) ) <EOL> if report_all_errors : <EOL> for err in e . _exception_set : <EOL> process_err ( err ) <EOL> elif len ( e . _exception_set ) > <NUM_LIT:0> : <EOL> process_err ( e . _exception_set . __iter__ ( ) . next ( ) ) <EOL> except Exception , e : <EOL> debug . critical ( "<STR_LIT>" , debug . format_exc ( ) ) <EOL> def write_temporary ( self ) : <EOL> if self . vistrail and self . changed : <EOL> locator = self . get_locator ( ) <EOL> if locator : <EOL> locator . save_temporary ( self . vistrail ) <EOL> def write_abstractions ( self , locator , save_bundle , abstractions , <EOL> abs_save_dir ) : <EOL> def make_abstraction_path_unique ( abs_fname , namespace ) : <EOL> path , prefix , absname , old_ns , suffix = parse_abstraction_name ( abs_fname , True ) <EOL> new_abs_fname = os . path . join ( abs_save_dir , <EOL> '<STR_LIT>' % ( prefix , absname , <EOL> namespace , suffix ) ) <EOL> shutil . copy ( abs_fname , new_abs_fname ) <EOL> return new_abs_fname <EOL> included_abstractions = { } <EOL> for abstraction_list in abstractions . itervalues ( ) : <EOL> for abstraction in abstraction_list : <EOL> abs_module = abstraction . module_descriptor . module <EOL> namespaces = set ( get_all_abs_namespaces ( abstraction . vistrail ) ) <EOL> if abs_module is not None : <EOL> abs_fname = abs_module . vt_fname <EOL> path , prefix , abs_name , old_ns , suffix = parse_abstraction_name ( abs_fname , True ) <EOL> if abs_name not in included_abstractions : <EOL> included_abstractions [ abs_name ] = [ ( abstraction , <EOL> namespaces ) ] <EOL> else : <EOL> new_list = [ ] <EOL> found = False <EOL> for ( i_abs , i_namespaces ) in included_abstractions [ abs_name ] : <EOL> if not ( i_namespaces < namespaces ) : <EOL> new_list . append ( ( i_abs , i_namespaces ) ) <EOL> if i_namespaces >= namespaces : <EOL> found = True <EOL> if not found : <EOL> new_list . append ( ( abstraction , namespaces ) ) <EOL> included_abstractions [ abs_name ] = new_list <EOL> for abs_name , abstraction_list in included_abstractions . iteritems ( ) : <EOL> for ( abstraction , _ ) in abstraction_list : <EOL> abs_module = abstraction . module_descriptor . module <EOL> if abs_module is None : <EOL> continue <EOL> abs_fname = abs_module . vt_fname <EOL> if not os . path . exists ( abs_fname ) : <EOL> abs_fname = os . path . join ( abs_save_dir , <EOL> abstraction . name + '<STR_LIT>' ) <EOL> save_abstraction ( abstraction . vistrail , abs_fname ) <EOL> namespace = get_cur_abs_namespace ( abstraction . vistrail ) <EOL> abs_unique_name = make_abstraction_path_unique ( abs_fname , <EOL> namespace ) <EOL> save_bundle . abstractions . append ( abs_unique_name ) <EOL> def write_vistrail ( self , locator , version = None , export = False ) : <EOL> """<STR_LIT>""" <EOL> result = False <EOL> if self . vistrail and ( self . changed or self . locator != locator ) : <EOL> if self . jobMonitor . workflows : <EOL> self . vistrail . set_annotation ( '<STR_LIT>' , <EOL> self . jobMonitor . serialize ( ) ) <EOL> else : <EOL> self . vistrail . set_annotation ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> abs_save_dir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> is_abstraction = self . vistrail . is_abstraction <EOL> if is_abstraction and self . changed : <EOL> self . check_subpipeline_port_names ( ) <EOL> new_namespace = str ( uuid . uuid1 ( ) ) <EOL> annotation_key = get_next_abs_annotation_key ( self . vistrail ) <EOL> self . vistrail . set_annotation ( annotation_key , new_namespace ) <EOL> save_bundle = SaveBundle ( self . vistrail . vtType ) <EOL> if export : <EOL> save_bundle . vistrail = self . vistrail . do_copy ( ) <EOL> if isinstance ( locator , vistrails . core . db . locator . DBLocator ) : <EOL> save_bundle . vistrail . db_log_filename = None <EOL> else : <EOL> save_bundle . vistrail = self . vistrail <EOL> if self . log and len ( self . log . workflow_execs ) > <NUM_LIT:0> : <EOL> save_bundle . log = self . log <EOL> abstractions = self . find_abstractions ( self . vistrail , True ) <EOL> self . write_abstractions ( locator , save_bundle , abstractions , <EOL> abs_save_dir ) <EOL> thumb_cache = ThumbnailCache . getInstance ( ) <EOL> if thumb_cache . conf . autoSave : <EOL> save_bundle . thumbnails = self . find_thumbnails ( <EOL> tags_only = thumb_cache . conf . tagsOnly ) <EOL> save_bundle . mashups = self . _mashups <EOL> self . vistrail . db_currentVersion = self . current_version <EOL> if self . locator != locator : <EOL> log = Log ( ) <EOL> if isinstance ( self . locator , vistrails . core . db . locator . DBLocator ) : <EOL> connection = self . locator . get_connection ( ) <EOL> db_log = open_vt_log_from_db ( connection , <EOL> self . vistrail . db_id ) <EOL> Log . convert ( db_log ) <EOL> for workflow_exec in db_log . workflow_execs : <EOL> workflow_exec . db_id = log . id_scope . getNewId ( DBWorkflowExec . vtType ) <EOL> log . db_add_workflow_exec ( workflow_exec ) <EOL> if self . log and len ( self . log . workflow_execs ) > <NUM_LIT:0> : <EOL> for workflow_exec in self . log . db_workflow_execs : <EOL> workflow_exec = copy . copy ( workflow_exec ) <EOL> workflow_exec . db_id = log . id_scope . getNewId ( DBWorkflowExec . vtType ) <EOL> log . db_add_workflow_exec ( workflow_exec ) <EOL> if len ( log . workflow_execs ) > <NUM_LIT:0> : <EOL> save_bundle . log = log <EOL> old_locator = self . get_locator ( ) <EOL> if not export : <EOL> self . locator = locator <EOL> save_bundle = locator . save_as ( save_bundle , version ) <EOL> new_vistrail = save_bundle . vistrail <EOL> if isinstance ( locator , vistrails . core . db . locator . DBLocator ) : <EOL> new_vistrail . db_log_filename = None <EOL> locator . kwargs [ '<STR_LIT>' ] = new_vistrail . db_id <EOL> if not export : <EOL> self . ensure_abstractions_loaded ( new_vistrail , <EOL> save_bundle . abstractions ) <EOL> self . set_file_name ( locator . name ) <EOL> if old_locator and not export : <EOL> old_locator . clean_temporaries ( ) <EOL> old_locator . close ( ) <EOL> self . flush_pipeline_cache ( ) <EOL> self . change_selected_version ( new_vistrail . db_currentVersion , <EOL> from_root = True ) <EOL> else : <EOL> save_bundle = self . locator . save ( save_bundle ) <EOL> new_vistrail = save_bundle . vistrail <EOL> self . ensure_abstractions_loaded ( new_vistrail , <EOL> save_bundle . abstractions ) <EOL> if is_abstraction : <EOL> new_vistrail . is_abstraction = True <EOL> if isinstance ( self . locator , ( <EOL> vistrails . core . db . locator . XMLFileLocator , <EOL> vistrails . core . db . locator . ZIPFileLocator ) ) : <EOL> filename = self . locator . name <EOL> if filename in self . _loaded_abstractions : <EOL> del self . _loaded_abstractions [ filename ] <EOL> self . load_abstraction ( filename , False ) <EOL> if not export : <EOL> if id ( self . vistrail ) != id ( new_vistrail ) : <EOL> new_version = new_vistrail . db_currentVersion <EOL> self . set_vistrail ( new_vistrail , locator ) <EOL> self . change_selected_version ( new_version ) <EOL> result = True <EOL> if self . log : <EOL> self . log . delete_all_workflow_execs ( ) <EOL> self . set_changed ( False ) <EOL> locator . clean_temporaries ( ) <EOL> try : <EOL> for root , _ , files in os . walk ( abs_save_dir , topdown = False ) : <EOL> for name in files : <EOL> os . remove ( os . path . join ( root , name ) ) <EOL> os . rmdir ( abs_save_dir ) <EOL> except OSError , e : <EOL> raise VistrailsDBException ( "<STR_LIT>" % ( <EOL> abs_save_dir , <EOL> debug . format_exception ( e ) ) ) <EOL> return result <EOL> def write_workflow ( self , locator , version = None ) : <EOL> if self . current_pipeline : <EOL> pipeline = Pipeline ( ) <EOL> for module in self . current_pipeline . modules . itervalues ( ) : <EOL> pipeline . add_module ( module ) <EOL> for connection in self . current_pipeline . connections . itervalues ( ) : <EOL> pipeline . add_connection ( connection ) <EOL> save_bundle = SaveBundle ( pipeline . vtType , workflow = pipeline ) <EOL> locator . save_as ( save_bundle , version ) <EOL> def write_log ( self , locator ) : <EOL> if self . log : <EOL> if self . vistrail . db_log_filename is not None : <EOL> log = vistrails . core . db . io . merge_logs ( self . log , <EOL> self . vistrail . db_log_filename ) <EOL> else : <EOL> log = self . log <EOL> save_bundle = SaveBundle ( log . vtType , log = log ) <EOL> locator . save_as ( save_bundle ) <EOL> def read_log ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . vistrail . get_persisted_log ( ) <EOL> def write_registry ( self , locator ) : <EOL> registry = vistrails . core . modules . module_registry . get_module_registry ( ) <EOL> save_bundle = SaveBundle ( registry . vtType , registry = registry ) <EOL> locator . save_as ( save_bundle ) <EOL> def update_checkout_version ( self , app = '<STR_LIT>' ) : <EOL> self . vistrail . update_checkout_version ( app ) <EOL> def layout_modules ( self , old_modules = [ ] , preserve_order = False , <EOL> new_modules = [ ] , new_connections = [ ] , module_size_func = None , no_gaps = False ) : <EOL> """<STR_LIT>""" <EOL> self . flush_delayed_actions ( ) <EOL> action_list = self . layout_modules_ops ( old_modules , preserve_order , <EOL> new_modules , new_connections , module_size_func , no_gaps ) <EOL> if ( len ( action_list ) > <NUM_LIT:0> ) : <EOL> action = vistrails . core . db . action . create_action ( action_list ) <EOL> self . add_new_action ( action ) <EOL> version = self . perform_action ( action ) <EOL> self . change_selected_version ( version ) <EOL> return version <EOL> return self . current_version <EOL> def layout_modules_ops ( self , old_modules = [ ] , preserve_order = False , <EOL> new_modules = [ ] , new_connections = [ ] , module_size_func = None , no_gaps = False ) : <EOL> """<STR_LIT>""" <EOL> connected_input_ports = set ( <EOL> c . destination . spec for c in self . current_pipeline . connection_list ) <EOL> connected_input_ports . update ( <EOL> c . destination . spec for c in new_connections ) <EOL> connected_output_ports = set ( <EOL> c . source . spec for c in self . current_pipeline . connection_list ) <EOL> connected_output_ports . update ( <EOL> c . source . spec for c in new_connections ) <EOL> connected_ports = connected_input_ports | connected_output_ports <EOL> def get_visible_port_names ( port_list , visible_ports ) : <EOL> output_list = [ ] <EOL> visible_list = [ ] <EOL> for i , p in enumerate ( port_list ) : <EOL> if not p . optional : <EOL> output_list . append ( p . name ) <EOL> elif p . name in visible_ports or p in connected_ports : <EOL> visible_list . append ( p . name ) <EOL> output_list . extend ( visible_list ) <EOL> return output_list <EOL> if not old_modules or len ( old_modules ) == <NUM_LIT:0> : <EOL> old_modules = self . current_pipeline . modules . values ( ) <EOL> layoutPipeline = LayoutPipeline ( ) <EOL> module_info = { } <EOL> def _add_layout_module ( module , prev_x ) : <EOL> in_ports = get_visible_port_names ( module . destinationPorts ( ) , <EOL> module . visible_input_ports ) <EOL> out_ports = get_visible_port_names ( module . sourcePorts ( ) , <EOL> module . visible_output_ports ) <EOL> layoutModule = layoutPipeline . createModule ( module . id , <EOL> module . name , <EOL> len ( in_ports ) , <EOL> len ( out_ports ) , <EOL> prev_x ) <EOL> module_info [ module . id ] = ( module , layoutModule , in_ports , out_ports ) <EOL> for module in old_modules : <EOL> _add_layout_module ( module , module . location . x ) <EOL> for module in new_modules : <EOL> _add_layout_module ( module , None ) <EOL> old_ids = [ module . id for module in old_modules ] <EOL> old_conns = self . get_connections_to ( self . current_pipeline , old_ids ) <EOL> for conn in old_conns + new_connections : <EOL> if conn . source . moduleId in module_info : <EOL> layoutPipeline . createConnection ( <EOL> module_info [ conn . source . moduleId ] [ <NUM_LIT:1> ] , <EOL> module_info [ conn . source . moduleId ] [ <NUM_LIT:3> ] . index ( conn . source . name ) , <EOL> module_info [ conn . destination . moduleId ] [ <NUM_LIT:1> ] , <EOL> module_info [ conn . destination . moduleId ] [ <NUM_LIT:2> ] . index ( conn . destination . name ) ) <EOL> paddedPortWidth = self . layoutTheme . PORT_WIDTH + self . layoutTheme . MODULE_PORT_SPACE <EOL> def estimate_module_size ( module ) : <EOL> width = max ( len ( module . name ) * <NUM_LIT:6> + self . layoutTheme . MODULE_LABEL_MARGIN [ <NUM_LIT:0> ] + self . layoutTheme . MODULE_LABEL_MARGIN [ <NUM_LIT:1> ] , <EOL> len ( module_info [ module . shortname ] [ <NUM_LIT:2> ] ) * paddedPortWidth + self . layoutTheme . MODULE_PORT_PADDED_SPACE , <EOL> len ( module_info [ module . shortname ] [ <NUM_LIT:3> ] ) * paddedPortWidth + self . layoutTheme . MODULE_PORT_PADDED_SPACE ) <EOL> height = LayoutDefaults . u * <NUM_LIT:5> <EOL> return ( width , height ) <EOL> if module_size_func is None : <EOL> module_size_func = estimate_module_size <EOL> workflowLayout = WorkflowLayout ( layoutPipeline , <EOL> module_size_func , <EOL> self . layoutTheme . MODULE_PORT_MARGIN , <EOL> ( self . layoutTheme . PORT_WIDTH , self . layoutTheme . PORT_HEIGHT ) , <EOL> self . layoutTheme . MODULE_PORT_SPACE ) <EOL> workflowLayout . run_all ( <NUM_LIT:50> , <NUM_LIT:50> , preserve_order , no_gaps ) <EOL> center_x , center_y = self . get_avg_location ( [ item [ <NUM_LIT:0> ] for item in module_info . values ( ) ] ) <EOL> new_center_x = sum ( [ m . layout_pos . x for m in layoutPipeline . modules ] ) / len ( layoutPipeline . modules ) <EOL> new_center_y = - sum ( [ m . layout_pos . y for m in layoutPipeline . modules ] ) / len ( layoutPipeline . modules ) <EOL> offset_x = center_x - new_center_x <EOL> offset_y = center_y - new_center_y <EOL> moves = [ ] <EOL> for ( module , layoutModule , _ , _ ) in module_info . values ( ) : <EOL> new_x = layoutModule . layout_pos . x + offset_x <EOL> new_y = - layoutModule . layout_pos . y + offset_y <EOL> if module . id in self . current_pipeline . modules : <EOL> moves . append ( ( module . id , new_x , new_y ) ) <EOL> else : <EOL> module . location . x = new_x <EOL> module . location . y = new_y <EOL> return self . move_modules_ops ( moves ) <EOL> def get_pipeline ( self , version , allow_fail = False , use_current = False , <EOL> do_validate = True , from_root = False ) : <EOL> """<STR_LIT>""" <EOL> if use_current and self . current_version != - <NUM_LIT:1> and not self . current_pipeline : <EOL> debug . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if use_current and version != self . current_version : <EOL> if len ( self . _delayed_actions ) > <NUM_LIT:0> : <EOL> self . clear_delayed_actions ( ) <EOL> self . current_pipeline = Pipeline ( ) <EOL> self . current_version = <NUM_LIT:0> <EOL> if version == - <NUM_LIT:1> : <EOL> return None <EOL> if from_root : <EOL> result = self . vistrail . getPipeline ( version ) <EOL> elif use_current and version == self . current_version : <EOL> result = self . current_pipeline <EOL> if self . current_pipeline . is_valid : <EOL> return result <EOL> elif version in self . _pipelines : <EOL> result = copy . copy ( self . _pipelines [ version ] ) <EOL> else : <EOL> cv = self . _current_full_graph . inverse_immutable ( ) . closest_vertex <EOL> closest = cv ( version , self . _pipelines ) <EOL> if use_current : <EOL> cost_to_closest_version = self . version_switch_cost ( version , <EOL> closest ) <EOL> shared_parent = getSharedRoot ( self . vistrail , <EOL> [ self . current_version , <EOL> version ] ) <EOL> cost_common_to_old = self . version_switch_cost ( <EOL> self . current_version , shared_parent ) <EOL> cost_common_to_new = self . version_switch_cost ( version , <EOL> shared_parent ) <EOL> cost_to_current_version = cost_common_to_old + cost_common_to_new <EOL> else : <EOL> cost_to_closest_version = <NUM_LIT:0> <EOL> cost_to_current_version = <NUM_LIT:1> <EOL> if cost_to_closest_version < cost_to_current_version : <EOL> if closest == <NUM_LIT:0> : <EOL> result = self . vistrail . getPipeline ( version ) <EOL> else : <EOL> result = copy . copy ( self . _pipelines [ closest ] ) <EOL> action = self . vistrail . general_action_chain ( closest , <EOL> version ) <EOL> result . perform_action ( action ) <EOL> else : <EOL> action = self . vistrail . general_action_chain ( self . current_version , <EOL> version ) <EOL> if self . current_version == - <NUM_LIT:1> or self . current_version == <NUM_LIT:0> : <EOL> result = Pipeline ( ) <EOL> else : <EOL> result = copy . copy ( self . current_pipeline ) <EOL> result . perform_action ( action ) <EOL> if self . _cache_pipelines and self . get_tag ( long ( version ) ) : <EOL> if do_validate : <EOL> try : <EOL> self . validate ( result ) <EOL> except InvalidPipeline : <EOL> if not allow_fail : <EOL> raise <EOL> else : <EOL> self . _pipelines [ version ] = copy . copy ( result ) <EOL> else : <EOL> self . _pipelines [ version ] = copy . copy ( result ) <EOL> if do_validate : <EOL> try : <EOL> self . validate ( result ) <EOL> except InvalidPipeline : <EOL> if not allow_fail : <EOL> raise <EOL> return result <EOL> def get_tag ( self , version_number ) : <EOL> if not getattr ( get_vistrails_configuration ( ) , <EOL> '<STR_LIT>' , True ) : <EOL> return self . vistrail . getVersionName ( version_number ) <EOL> tag = self . vistrail . search_upgrade_versions ( <EOL> version_number , <EOL> lambda vt , v , bv : vt . getVersionName ( v ) or None ) or '<STR_LIT>' <EOL> return tag <EOL> def get_tagged_version ( self , version_number ) : <EOL> if not getattr ( get_vistrails_configuration ( ) , <EOL> '<STR_LIT>' , True ) : <EOL> return version_number <EOL> def is_tagged ( vt , v ) : <EOL> return v if vt . getVersionName ( v ) else None <EOL> tagged_version = self . vistrail . search_upgrade_versions ( <EOL> version_number , <EOL> lambda vt , v , bv : is_tagged ( vt , v ) ) or version_number <EOL> return tagged_version <EOL> def get_notes ( self , version_number ) : <EOL> if not getattr ( get_vistrails_configuration ( ) , <EOL> '<STR_LIT>' , True ) : <EOL> return self . vistrail . get_notes ( version_number ) <EOL> notes = self . vistrail . search_upgrade_versions ( <EOL> version_number , <EOL> lambda vt , v , bv : vt . get_notes ( v ) or None ) <EOL> return notes <EOL> def create_upgrade ( self , version , delay_update = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . get_pipeline ( version ) <EOL> except InvalidPipeline as e : <EOL> if version == self . current_version : <EOL> self . flush_delayed_actions ( delay_update = delay_update ) <EOL> try : <EOL> version , _ = self . validate_version ( version , <EOL> delay_update = delay_update , <EOL> use_current = False ) <EOL> except InvalidPipeline as e : <EOL> debug . unexpected_exception ( e ) <EOL> version = e . _version <EOL> return version <EOL> import unittest <EOL> class TestTerseGraph ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> pm = vistrails . core . packagemanager . get_package_manager ( ) <EOL> if pm . has_package ( '<STR_LIT>' ) : <EOL> return <EOL> d = { '<STR_LIT>' : '<STR_LIT>' } <EOL> pm . late_enable_package ( '<STR_LIT>' , d ) <EOL> cls . maxDiff = None <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> manager = vistrails . core . packagemanager . get_package_manager ( ) <EOL> if manager . has_package ( '<STR_LIT>' ) : <EOL> manager . late_disable_package ( '<STR_LIT>' ) <EOL> def get_workflow ( self , name ) : <EOL> from vistrails . core . db . locator import XMLFileLocator <EOL> from vistrails . core . system import vistrails_root_directory <EOL> locator = XMLFileLocator ( vistrails_root_directory ( ) + <EOL> '<STR_LIT>' + name ) <EOL> vistrail = locator . load ( ) <EOL> return VistrailController ( vistrail , locator ) <EOL> def test_workflow1_upgrades ( self ) : <EOL> """<STR_LIT>""" <EOL> controller = self . get_workflow ( '<STR_LIT>' ) <EOL> controller . recompute_terse_graph ( True ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:1> L , ( False , False ) ) , ( <NUM_LIT:5> L , ( False , False ) ) , ( <NUM_LIT:16> L , ( True , False ) ) ] , <EOL> <NUM_LIT:1> L : [ ( <NUM_LIT:3> L , ( True , False ) ) ] , <EOL> <NUM_LIT:3> L : [ ( <NUM_LIT:4> L , ( False , False ) ) ] , <EOL> <NUM_LIT:5> L : [ ( <NUM_LIT:8> L , ( True , False ) ) , ( <NUM_LIT:10> L , ( True , False ) ) ] , <EOL> <NUM_LIT:10> L : [ ( <NUM_LIT:11> L , ( False , False ) ) , ( <NUM_LIT> L , ( True , False ) ) ] , <EOL> <NUM_LIT:4> L : [ ] , <NUM_LIT:8> L : [ ] , <NUM_LIT:11> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT:16> L : [ ] , <EOL> } ) <EOL> controller . expand_all_versions_below ( <NUM_LIT:0> ) <EOL> controller . recompute_terse_graph ( True ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:1> L , ( False , False ) ) , ( <NUM_LIT:5> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , True ) ) ] , <EOL> <NUM_LIT:1> L : [ ( <NUM_LIT:2> L , ( False , True ) ) ] , <EOL> <NUM_LIT:2> L : [ ( <NUM_LIT:3> L , ( False , False ) ) ] , <EOL> <NUM_LIT:3> L : [ ( <NUM_LIT:4> L , ( False , False ) ) ] , <EOL> <NUM_LIT:5> L : [ ( <NUM_LIT:6> L , ( False , True ) ) , ( <NUM_LIT:9> L , ( False , True ) ) ] , <EOL> <NUM_LIT:6> L : [ ( <NUM_LIT:7> L , ( False , False ) ) ] , <EOL> <NUM_LIT:7> L : [ ( <NUM_LIT:8> L , ( False , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:10> L , ( False , False ) ) ] , <EOL> <NUM_LIT:10> L : [ ( <NUM_LIT:11> L , ( False , False ) ) , ( <NUM_LIT:12> L , ( False , True ) ) ] , <EOL> <NUM_LIT:12> L : [ ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT> L : [ ( <NUM_LIT:15> L , ( False , False ) ) ] , <EOL> <NUM_LIT:15> L : [ ( <NUM_LIT:16> L , ( False , False ) ) ] , <EOL> <NUM_LIT:4> L : [ ] , <NUM_LIT:8> L : [ ] , <NUM_LIT:11> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT:16> L : [ ] , <EOL> } ) <EOL> def test_workflow1_no_upgrades ( self ) : <EOL> """<STR_LIT>""" <EOL> controller = self . get_workflow ( '<STR_LIT>' ) <EOL> controller . recompute_terse_graph ( False ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:1> L , ( False , False ) ) , ( <NUM_LIT:5> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:1> L : [ ( <NUM_LIT:3> L , ( False , False ) ) ] , <EOL> <NUM_LIT:3> L : [ ( <NUM_LIT:4> L , ( False , False ) ) ] , <EOL> <NUM_LIT:5> L : [ ( <NUM_LIT:8> L , ( False , False ) ) , ( <NUM_LIT:9> L , ( False , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:11> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:4> L : [ ] , <NUM_LIT:8> L : [ ] , <NUM_LIT:11> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT> L : [ ] , <EOL> } ) <EOL> controller . expand_all_versions_below ( <NUM_LIT:0> ) <EOL> controller . recompute_terse_graph ( False ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:1> L , ( False , False ) ) , ( <NUM_LIT:5> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:1> L : [ ( <NUM_LIT:3> L , ( False , False ) ) ] , <EOL> <NUM_LIT:3> L : [ ( <NUM_LIT:4> L , ( False , False ) ) ] , <EOL> <NUM_LIT:5> L : [ ( <NUM_LIT:8> L , ( False , False ) ) , ( <NUM_LIT:9> L , ( False , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:11> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:4> L : [ ] , <NUM_LIT:8> L : [ ] , <NUM_LIT:11> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT> L : [ ] , <EOL> } ) <EOL> def test_workflow2_upgrades ( self ) : <EOL> """<STR_LIT>""" <EOL> controller = self . get_workflow ( '<STR_LIT>' ) <EOL> controller . recompute_terse_graph ( True ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:3> L , ( True , False ) ) , ( <NUM_LIT:9> L , ( True , False ) ) , ( <NUM_LIT:12> L , ( False , False ) ) ] , <EOL> <NUM_LIT:3> L : [ ( <NUM_LIT:7> L , ( True , False ) ) , ( <NUM_LIT:6> L , ( True , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:10> L , ( False , False ) ) , ( <NUM_LIT:11> L , ( False , False ) ) ] , <EOL> <NUM_LIT:12> L : [ ( <NUM_LIT> L , ( False , False ) ) , ( <NUM_LIT:15> L , ( False , False ) ) ] , <EOL> <NUM_LIT> L : [ ( <NUM_LIT> L , ( False , False ) ) , ( <NUM_LIT> L , ( True , False ) ) ] , <EOL> <NUM_LIT:7> L : [ ] , <NUM_LIT:6> L : [ ] , <NUM_LIT:10> L : [ ] , <NUM_LIT:11> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT:15> L : [ ] , <NUM_LIT> L : [ ] , <EOL> } ) <EOL> controller . expand_all_versions_below ( <NUM_LIT:0> ) <EOL> controller . recompute_terse_graph ( True ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:1> L , ( False , True ) ) , ( <NUM_LIT:8> L , ( False , True ) ) , ( <NUM_LIT:12> L , ( ( False , False ) ) ) ] , <EOL> <NUM_LIT:1> L : [ ( <NUM_LIT:2> L , ( False , False ) ) ] , <EOL> <NUM_LIT:2> L : [ ( <NUM_LIT:3> L , ( False , False ) ) ] , <EOL> <NUM_LIT:3> L : [ ( <NUM_LIT:4> L , ( False , True ) ) , ( <NUM_LIT:5> L , ( False , True ) ) ] , <EOL> <NUM_LIT:4> L : [ ( <NUM_LIT:7> L , ( False , False ) ) ] , <EOL> <NUM_LIT:5> L : [ ( <NUM_LIT:6> L , ( False , False ) ) ] , <EOL> <NUM_LIT:8> L : [ ( <NUM_LIT:9> L , ( False , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:10> L , ( False , False ) ) , ( <NUM_LIT:11> L , ( False , False ) ) ] , <EOL> <NUM_LIT:12> L : [ ( <NUM_LIT> L , ( False , False ) ) , ( <NUM_LIT:15> L , ( False , False ) ) ] , <EOL> <NUM_LIT> L : [ ( <NUM_LIT> L , ( False , False ) ) , ( <NUM_LIT:16> L , ( False , True ) ) ] , <EOL> <NUM_LIT:16> L : [ ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:7> L : [ ] , <NUM_LIT:6> L : [ ] , <NUM_LIT:10> L : [ ] , <NUM_LIT:11> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT:15> L : [ ] , <NUM_LIT> L : [ ] , <EOL> } ) <EOL> def test_workflow2_no_upgrades ( self ) : <EOL> """<STR_LIT>""" <EOL> controller = self . get_workflow ( '<STR_LIT>' ) <EOL> controller . recompute_terse_graph ( False ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:2> L , ( True , False ) ) , ( <NUM_LIT:9> L , ( True , False ) ) , ( <NUM_LIT> L , ( True , False ) ) ] , <EOL> <NUM_LIT:2> L : [ ( <NUM_LIT:4> L , ( False , False ) ) , ( <NUM_LIT:6> L , ( True , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:10> L , ( False , False ) ) ] , <EOL> <NUM_LIT> L : [ ( <NUM_LIT> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:4> L : [ ] , <NUM_LIT:6> L : [ ] , <NUM_LIT:10> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT> L : [ ] , <EOL> } ) <EOL> controller . expand_all_versions_below ( <NUM_LIT:0> ) <EOL> controller . recompute_terse_graph ( False ) <EOL> self . assertEqual ( controller . _current_terse_graph . adjacency_list , { <EOL> <NUM_LIT:0> : [ ( <NUM_LIT:1> L , ( False , True ) ) , ( <NUM_LIT:8> L , ( False , True ) ) , ( <NUM_LIT:12> L , ( ( False , True ) ) ) ] , <EOL> <NUM_LIT:1> L : [ ( <NUM_LIT:2> L , ( False , False ) ) ] , <EOL> <NUM_LIT:2> L : [ ( <NUM_LIT:4> L , ( False , False ) ) , ( <NUM_LIT:5> L , ( False , True ) ) ] , <EOL> <NUM_LIT:5> L : [ ( <NUM_LIT:6> L , ( False , False ) ) ] , <EOL> <NUM_LIT:8> L : [ ( <NUM_LIT:9> L , ( False , False ) ) ] , <EOL> <NUM_LIT:9> L : [ ( <NUM_LIT:10> L , ( False , False ) ) ] , <EOL> <NUM_LIT:12> L : [ ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT> L : [ ( <NUM_LIT> L , ( False , False ) ) , ( <NUM_LIT> L , ( False , False ) ) ] , <EOL> <NUM_LIT:4> L : [ ] , <NUM_LIT:6> L : [ ] , <NUM_LIT:10> L : [ ] , <NUM_LIT> L : [ ] , <NUM_LIT> L : [ ] , <EOL> } ) </s>
