<s> import sys <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> import os <EOL> os . environ [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> import copy <EOL> import datetime <EOL> import re <EOL> import urllib <EOL> from vistrails . db . domain import DBModule , DBConnection , DBPort , DBFunction , DBParameter , DBLocation , DBPortSpec , DBTag , DBAnnotation , DBVistrail , DBRegistry <EOL> import vistrails . db . services . io <EOL> from vistrails . db . services . io import SaveBundle <EOL> from vtk_imposter import vtk_module , vtk_function <EOL> class VTK2VT ( object ) : <EOL> vtk_data_url = '<STR_LIT>' <EOL> package_name = '<STR_LIT>' <EOL> basic_name = '<STR_LIT>' <EOL> pythoncalc_name = '<STR_LIT>' <EOL> http_name = '<STR_LIT>' <EOL> variant_sigstring = '<STR_LIT>' <EOL> unused_functions = set ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> translate_ports = { '<STR_LIT>' : { None : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> inspector_functions = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> getters = { '<STR_LIT>' : { None : ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None ) } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None ) } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , ) , <EOL> ( '<STR_LIT>' , ) , <EOL> ( '<STR_LIT>' , ) , <EOL> ( '<STR_LIT>' , ) ] ) } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None ) } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , '<STR_LIT>' , None ) } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , '<STR_LIT>' , None ) } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:8> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:8> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:4> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:6> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:5> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:4> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:4> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:2> ) ] ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) , <EOL> } , <EOL> '<STR_LIT>' : { None : ( '<STR_LIT>' , '<STR_LIT>' , None ) } , <EOL> } <EOL> set_file_name_pattern = re . compile ( '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> self . created_modules = { } <EOL> self . modules = { } <EOL> self . vt_modules = { } <EOL> self . vtk_modules = { } <EOL> self . connections = { } <EOL> self . vt_f_connections = { } <EOL> self . vt_b_connections = { } <EOL> self . max_module_id = <NUM_LIT:0> <EOL> self . max_location_id = <NUM_LIT:0> <EOL> self . max_function_id = <NUM_LIT:0> <EOL> self . max_parameter_id = <NUM_LIT:0> <EOL> self . max_connection_id = <NUM_LIT:0> <EOL> self . max_port_id = <NUM_LIT:0> <EOL> self . max_port_spec_id = <NUM_LIT:0> <EOL> self . http_module = None <EOL> r_file = '<STR_LIT>' <EOL> self . registry = vistrails . db . services . io . open_registry_from_xml ( r_file ) <EOL> self . registry_desc_idx = { } <EOL> for package in self . registry . db_packages : <EOL> for desc in package . db_module_descriptors : <EOL> self . registry_desc_idx [ desc . db_id ] = desc <EOL> def create_module ( self , module ) : <EOL> module_name = module . _name <EOL> package_name = self . package_name <EOL> if module_name == '<STR_LIT>' : <EOL> module_name = '<STR_LIT>' <EOL> elif module_name == '<STR_LIT>' : <EOL> return <EOL> elif module_name == '<STR_LIT>' or module_name == '<STR_LIT>' : <EOL> package_name = self . basic_name <EOL> elif module_name == '<STR_LIT>' : <EOL> package_name = self . pythoncalc_name <EOL> elif module_name == '<STR_LIT>' : <EOL> package_name = self . http_name <EOL> db_module = DBModule ( id = self . max_module_id , <EOL> name = module_name , <EOL> package = package_name , <EOL> location = DBLocation ( id = self . max_location_id , <EOL> x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> ) , <EOL> ) <EOL> self . max_module_id += <NUM_LIT:1> <EOL> self . max_location_id += <NUM_LIT:1> <EOL> self . modules [ id ( module ) ] = db_module <EOL> self . vt_modules [ db_module . db_id ] = db_module <EOL> self . vtk_modules [ id ( module ) ] = module <EOL> def save_modules ( self ) : <EOL> self . saved_functions = { } <EOL> for k , module in self . vtk_modules . iteritems ( ) : <EOL> self . saved_functions [ k ] = module . functions <EOL> module . functions = [ ] <EOL> def restore_modules ( self ) : <EOL> for k , module in self . vtk_modules . iteritems ( ) : <EOL> module . functions = self . saved_functions [ k ] <EOL> def do_layout ( self ) : <EOL> queue = [ ] <EOL> vt_b_connections = self . vt_f_connections <EOL> vt_f_connections = self . vt_b_connections <EOL> b_connections = copy . deepcopy ( vt_b_connections ) <EOL> f_connections = copy . deepcopy ( vt_f_connections ) <EOL> for m_id , module in self . vt_modules . iteritems ( ) : <EOL> if m_id not in b_connections : <EOL> queue . append ( ( module , <NUM_LIT:0> ) ) <EOL> t_sort = [ ] <EOL> for module , level in queue : <EOL> t_sort . append ( ( module , level ) ) <EOL> if module . db_id in f_connections : <EOL> for ( next_id , _ ) in f_connections [ module . db_id ] : <EOL> next_module = self . vt_modules [ next_id ] <EOL> if next_module . db_id in b_connections : <EOL> if len ( b_connections [ next_module . db_id ] ) == <NUM_LIT:0> : <EOL> continue <EOL> remaining_list = b_connections [ next_module . db_id ] [ : ] <EOL> for t in remaining_list : <EOL> if t [ <NUM_LIT:0> ] == module . db_id : <EOL> b_connections [ next_module . db_id ] . remove ( t ) <EOL> if len ( b_connections [ next_module . db_id ] ) == <NUM_LIT:0> : <EOL> queue . append ( ( next_module , level + <NUM_LIT:1> ) ) <EOL> levels = { } <EOL> module_levels = { } <EOL> for ( m , ell ) in t_sort : <EOL> if ell not in levels : <EOL> levels [ ell ] = [ ] <EOL> levels [ ell ] . append ( m ) <EOL> module_levels [ m . db_id ] = ell <EOL> for level , m_list in sorted ( levels . iteritems ( ) ) : <EOL> for i , m in enumerate ( m_list ) : <EOL> if i >= len ( m_list ) - <NUM_LIT:1> : <EOL> continue <EOL> m_next = m_list [ i + <NUM_LIT:1> ] <EOL> m_idxs = [ ] <EOL> m_next_idxs = [ ] <EOL> if m . db_id not in vt_b_connections : <EOL> continue <EOL> if m_next . db_id not in vt_b_connections : <EOL> continue <EOL> for ( n_id , _ ) in vt_b_connections [ m . db_id ] : <EOL> n = self . vt_modules [ n_id ] <EOL> n_idx = levels [ module_levels [ n_id ] ] . index ( n ) <EOL> m_idxs . append ( n_idx ) <EOL> for ( n_id , _ ) in vt_b_connections [ m_next . db_id ] : <EOL> n = self . vt_modules [ n_id ] <EOL> n_idx = levels [ module_levels [ n_id ] ] . index ( n ) <EOL> m_next_idxs . append ( n_idx ) <EOL> num_overlaps_f = <NUM_LIT:0> <EOL> num_overlaps_b = <NUM_LIT:0> <EOL> for m_idx in m_idxs : <EOL> for m_next_idx in m_next_idxs : <EOL> if m_idx == m_next_idx : <EOL> continue <EOL> elif m_idx < m_next_idx : <EOL> num_overlaps_b += <NUM_LIT:1> <EOL> else : <EOL> num_overlaps_f += <NUM_LIT:1> <EOL> if num_overlaps_f > num_overlaps_b : <EOL> swap = m_list [ i ] <EOL> m_list [ i ] = m_list [ i + <NUM_LIT:1> ] <EOL> m_list [ i + <NUM_LIT:1> ] = swap <EOL> dx = <NUM_LIT> <EOL> dy = <NUM_LIT> <EOL> current_y = <NUM_LIT:0.0> <EOL> for level , m_list in levels . iteritems ( ) : <EOL> current_x = - ( len ( m_list ) * dx ) / <NUM_LIT> <EOL> for m in m_list : <EOL> m . db_location . db_x = current_x <EOL> m . db_location . db_y = current_y <EOL> current_x += dx <EOL> current_y += dy <EOL> def get_vtk_cell ( self , interactor ) : <EOL> found_vtk_cell = False <EOL> if interactor . _name == '<STR_LIT>' : <EOL> found_vtk_cell = False <EOL> for function in interactor . functions : <EOL> if function . _name == '<STR_LIT>' and len ( function . _args ) == <NUM_LIT:1> and type ( function . _args [ <NUM_LIT:0> ] ) == vtk_module : <EOL> function_list = interactor . functions <EOL> module = function . _args [ <NUM_LIT:0> ] <EOL> found_vtk_cell = True <EOL> break <EOL> if found_vtk_cell : <EOL> return ( module , function_list ) <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> return ( None , None ) <EOL> def create_functions ( self , module , function_list = None , f_pos = <NUM_LIT:0> ) : <EOL> if module . _name == '<STR_LIT>' : <EOL> ( module , new_function_list ) = self . get_vtk_cell ( module ) <EOL> if not module : <EOL> return <EOL> else : <EOL> function_list = [ ] <EOL> for function in new_function_list [ : ] : <EOL> if type ( function . parent ) == vtk_module : <EOL> function . parent = module <EOL> if function . _name != '<STR_LIT>' : <EOL> function_list . append ( function ) <EOL> if function_list is None : <EOL> function_list = module . functions <EOL> for function in function_list : <EOL> db_function = self . create_function ( function , f_pos ) <EOL> if db_function : <EOL> self . modules [ id ( module ) ] . db_add_function ( db_function ) <EOL> f_pos += <NUM_LIT:1> <EOL> return f_pos <EOL> def find_or_create_module ( self , function , allow_sub = True ) : <EOL> parent_name = function . parent . _name <EOL> if function . _name . startswith ( '<STR_LIT>' ) and len ( function . _args ) == <NUM_LIT:0> and len ( function . sub_functions ) == <NUM_LIT:1> and function . sub_functions [ <NUM_LIT:0> ] . _name in self . inspector_functions : <EOL> inspector_name = self . inspector_functions [ function . sub_functions [ <NUM_LIT:0> ] . _name ] <EOL> key = ( id ( function . parent ) , function . _name ) <EOL> out_function = function . sub_functions [ <NUM_LIT:0> ] <EOL> if key in self . created_modules : <EOL> inspector_module = self . created_modules [ key ] <EOL> else : <EOL> inspector_module = vtk_module ( inspector_name ) <EOL> self . create_module ( inspector_module ) <EOL> self . created_modules [ key ] = inspector_module <EOL> in_function = vtk_function ( '<STR_LIT>' ) <EOL> in_function . parent = inspector_module <EOL> function . sub_functions = [ ] <EOL> in_function . _args = [ function ] <EOL> inspector_module . functions . append ( in_function ) <EOL> self . create_functions ( inspector_module , [ in_function ] ) <EOL> found = False <EOL> out_function . parent = inspector_module <EOL> for old_function in inspector_module . functions : <EOL> if old_function . _name == out_function . _name and ( len ( old_function . sub_functions ) == <NUM_LIT:0> or <EOL> len ( out_function . sub_functions ) == <NUM_LIT:0> or <EOL> old_function . sub_functions [ <NUM_LIT:0> ] . _name == old_function . sub_functions [ <NUM_LIT:0> ] . _name ) : <EOL> found = True <EOL> break <EOL> if not found : <EOL> inspector_module . functions . append ( out_function ) <EOL> self . create_functions ( inspector_module , [ out_function ] ) <EOL> return ( inspector_module , True ) <EOL> elif function . _name in self . getters and ( function . _name not in self . inspector_functions or <EOL> self . inspector_functions [ function . _name ] != function . parent . _name ) : <EOL> if not allow_sub : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> key = ( id ( function . parent ) , function . _name ) <EOL> if key in self . created_modules : <EOL> p_module = self . created_modules [ key ] <EOL> return ( p_module , False ) <EOL> if parent_name in self . getters [ function . _name ] : <EOL> ( setter , module_name , function_list ) = self . getters [ function . _name ] [ parent_name ] <EOL> else : <EOL> ( setter , module_name , function_list ) = self . getters [ function . _name ] [ None ] <EOL> found_setter = False <EOL> for p_function in function . parent . functions : <EOL> if p_function . _name == setter : <EOL> found_setter = True <EOL> for arg in p_function . _args : <EOL> if type ( arg ) == vtk_module : <EOL> p_module = arg <EOL> else : <EOL> if arg == function : <EOL> found_setter = False <EOL> else : <EOL> p_module = arg . parent <EOL> if found_setter and type ( p_module ) != vtk_module : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> found_setter = False <EOL> if found_setter : <EOL> self . create_functions ( p_module , function . sub_functions ) <EOL> return ( p_module , False ) <EOL> if not found_setter : <EOL> p_module = self . create_module_for_get ( function , setter , module_name , <EOL> function_list ) <EOL> return ( p_module , False ) <EOL> return ( None , False ) <EOL> def create_module_for_get ( self , function , setter , module_name , <EOL> function_list = None ) : <EOL> src_module = None <EOL> db_module = DBModule ( id = self . max_module_id , <EOL> name = module_name , <EOL> package = self . package_name , <EOL> location = DBLocation ( id = self . max_location_id , <EOL> x = <NUM_LIT:0.0> , y = <NUM_LIT:0.0> ) , <EOL> ) <EOL> self . max_module_id += <NUM_LIT:1> <EOL> self . max_location_id += <NUM_LIT:1> <EOL> src_module = vtk_module ( module_name ) <EOL> self . modules [ id ( src_module ) ] = db_module <EOL> self . vt_modules [ db_module . db_id ] = db_module <EOL> self . vtk_modules [ id ( src_module ) ] = src_module <EOL> if function_list : <EOL> src_functions = [ ] <EOL> for f in function_list : <EOL> src_function = vtk_function ( f [ <NUM_LIT:0> ] ) <EOL> if len ( f ) > <NUM_LIT:1> : <EOL> src_function . _args = list ( f [ <NUM_LIT:1> : ] ) <EOL> src_function . parent = src_module <EOL> src_functions . append ( src_function ) <EOL> self . create_functions ( src_module , src_functions ) <EOL> self . created_modules [ ( id ( function . parent ) , function . _name ) ] = src_module <EOL> dst_function = vtk_function ( setter ) <EOL> dst_function . parent = function . parent <EOL> self . create_connection ( src_module , dst_function ) <EOL> return src_module <EOL> def create_tuple ( self , function ) : <EOL> tuple_module = vtk_module ( '<STR_LIT>' ) <EOL> tuple_module . blah ( ) <EOL> self . create_module ( tuple_module ) <EOL> db_tuple_module = self . modules [ id ( tuple_module ) ] <EOL> tuple_f_pos = <NUM_LIT:0> <EOL> final_sigs = [ ] <EOL> for i , arg in enumerate ( function . _args ) : <EOL> port_spec = DBPortSpec ( id = self . max_port_spec_id , <EOL> name = '<STR_LIT>' + str ( i ) , <EOL> type = '<STR_LIT:input>' , <EOL> sigstring = self . variant_sigstring ) <EOL> db_tuple_module . db_add_portSpec ( port_spec ) <EOL> self . max_port_spec_id += <NUM_LIT:1> <EOL> if type ( arg ) == vtk_module or type ( arg ) == vtk_function : <EOL> tuple_function = vtk_function ( '<STR_LIT>' + str ( i ) ) <EOL> tuple_function . parent = tuple_module <EOL> conn = self . create_connection ( arg , tuple_function ) <EOL> port_spec . db_sigstring = conn . db_ports_type_index [ '<STR_LIT:source>' ] . db_signature <EOL> conn . db_ports_type_index [ '<STR_LIT>' ] . db_signature = port_spec . db_sigstring <EOL> final_sigs . append ( port_spec . db_sigstring [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> else : <EOL> db_parameters = self . get_parameters ( [ arg ] ) <EOL> db_function = DBFunction ( id = self . max_function_id , <EOL> name = '<STR_LIT>' + str ( i ) , <EOL> pos = tuple_f_pos , <EOL> parameters = db_parameters , <EOL> ) <EOL> self . max_function_id += <NUM_LIT:1> <EOL> tuple_f_pos += <NUM_LIT:1> <EOL> db_tuple_module . db_add_function ( db_function ) <EOL> port_spec . db_sigstring = "<STR_LIT:(>" + '<STR_LIT:U+002C>' . join ( p . db_type for p in db_parameters ) + "<STR_LIT:)>" <EOL> final_sigs . extend ( p . db_type for p in db_parameters ) <EOL> final_sigstring = "<STR_LIT:(>" + "<STR_LIT:U+002C>" . join ( final_sigs ) + "<STR_LIT:)>" <EOL> port_spec = DBPortSpec ( id = self . max_port_spec_id , <EOL> name = '<STR_LIT:value>' , <EOL> type = '<STR_LIT>' , <EOL> sigstring = final_sigstring ) <EOL> db_tuple_module . db_add_portSpec ( port_spec ) <EOL> self . max_port_spec_id += <NUM_LIT:1> <EOL> tuple_output = vtk_function ( '<STR_LIT:value>' ) <EOL> tuple_output . parent = tuple_module <EOL> self . create_connection ( tuple_output , function ) <EOL> return tuple_module <EOL> def get_parameters ( self , params ) : <EOL> def get_type ( arg ) : <EOL> python_types = { int : '<STR_LIT>' , <EOL> str : '<STR_LIT>' , <EOL> float : '<STR_LIT>' , <EOL> bool : '<STR_LIT>' } <EOL> if type ( arg ) not in python_types : <EOL> return None <EOL> return python_types [ type ( arg ) ] <EOL> def create_param ( arg , position ) : <EOL> p_type = get_type ( arg ) <EOL> if p_type : <EOL> p = DBParameter ( id = self . max_parameter_id , <EOL> type = p_type , <EOL> val = arg , <EOL> pos = position , <EOL> ) <EOL> db_parameters . append ( p ) <EOL> self . max_parameter_id += <NUM_LIT:1> <EOL> position += <NUM_LIT:1> <EOL> return position <EOL> db_parameters = [ ] <EOL> pos = <NUM_LIT:0> <EOL> for arg in params : <EOL> if type ( arg ) == tuple : <EOL> for tuple_arg in arg : <EOL> pos = create_param ( tuple_arg , pos ) <EOL> else : <EOL> pos = create_param ( arg , pos ) <EOL> return db_parameters <EOL> def create_function ( self , function , f_pos , allow_sub = True ) : <EOL> db_function = None <EOL> ( p_module , _ ) = self . find_or_create_module ( function , allow_sub ) <EOL> if p_module : <EOL> add_functions = [ ] <EOL> for sub_function in function . sub_functions : <EOL> if not sub_function . _name . startswith ( '<STR_LIT>' ) : <EOL> add_functions . append ( sub_function ) <EOL> self . create_functions ( p_module , add_functions , <EOL> len ( self . modules [ id ( p_module ) ] . db_functions ) ) <EOL> db_function = None <EOL> else : <EOL> if function . _name in self . unused_functions : <EOL> return None <EOL> parameters = [ ] <EOL> connections = [ ] <EOL> for arg in function . _args : <EOL> if type ( arg ) == vtk_module or type ( arg ) == vtk_function : <EOL> connections . append ( arg ) <EOL> else : <EOL> parameters . append ( arg ) <EOL> if len ( function . _args ) == <NUM_LIT:0> and len ( function . sub_functions ) == <NUM_LIT:0> and not function . _name . startswith ( '<STR_LIT>' ) : <EOL> parameters . append ( None ) <EOL> elif function . _name . startswith ( '<STR_LIT>' ) : <EOL> parameters = [ ] <EOL> connections = [ ] <EOL> if self . set_file_name_pattern . match ( function . _name ) and type ( function . parent ) == vtk_module and len ( function . _args ) == <NUM_LIT:1> and type ( function . _args [ <NUM_LIT:0> ] ) == str : <EOL> if not self . http_module : <EOL> self . http_module = vtk_module ( '<STR_LIT>' ) <EOL> self . http_module . url ( self . vtk_data_url ) <EOL> self . create_module ( self . http_module ) <EOL> self . create_functions ( self . http_module ) <EOL> unzip_module = vtk_module ( '<STR_LIT>' ) <EOL> self . create_module ( unzip_module ) <EOL> unzip_module . filename_in_archive ( function . _args [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] ) <EOL> unzip_module . archive_file ( self . http_module . file ( ) ) <EOL> self . create_functions ( unzip_module ) <EOL> set_file_function = vtk_function ( function . _name [ : - <NUM_LIT:4> ] ) <EOL> set_file_function . parent = function . parent <EOL> set_file_function . _args = [ unzip_module . file ( ) ] <EOL> self . create_functions ( function . parent , [ set_file_function ] ) <EOL> return None <EOL> if function . _name == '<STR_LIT>' and len ( function . _args ) == <NUM_LIT:1> and type ( function . _args [ <NUM_LIT:0> ] ) == vtk_module and type ( function . parent ) == vtk_module : <EOL> observer_module = function . parent <EOL> for a_function in observer_module . functions : <EOL> if a_function . _name == '<STR_LIT>' and len ( a_function . _args ) == <NUM_LIT:2> : <EOL> ( vtk_cell , _ ) = self . get_vtk_cell ( function . _args [ <NUM_LIT:0> ] ) <EOL> handler_module = vtk_module ( '<STR_LIT>' ) <EOL> handler_module . Observer ( function . parent ) <EOL> self . create_module ( handler_module ) <EOL> vtk_cell . InteractionHandler ( handler_module ) <EOL> for b_index , b_function in enumerate ( vtk_cell . functions ) : <EOL> if b_function . _name == '<STR_LIT>' : <EOL> break <EOL> self . create_functions ( vtk_cell , [ b_function ] , <EOL> len ( self . modules [ id ( vtk_cell ) ] . db_functions ) ) <EOL> del vtk_cell . functions [ b_index ] <EOL> ( event_type , python_function ) = a_function . _args <EOL> self . save_modules ( ) <EOL> python_function ( observer_module , None ) <EOL> f = event_type [ <NUM_LIT:0> ] . lower ( ) + event_type [ <NUM_LIT:1> : ] <EOL> f = f . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> handler_code = '<STR_LIT>' % f <EOL> shared_data = set ( ) <EOL> for s_module in self . vtk_modules . itervalues ( ) : <EOL> if len ( s_module . functions ) > <NUM_LIT:0> : <EOL> if not s_module . _name == '<STR_LIT>' : <EOL> shared_data . add ( s_module ) <EOL> for s_function in s_module . functions : <EOL> for s_arg in s_function . _args : <EOL> while type ( s_arg ) == vtk_function : <EOL> s_arg = s_arg . parent <EOL> if type ( s_arg ) == vtk_module : <EOL> shared_data . add ( s_arg ) <EOL> s_codelines = [ ] <EOL> s_arg_map = { } <EOL> s_arg_idx = <NUM_LIT:1> <EOL> if len ( shared_data ) < <NUM_LIT:1> or ( len ( shared_data ) == <NUM_LIT:1> and observer_module in shared_data ) : <EOL> handler_code += '<STR_LIT>' <EOL> else : <EOL> if len ( shared_data ) > <NUM_LIT:2> : <EOL> handler_code += '<STR_LIT>' <EOL> comma = '<STR_LIT:U+002C>' <EOL> else : <EOL> handler_code += '<STR_LIT:U+0020>' <EOL> comma = '<STR_LIT>' <EOL> for s_module in shared_data : <EOL> if s_module != observer_module : <EOL> handler_code += '<STR_LIT>' + str ( s_arg_idx ) + comma <EOL> s_arg_map [ id ( s_module ) ] = s_arg_idx <EOL> loop_arg_idx = s_arg_idx <EOL> s_arg_idx += <NUM_LIT:1> <EOL> else : <EOL> loop_arg_idx = <NUM_LIT:0> <EOL> for s_function in s_module . functions : <EOL> s_line = ( s_function . id , loop_arg_idx , <EOL> s_function ) <EOL> s_codelines . append ( s_line ) <EOL> if len ( shared_data ) > <NUM_LIT:2> : <EOL> handler_code += '<STR_LIT>' <EOL> else : <EOL> handler_code += '<STR_LIT>' <EOL> s_codelines . sort ( ) <EOL> for ( _ , m_idx , s_function ) in s_codelines : <EOL> s_module_name = '<STR_LIT>' if m_idx == <NUM_LIT:0> else '<STR_LIT>' % m_idx <EOL> s_function_str = s_function . _name <EOL> while len ( s_function . sub_functions ) > <NUM_LIT:0> : <EOL> if len ( s_function . sub_functions ) > <NUM_LIT:1> : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> s_function_str += '<STR_LIT>' + s_function . sub_functions [ <NUM_LIT:0> ] . _name <EOL> s_function = s_function . sub_functions [ <NUM_LIT:0> ] <EOL> handler_code += '<STR_LIT>' % ( s_module_name , s_function_str ) <EOL> s_arg_str = '<STR_LIT>' <EOL> for arg in s_function . _args : <EOL> if type ( arg ) == vtk_module : <EOL> s_module = arg <EOL> elif type ( arg ) == vtk_function : <EOL> s_module = arg . parent <EOL> else : <EOL> s_arg_str += arg + '<STR_LIT:U+002CU+0020>' <EOL> continue <EOL> m_idx = s_arg_map [ id ( s_module ) ] <EOL> s_module_name = '<STR_LIT>' if m_idx == <NUM_LIT:0> else '<STR_LIT>' % m_idx <EOL> if type ( arg ) == vtk_module : <EOL> s_arg_str += s_module_name <EOL> else : <EOL> s_arg_str += s_module_name + arg . _name + '<STR_LIT>' <EOL> handler_code += s_arg_str + '<STR_LIT>' <EOL> self . restore_modules ( ) <EOL> shared_data . discard ( observer_module ) <EOL> shared_data . discard ( handler_module ) <EOL> handler_module . SharedData ( * shared_data ) <EOL> handler_module . Handler ( urllib . quote ( handler_code ) ) <EOL> self . create_functions ( handler_module ) <EOL> return None <EOL> elif len ( function . sub_functions ) == <NUM_LIT:1> : <EOL> sub_function = function . sub_functions [ <NUM_LIT:0> ] <EOL> if function . _name == '<STR_LIT>' and sub_function . _name == '<STR_LIT>' : <EOL> new_function = vtk_function ( '<STR_LIT>' ) <EOL> new_function . _args = sub_function . _args [ : <NUM_LIT:2> ] <EOL> new_function . _kwargs = sub_function . _kwargs <EOL> new_function . parent = function . parent <EOL> function = new_function <EOL> parameters . extend ( new_function . _args ) <EOL> elif function . _name == '<STR_LIT>' and sub_function . _name == '<STR_LIT>' : <EOL> new_function = vtk_function ( '<STR_LIT>' ) <EOL> new_function . _args = sub_function . _args [ : <NUM_LIT:2> ] <EOL> new_function . _kwargs = sub_function . _kwargs <EOL> new_function . parent = function . parent <EOL> function = new_function <EOL> parameters . extend ( new_function . _args ) <EOL> if len ( connections ) > <NUM_LIT:0> : <EOL> if len ( connections ) > <NUM_LIT:1> or len ( parameters ) > <NUM_LIT:0> : <EOL> tuple_module = self . create_tuple ( function ) <EOL> db_function = None <EOL> else : <EOL> if allow_sub : <EOL> for arg in connections : <EOL> self . create_connection ( arg , function ) <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> elif len ( parameters ) > <NUM_LIT:0> : <EOL> db_parameters = self . get_parameters ( parameters ) <EOL> db_function = DBFunction ( id = self . max_function_id , <EOL> name = function . _name , <EOL> pos = f_pos , <EOL> parameters = db_parameters , <EOL> ) <EOL> self . max_function_id += <NUM_LIT:1> <EOL> return db_function <EOL> def create_connection ( self , src , dst ) : <EOL> convert_type_map = { '<STR_LIT:input>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:source>' } <EOL> def create_port ( vtk_module , type , name , other_vtk_module ) : <EOL> if id ( vtk_module ) not in self . modules : <EOL> print >> sys . stderr , '<STR_LIT>' , vtk_module . _name , type , name <EOL> import traceback <EOL> traceback . print_stack ( ) <EOL> return ( None , None ) <EOL> db_module = self . modules [ id ( vtk_module ) ] <EOL> db_package = self . registry . db_packages_identifier_index [ db_module . db_package ] <EOL> if db_module . db_namespace is None : <EOL> db_module . db_namespace = '<STR_LIT>' <EOL> d_key = ( db_module . db_name , db_module . db_namespace ) <EOL> db_module_desc = db_package . db_module_descriptors_name_index [ d_key ] <EOL> if name in self . translate_ports : <EOL> if db_module . db_name in self . translate_ports [ name ] : <EOL> name = self . translate_ports [ name ] [ db_module . db_name ] <EOL> elif ( db_module . db_name , <EOL> other_vtk_module . _name ) in self . translate_ports [ name ] : <EOL> name = self . translate_ports [ name ] [ ( db_module . db_name , <EOL> other_vtk_module . _name ) ] <EOL> else : <EOL> name = self . translate_ports [ name ] [ None ] <EOL> ps_key = ( name , type ) <EOL> if ps_key in db_module . db_portSpecs_name_index : <EOL> db_module_desc = db_module <EOL> while ps_key not in db_module_desc . db_portSpecs_name_index : <EOL> base_id = db_module_desc . db_base_descriptor_id <EOL> if base_id < <NUM_LIT:0> : <EOL> print >> sys . stderr , '<STR_LIT>' , vtk_module . _name , type , name <EOL> import traceback <EOL> traceback . print_stack ( ) <EOL> return ( None , None ) <EOL> db_module_desc = self . registry_desc_idx [ base_id ] <EOL> db_port_spec = db_module_desc . db_portSpecs_name_index [ ps_key ] <EOL> db_signature = db_port_spec . db_sigstring <EOL> new_port = DBPort ( id = self . max_port_id , <EOL> type = convert_type_map [ type ] , <EOL> moduleId = db_module . db_id , <EOL> moduleName = db_module . db_name , <EOL> name = name , <EOL> signature = db_signature , <EOL> ) <EOL> self . max_port_id += <NUM_LIT:1> <EOL> return ( db_module , new_port ) <EOL> def find_port_info ( entity ) : <EOL> if type ( entity ) == vtk_module : <EOL> if entity . _name == '<STR_LIT>' : <EOL> ( entity , _ ) = self . get_vtk_cell ( entity ) <EOL> found_module = entity <EOL> port_name = '<STR_LIT>' <EOL> elif type ( entity ) == vtk_function and type ( entity . parent ) == vtk_module : <EOL> ( found_module , inspector ) = self . find_or_create_module ( entity ) <EOL> if found_module : <EOL> if inspector : <EOL> port_name = entity . _name <EOL> else : <EOL> port_name = '<STR_LIT>' <EOL> else : <EOL> found_module = entity . parent <EOL> port_name = entity . _name <EOL> elif type ( entity ) == vtk_function and type ( entity . parent ) == vtk_function : <EOL> ( found_module , _ ) = self . find_or_create_module ( entity . parent ) <EOL> port_name = entity . _name <EOL> if not found_module : <EOL> print >> sys . stderr , "<STR_LIT>" , entity . _name <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' + str ( type ( entity ) ) <EOL> found_module = None <EOL> port_name = None <EOL> return ( found_module , port_name ) <EOL> src_port = None <EOL> src_module = None <EOL> dst_port = None <EOL> dst_module = None <EOL> ( src_vtk_module , src_port_name ) = find_port_info ( src ) <EOL> ( dst_vtk_module , dst_port_name ) = find_port_info ( dst ) <EOL> if src_vtk_module and dst_vtk_module : <EOL> ( src_module , src_port ) = create_port ( src_vtk_module , '<STR_LIT>' , <EOL> src_port_name , dst_vtk_module ) <EOL> ( dst_module , dst_port ) = create_port ( dst_vtk_module , '<STR_LIT:input>' , <EOL> dst_port_name , src_vtk_module ) <EOL> if not src_module or not dst_module : <EOL> print >> sys . stderr , '<STR_LIT>' , src . _name , dst . _name <EOL> return None <EOL> connection = DBConnection ( id = self . max_connection_id , <EOL> ports = [ src_port , dst_port ] , <EOL> ) <EOL> self . max_connection_id += <NUM_LIT:1> <EOL> key = ( id ( src_module ) , id ( dst_module ) ) <EOL> if key not in self . connections : <EOL> self . connections [ key ] = [ ] <EOL> self . connections [ key ] . append ( connection ) <EOL> if src_module . db_id not in self . vt_f_connections : <EOL> self . vt_f_connections [ src_module . db_id ] = [ ] <EOL> self . vt_f_connections [ src_module . db_id ] . append ( ( dst_module . db_id , <EOL> connection ) ) <EOL> if dst_module . db_id not in self . vt_b_connections : <EOL> self . vt_b_connections [ dst_module . db_id ] = [ ] <EOL> self . vt_b_connections [ dst_module . db_id ] . append ( ( src_module . db_id , <EOL> connection ) ) <EOL> return connection <EOL> def print_vt ( self , filename = None ) : <EOL> import vistrails . db . services . io <EOL> import vistrails . db . services . action <EOL> action_list = [ ] <EOL> for module in self . modules . itervalues ( ) : <EOL> action_list . append ( ( '<STR_LIT>' , module ) ) <EOL> for connection_list in self . connections . itervalues ( ) : <EOL> for connection in connection_list : <EOL> action_list . append ( ( '<STR_LIT>' , connection ) ) <EOL> self . do_layout ( ) <EOL> action = vistrails . db . services . action . create_action ( action_list ) <EOL> action . db_id = <NUM_LIT:1> <EOL> action . db_prevId = <NUM_LIT:0> <EOL> action . db_user = '<STR_LIT>' <EOL> action . db_date = datetime . datetime . now ( ) <EOL> tag = DBTag ( name = '<STR_LIT>' , id = <NUM_LIT:1> L ) <EOL> op_id = <NUM_LIT:0> <EOL> for op in action . db_operations : <EOL> op . db_id = op_id <EOL> op_id += <NUM_LIT:1> <EOL> vistrail = DBVistrail ( actions = [ action ] , tags = [ tag ] , version = '<STR_LIT>' ) <EOL> if filename : <EOL> script_name = os . path . splitext ( filename ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> script_name = '<STR_LIT:E>' + script_name [ <NUM_LIT:3> : ] <EOL> annotation = DBAnnotation ( id = <NUM_LIT:1> , <EOL> key = '<STR_LIT>' , <EOL> value = "<STR_LIT>" % script_name ) <EOL> action . db_add_annotation ( annotation ) <EOL> vistrails . db . services . io . save_bundle_to_zip_xml ( SaveBundle ( DBVistrail . vtType , vistrail ) , filename ) <EOL> else : <EOL> f = None <EOL> print >> f , vistrails . db . services . io . serialize ( vistrail ) </s>
