<s> def auto_fs_granter ( selexp ) : <EOL> """<STR_LIT>""" <EOL> from django . conf import settings <EOL> from openflow . optin_manager . xmlrpc_server . models import FVServerProxy <EOL> from openflow . optin_manager . users . models import Priority , UserProfile <EOL> from django . contrib . auth . models import User <EOL> from openflow . optin_manager . opts . helper import opt_fs_into_exp <EOL> from openflow . optin_manager . flowspace . helper import multi_fs_intersect , single_fs_intersect <EOL> from openflow . optin_manager . opts . models import Experiment , ExperimentFLowSpace , UserFlowSpace , AdminFlowSpace , UserOpts <EOL> try : <EOL> user = User . objects . filter ( username = settings . ROOT_USERNAME ) [ <NUM_LIT:0> ] <EOL> adminFS = AdminFlowSpace . objects . filter ( user = user ) <EOL> profile = UserProfile . get_or_create_profile ( user ) <EOL> fv = FVServerProxy . objects . all ( ) [ <NUM_LIT:0> ] <EOL> assigned_priority = profile . max_priority_level - Priority . Strict_Priority_Offset - <NUM_LIT:1> <EOL> all_this_admin_opts = UserOpts . objects . filter ( user = user , nice = True ) <EOL> for admin_opt in all_this_admin_opts : <EOL> if admin_opt . priority <= assigned_priority : <EOL> assigned_priority = admin_opt . priority - <NUM_LIT:1> <EOL> flow_space = ExperimentFLowSpace . objects . filter ( exp = selexp . id ) <EOL> if not flow_space : <EOL> print "<STR_LIT>" % selexp . slice_id <EOL> raise Exception ( '<STR_LIT>' % selexp . slice_id ) <EOL> intersected_flowspace = get_used_fs ( flow_space ) <EOL> fv_args , match_list = opt_fs_into_exp ( intersected_flowspace , selexp , user , assigned_priority , True ) <EOL> returned_ids = fv . proxy . api . changeFlowSpace ( fv_args ) <EOL> for i in range ( len ( match_list ) ) : <EOL> match_list [ i ] . fv_id = returned_ids [ i ] <EOL> match_list [ i ] . save ( ) <EOL> allopts = UserOpts . objects . filter ( user = user ) . order_by ( '<STR_LIT>' ) <EOL> for opt in allopts : <EOL> this_opt_fses = opt . optsflowspace_set . all ( ) <EOL> fs_project = opt . experiment . project_name or "<STR_LIT>" <EOL> fs_slice = opt . experiment . slice_name or "<STR_LIT>" <EOL> fs_description = "<STR_LIT>" <EOL> for fs in this_opt_fses : <EOL> if fs_description != "<STR_LIT>" : <EOL> fs_description = fs_description + "<STR_LIT>" % fs <EOL> else : <EOL> fs_description = "<STR_LIT:%s>" % fs <EOL> print "<STR_LIT>" % selexp . slice_id <EOL> except Exception as e : <EOL> raise e <EOL> def filter_own_experiment ( slice_iden ) : <EOL> filtered_exp = None <EOL> try : <EOL> filtered_exp = Experiment . objects . get ( slice_id = slice_iden [ '<STR_LIT:id>' ] ) <EOL> for keyword in slice_iden [ '<STR_LIT>' ] : <EOL> if keyword not in filtered_exp . slice_name : <EOL> filtered_exp = None <EOL> break <EOL> except Exception as e : <EOL> print "<STR_LIT>" % ( str ( slice_iden [ '<STR_LIT:id>' ] ) , str ( e ) ) <EOL> return filtered_exp <EOL> def get_used_fs ( flow_space ) : <EOL> forbidden_keys = [ "<STR_LIT:id>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> intersections_return = list ( ) <EOL> intersection_dicts = list ( ) <EOL> for flow in flow_space : <EOL> intersection = dict ( ) <EOL> for key in flow . __dict__ . keys ( ) : <EOL> if key in forbidden_keys : <EOL> continue <EOL> else : <EOL> intersection [ key ] = flow . __dict__ [ key ] <EOL> if intersection not in intersection_dicts : <EOL> intersection_dicts . append ( intersection ) <EOL> for intersection in intersection_dicts : <EOL> int_fs = intersection_fs ( ) <EOL> for key in intersection . keys ( ) : <EOL> setattr ( int_fs , key , intersection [ key ] ) <EOL> intersections_return . append ( int_fs ) <EOL> return intersections_return <EOL> class intersection_fs : <EOL> pass </s>
