<s> from __future__ import division <EOL> from auto_gen import DBWorkflow as _DBWorkflow <EOL> from auto_gen import DBAbstractionRef , DBModule , DBGroup <EOL> from id_scope import IdScope <EOL> import copy <EOL> class DBWorkflow ( _DBWorkflow ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> _DBWorkflow . __init__ ( self , * args , ** kwargs ) <EOL> self . objects = { } <EOL> self . tmp_id = IdScope ( <NUM_LIT:1> , <EOL> { DBAbstractionRef . vtType : DBModule . vtType , <EOL> DBGroup . vtType : DBModule . vtType } ) <EOL> def __copy__ ( self ) : <EOL> return DBWorkflow . do_copy ( self ) <EOL> def do_copy ( self , new_ids = False , id_scope = None , id_remap = None ) : <EOL> cp = _DBWorkflow . do_copy ( self , new_ids , id_scope , id_remap ) <EOL> cp . __class__ = DBWorkflow <EOL> cp . build_index ( ) <EOL> cp . tmp_id = copy . copy ( self . tmp_id ) <EOL> return cp <EOL> _vtTypeMap = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> def build_index ( self ) : <EOL> g = self . _vtTypeMap . get <EOL> self . objects = dict ( ( ( g ( o . vtType , o . vtType ) , o . _db_id ) , o ) <EOL> for ( o , _ , _ ) in self . db_children ( ) ) <EOL> def add_to_index ( self , object ) : <EOL> obj_type = self . _vtTypeMap . get ( object . vtType , object . vtType ) <EOL> self . objects [ ( obj_type , object . getPrimaryKey ( ) ) ] = object <EOL> def delete_from_index ( self , object ) : <EOL> obj_type = self . _vtTypeMap . get ( object . vtType , object . vtType ) <EOL> del self . objects [ ( obj_type , object . getPrimaryKey ( ) ) ] <EOL> def capitalizeOne ( self , str ) : <EOL> return str [ <NUM_LIT:0> ] . upper ( ) + str [ <NUM_LIT:1> : ] <EOL> def db_print_objects ( self ) : <EOL> for k , v in self . objects . iteritems ( ) : <EOL> print '<STR_LIT>' % ( k , v ) <EOL> def db_has_object ( self , type , id ) : <EOL> return ( type , id ) in self . objects <EOL> def db_get_object ( self , type , id ) : <EOL> return self . objects [ ( type , id ) ] <EOL> def db_add_object ( self , object , parent_obj_type = None , <EOL> parent_obj_id = None , parent_obj = None ) : <EOL> if parent_obj is None : <EOL> if parent_obj_type is None or parent_obj_id is None : <EOL> parent_obj = self <EOL> else : <EOL> if parent_obj_type == '<STR_LIT>' or parent_obj_type == '<STR_LIT>' : <EOL> parent_obj_type = '<STR_LIT>' <EOL> try : <EOL> parent_obj = self . objects [ ( parent_obj_type , parent_obj_id ) ] <EOL> except KeyError : <EOL> msg = "<STR_LIT>" % ( parent_obj_type , parent_obj_id ) <EOL> raise Exception ( msg ) <EOL> if object . vtType == '<STR_LIT>' or object . vtType == '<STR_LIT>' : <EOL> obj_type = '<STR_LIT>' <EOL> else : <EOL> obj_type = object . vtType <EOL> funname = '<STR_LIT>' + obj_type <EOL> obj_copy = copy . copy ( object ) <EOL> getattr ( parent_obj , funname ) ( obj_copy ) <EOL> self . add_to_index ( obj_copy ) <EOL> def db_change_object ( self , old_id , object , parent_obj_type = None , <EOL> parent_obj_id = None , parent_obj = None ) : <EOL> if parent_obj is None : <EOL> if parent_obj_type is None or parent_obj_id is None : <EOL> parent_obj = self <EOL> else : <EOL> if parent_obj_type == '<STR_LIT>' or parent_obj_type == '<STR_LIT>' : <EOL> parent_obj_type = '<STR_LIT>' <EOL> try : <EOL> parent_obj = self . objects [ ( parent_obj_type , parent_obj_id ) ] <EOL> except KeyError : <EOL> msg = "<STR_LIT>" % ( parent_obj_type , parent_obj_id ) <EOL> raise Exception ( msg ) <EOL> self . db_delete_object ( old_id , object . vtType , None , None , parent_obj ) <EOL> self . db_add_object ( object , None , None , parent_obj ) <EOL> def db_delete_object ( self , obj_id , obj_type , parent_obj_type = None , <EOL> parent_obj_id = None , parent_obj = None ) : <EOL> if parent_obj is None : <EOL> if parent_obj_type is None or parent_obj_id is None : <EOL> parent_obj = self <EOL> else : <EOL> if parent_obj_type == '<STR_LIT>' or parent_obj_type == '<STR_LIT>' : <EOL> parent_obj_type = '<STR_LIT>' <EOL> try : <EOL> parent_obj = self . objects [ ( parent_obj_type , parent_obj_id ) ] <EOL> except KeyError : <EOL> msg = "<STR_LIT>" % ( parent_obj_type , parent_obj_id ) <EOL> raise Exception ( msg ) <EOL> if obj_type == '<STR_LIT>' or obj_type == '<STR_LIT>' : <EOL> obj_type = '<STR_LIT>' <EOL> funname = '<STR_LIT>' + obj_type <EOL> if hasattr ( parent_obj , funname ) : <EOL> object = getattr ( parent_obj , funname ) ( obj_id ) <EOL> else : <EOL> attr_name = '<STR_LIT>' + obj_type <EOL> object = getattr ( parent_obj , attr_name ) <EOL> funname = '<STR_LIT>' + obj_type <EOL> getattr ( parent_obj , funname ) ( object ) <EOL> self . delete_from_index ( object ) </s>
