<s> import cPickle as pickle <EOL> from jasmin . protocols . cli . managers import PersistableManager , Session <EOL> from jasmin . routing . jasminApi import Group <EOL> GroupKeyMap = { '<STR_LIT>' : '<STR_LIT>' } <EOL> def GroupBuild ( fCallback ) : <EOL> '<STR_LIT>' <EOL> def parse_args_and_call_with_instance ( self , * args , ** kwargs ) : <EOL> cmd = args [ <NUM_LIT:0> ] <EOL> arg = args [ <NUM_LIT:1> ] <EOL> if cmd is None : <EOL> return self . protocol . sendData ( ) <EOL> if cmd == '<STR_LIT>' : <EOL> if len ( self . sessBuffer ) != <NUM_LIT:1> : <EOL> return self . protocol . sendData ( '<STR_LIT>' ) <EOL> group = { } <EOL> for key , value in self . sessBuffer . iteritems ( ) : <EOL> group [ key ] = value <EOL> try : <EOL> GroupInstance = Group ( ** group ) <EOL> return fCallback ( self , GroupInstance ) <EOL> except Exception , e : <EOL> return self . protocol . sendData ( '<STR_LIT>' % str ( e ) ) <EOL> else : <EOL> if cmd not in GroupKeyMap : <EOL> return self . protocol . sendData ( '<STR_LIT>' % cmd ) <EOL> GroupKey = GroupKeyMap [ cmd ] <EOL> self . sessBuffer [ GroupKey ] = arg <EOL> return self . protocol . sendData ( ) <EOL> return parse_args_and_call_with_instance <EOL> class GroupExist ( object ) : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , gid_key ) : <EOL> self . gid_key = gid_key <EOL> def __call__ ( self , fCallback ) : <EOL> gid_key = self . gid_key <EOL> def exist_group_and_call ( self , * args , ** kwargs ) : <EOL> opts = args [ <NUM_LIT:1> ] <EOL> gid = getattr ( opts , gid_key ) <EOL> if self . pb [ '<STR_LIT>' ] . getGroup ( gid ) is not None : <EOL> return fCallback ( self , * args , ** kwargs ) <EOL> return self . protocol . sendData ( '<STR_LIT>' % gid ) <EOL> return exist_group_and_call <EOL> class GroupsManager ( PersistableManager ) : <EOL> "<STR_LIT>" <EOL> managerName = '<STR_LIT>' <EOL> def persist ( self , arg , opts ) : <EOL> if self . pb [ '<STR_LIT>' ] . perspective_persist ( opts . profile , '<STR_LIT>' ) : <EOL> self . protocol . sendData ( <EOL> '<STR_LIT>' % ( self . managerName , opts . profile ) , prompt = False ) <EOL> else : <EOL> self . protocol . sendData ( <EOL> '<STR_LIT>' % ( self . managerName , opts . profile ) , <EOL> prompt = False ) <EOL> def load ( self , arg , opts ) : <EOL> r = self . pb [ '<STR_LIT>' ] . perspective_load ( opts . profile , '<STR_LIT>' ) <EOL> if r : <EOL> self . protocol . sendData ( <EOL> '<STR_LIT>' % ( self . managerName , opts . profile ) , prompt = False ) <EOL> else : <EOL> self . protocol . sendData ( <EOL> '<STR_LIT>' % ( self . managerName , opts . profile ) , <EOL> prompt = False ) <EOL> def list ( self , arg , opts ) : <EOL> groups = pickle . loads ( self . pb [ '<STR_LIT>' ] . perspective_group_get_all ( ) ) <EOL> counter = <NUM_LIT:0> <EOL> if ( len ( groups ) ) > <NUM_LIT:0> : <EOL> self . protocol . sendData ( "<STR_LIT>" % '<STR_LIT>' . ljust ( <NUM_LIT:16> ) , prompt = False ) <EOL> for group in groups : <EOL> counter += <NUM_LIT:1> <EOL> group_prefix = '<STR_LIT>' <EOL> if not group . enabled : <EOL> group_prefix = '<STR_LIT:!>' <EOL> self . protocol . sendData ( "<STR_LIT>" % ( str ( group_prefix + group . gid ) . ljust ( <NUM_LIT:16> ) ) , prompt = False ) <EOL> self . protocol . sendData ( prompt = False ) <EOL> self . protocol . sendData ( '<STR_LIT>' % counter ) <EOL> @ Session <EOL> @ GroupBuild <EOL> def add_session ( self , GroupInstance ) : <EOL> st = self . pb [ '<STR_LIT>' ] . perspective_group_add ( pickle . dumps ( GroupInstance , pickle . HIGHEST_PROTOCOL ) ) <EOL> if st : <EOL> self . protocol . sendData ( '<STR_LIT>' % ( GroupInstance . gid ) , prompt = False ) <EOL> self . stopSession ( ) <EOL> else : <EOL> self . protocol . sendData ( '<STR_LIT>' ) <EOL> def add ( self , arg , opts ) : <EOL> return self . startSession ( self . add_session , <EOL> annoucement = '<STR_LIT>' , <EOL> completitions = GroupKeyMap . keys ( ) ) <EOL> @ GroupExist ( gid_key = '<STR_LIT>' ) <EOL> def enable ( self , arg , opts ) : <EOL> st = self . pb [ '<STR_LIT>' ] . perspective_group_enable ( opts . enable ) <EOL> if st : <EOL> self . protocol . sendData ( '<STR_LIT>' % opts . enable ) <EOL> else : <EOL> self . protocol . sendData ( '<STR_LIT>' ) <EOL> @ GroupExist ( gid_key = '<STR_LIT>' ) <EOL> def disable ( self , arg , opts ) : <EOL> st = self . pb [ '<STR_LIT>' ] . perspective_group_disable ( opts . disable ) <EOL> if st : <EOL> self . protocol . sendData ( '<STR_LIT>' % opts . disable ) <EOL> else : <EOL> self . protocol . sendData ( '<STR_LIT>' ) <EOL> @ GroupExist ( gid_key = '<STR_LIT>' ) <EOL> def remove ( self , arg , opts ) : <EOL> st = self . pb [ '<STR_LIT>' ] . perspective_group_remove ( opts . remove ) <EOL> if st : <EOL> self . protocol . sendData ( '<STR_LIT>' % opts . remove ) <EOL> else : <EOL> self . protocol . sendData ( '<STR_LIT>' ) </s>
