<s> import math <EOL> import sys <EOL> import types <EOL> import fishlib <EOL> import cli <EOL> import flags <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> from django . utils import simplejson as json <EOL> else : <EOL> import json <EOL> class PermissionsError ( Exception ) : <EOL> pass <EOL> class WisdomFailure ( Exception ) : <EOL> pass <EOL> class RemoveError ( Exception ) : <EOL> pass <EOL> class PermissionDesc : <EOL> def __init__ ( self , entity , path , actions , names ) : <EOL> self . entity = entity <EOL> self . path = path <EOL> self . actions = actions <EOL> self . names = names <EOL> def action ( self , name ) : <EOL> return self . actions [ self . names . index ( name ) ] <EOL> RAW_PERMS = { <EOL> u'<STR_LIT>' : PermissionDesc ( u'<STR_LIT>' , u'<STR_LIT>' , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] ) , <EOL> u'<STR_LIT>' : PermissionDesc ( u'<STR_LIT>' , u'<STR_LIT>' , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> u'<STR_LIT>' : PermissionDesc ( u'<STR_LIT>' , u'<STR_LIT>' , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT:list>' , <EOL> u'<STR_LIT>' ] , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' ] ) <EOL> } <EOL> RAW_PERM_ENTITIES = RAW_PERMS . keys ( ) <EOL> READ_NAMES = [ u'<STR_LIT>' ] <EOL> WRITE_NAMES = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> CONTROL_NAMES = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> ALL_NAMES = READ_NAMES + WRITE_NAMES + CONTROL_NAMES <EOL> class UnixPerm : <EOL> def __init__ ( self , s ) : <EOL> n = ord ( s ) - ord ( u'<STR_LIT:0>' ) <EOL> if not <NUM_LIT:0> <= n <= <NUM_LIT:7> : <EOL> raise PermissionsError ( u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> self . read = n & <NUM_LIT:4> == <NUM_LIT:4> <EOL> self . write = n & <NUM_LIT:2> == <NUM_LIT:2> <EOL> self . control = n & <NUM_LIT:1> == <NUM_LIT:1> <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' % ( u'<STR_LIT:r>' if self . read else u'<STR_LIT:->' , <EOL> u'<STR_LIT:w>' if self . write else u'<STR_LIT:->' , <EOL> u'<STR_LIT:c>' if self . control else u'<STR_LIT:->' ) <EOL> class UnixPerms : <EOL> def __init__ ( self , spec , user , isTag = None ) : <EOL> self . user = user <EOL> self . owner = UnixPerm ( spec [ <NUM_LIT:0> ] ) <EOL> self . group = UnixPerm ( spec [ <NUM_LIT:1> ] ) <EOL> self . world = UnixPerm ( spec [ <NUM_LIT:2> ] ) <EOL> self . read = self . fi_perm ( self . world . read , self . owner . read , isTag ) <EOL> self . write = self . fi_perm ( self . world . write , self . owner . write , isTag ) <EOL> self . control = self . fi_perm ( self . world . control , self . owner . control , <EOL> isTag ) <EOL> def fi_perm ( self , w , o , isTag ) : <EOL> policy = u'<STR_LIT>' if w else u'<STR_LIT>' <EOL> if policy == u'<STR_LIT>' : <EOL> exceptions = [ self . user ] if o else [ ] <EOL> else : <EOL> exceptions = [ ] if o else [ self . user ] <EOL> return FluidinfoPerm ( self . user , policy , exceptions , isTag ) <EOL> def check_owner_control_ok ( self ) : <EOL> if not self . owner . control : <EOL> raise WisdomFailure ( u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' % ( unicode ( self . owner ) , unicode ( self . group ) , <EOL> unicode ( self . world ) ) <EOL> class FluidinfoPerm : <EOL> def __init__ ( self , owner , policy = None , exceptions = None , hash = None , <EOL> name = None , action = None , isTag = None , isPolicy = False ) : <EOL> self . owner = owner <EOL> self . name = name <EOL> self . action = action <EOL> self . isTag = isTag <EOL> self . isPolicy = isPolicy <EOL> if hash : <EOL> self . policy = hash [ u'<STR_LIT>' ] <EOL> self . exceptions = hash [ u'<STR_LIT>' ] <EOL> else : <EOL> self . policy = policy <EOL> self . exceptions = exceptions <EOL> def accessible ( self , code , user ) : <EOL> return ( code if self . policy == u'<STR_LIT>' or user in self . exceptions <EOL> else u'<STR_LIT:->' ) <EOL> def isOpen ( self , code ) : <EOL> return code if self . policy == u'<STR_LIT>' else u'<STR_LIT:->' <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' % ( self . policy , <EOL> u'<STR_LIT:U+002CU+0020>' . join ( self . exceptions ) ) <EOL> class FluidinfoPerms : <EOL> def __init__ ( self , db , path , isTag , getFromFI = True , isPolicy = False ) : <EOL> self . isTag = isTag <EOL> self . isPolicy = isPolicy <EOL> self . path = path <EOL> self . valid = True <EOL> self . entities = [ u'<STR_LIT>' , u'<STR_LIT>' ] if isTag else [ u'<STR_LIT>' ] <EOL> self . compressIfPoss = True <EOL> self . owner = path . split ( u'<STR_LIT:/>' ) [ <NUM_LIT:1> ] <EOL> for entity in self . entities : <EOL> desc = RAW_PERMS [ entity ] <EOL> for ( action , name ) in zip ( desc . actions , desc . names ) : <EOL> if getFromFI : <EOL> if isPolicy : <EOL> p = db . get_raw_policy ( entity , path [ <NUM_LIT:1> : ] , action ) <EOL> else : <EOL> p = db . get_raw_perm ( entity , path [ <NUM_LIT:1> : ] , action , isTag ) <EOL> self . __dict__ [ name ] = p <EOL> if type ( p ) in ( int , long ) : <EOL> self . value = False <EOL> else : <EOL> policy = u'<STR_LIT>' if name in READ_NAMES else u'<STR_LIT>' <EOL> exceptions = [ ] if name in READ_NAMES else [ self . owner ] <EOL> self . __dict__ [ name ] = FluidinfoPerm ( self . owner , policy , <EOL> exceptions , None , <EOL> name , action , isTag , <EOL> isPolicy ) <EOL> def set_to_private ( self ) : <EOL> for name in ALL_NAMES : <EOL> if name in self . __dict__ : <EOL> self . __dict__ [ name ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ name ] . exceptions = [ self . owner ] <EOL> def set_to_default ( self ) : <EOL> for name in ALL_NAMES : <EOL> if name in self . __dict__ : <EOL> if name in READ_NAMES : <EOL> self . __dict__ [ name ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ name ] . exceptions = [ ] <EOL> else : <EOL> self . __dict__ [ name ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ name ] . exceptions = [ self . owner ] <EOL> def set_group_writable ( self , group ) : <EOL> fullgroup = group + ( [ ] if self . owner in group else [ self . owner ] ) <EOL> for name in WRITE_NAMES : <EOL> if hasattr ( self , name ) : <EOL> self . __dict__ [ name ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ name ] . exceptions = fullgroup <EOL> def set_group_readable ( self , group ) : <EOL> fullgroup = group + ( [ ] if self . owner in group else [ self . owner ] ) <EOL> self . __dict__ [ u'<STR_LIT>' ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ u'<STR_LIT>' ] . exceptions = fullgroup <EOL> def lock ( self ) : <EOL> for name in WRITE_NAMES : <EOL> if hasattr ( self , name ) : <EOL> self . __dict__ [ name ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ name ] . exceptions = [ ] <EOL> def unlock ( self ) : <EOL> for name in WRITE_NAMES : <EOL> if hasattr ( self , name ) : <EOL> self . __dict__ [ name ] . policy = u'<STR_LIT>' <EOL> self . __dict__ [ name ] . exceptions = [ self . owner ] <EOL> def check_owner_control ( self , p ) : <EOL> if ( ( p . policy == '<STR_LIT>' and self . owner in p . exceptions ) <EOL> or ( p . policy == '<STR_LIT>' and not self . owner in p . exceptions ) ) : <EOL> raise PermissionsError ( u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> def update_fluidinfo ( self , db , permsToSet = None , force = False , <EOL> restrict_to = None , verbose = False ) : <EOL> permsToSet = permsToSet or ALL_NAMES <EOL> if not force : <EOL> for name in CONTROL_NAMES : <EOL> if hasattr ( self , name ) : <EOL> self . check_owner_control ( self . __dict__ [ name ] ) <EOL> entities = ( u'<STR_LIT>' , u'<STR_LIT>' ) if self . isTag else ( u'<STR_LIT>' , ) <EOL> for entity in entities : <EOL> for name in RAW_PERMS [ entity ] . names : <EOL> if name in permsToSet and ( not restrict_to <EOL> or name in restrict_to ) : <EOL> action = RAW_PERMS [ entity ] . action ( name ) <EOL> if verbose : <EOL> db . Print ( u'<STR_LIT>' <EOL> u'<STR_LIT>' % ( entity , self . path [ <NUM_LIT:1> : ] , <EOL> action , <EOL> self . __dict__ [ name ] . policy , <EOL> unicode ( self . __dict__ [ name ] . exceptions ) ) ) <EOL> err = db . set_raw_perm ( entity , self . path [ <NUM_LIT:1> : ] , action , <EOL> self . __dict__ [ name ] . policy , <EOL> self . __dict__ [ name ] . exceptions ) <EOL> if err : <EOL> db . warning ( cli . error_code ( err ) ) <EOL> def fi_tag_desc ( self ) : <EOL> s = [ u'<STR_LIT>' ] <EOL> writes = ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> controls = ( self . acontrol , self . tcontrol ) <EOL> wPerms = [ ] <EOL> for kind in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> desc = RAW_PERMS [ u'<STR_LIT>' if kind == u'<STR_LIT>' else u'<STR_LIT>' ] <EOL> L = u'<STR_LIT:t>' if kind == u'<STR_LIT>' else u'<STR_LIT:a>' <EOL> s . append ( kind [ - <NUM_LIT:3> : ] + u'<STR_LIT>' % desc . path ) <EOL> if kind == u'<STR_LIT>' : <EOL> s . append ( u'<STR_LIT>' ) <EOL> s . append ( u'<STR_LIT>' % ( u'<STR_LIT>' , <EOL> unicode ( self . read ) ) ) <EOL> s . append ( u'<STR_LIT>' ) <EOL> for ( fi , fdb ) in zip ( desc . actions , desc . names ) : <EOL> if fdb in writes : <EOL> w = unicode ( self . __dict__ [ fdb ] ) <EOL> wPerms . append ( w ) <EOL> s . append ( u'<STR_LIT>' % ( u'<STR_LIT>' % ( fi , fdb ) , w ) ) <EOL> s . extend ( [ u'<STR_LIT>' ] ) <EOL> c = self . tcontrol if kind == u'<STR_LIT>' else self . acontrol <EOL> s . append ( u'<STR_LIT>' % ( u'<STR_LIT>' % L , <EOL> unicode ( c ) ) ) <EOL> s . append ( u'<STR_LIT>' ) <EOL> if self . compressIfPoss : <EOL> if ( all ( w == wPerms [ <NUM_LIT:0> ] for w in wPerms [ <NUM_LIT:1> : ] ) <EOL> and unicode ( self . acontrol ) == unicode ( self . tcontrol ) ) : <EOL> s = [ u'<STR_LIT>' % unicode ( self . read ) , <EOL> u'<STR_LIT>' % unicode ( wPerms [ <NUM_LIT:0> ] ) , <EOL> u'<STR_LIT>' % unicode ( self . acontrol ) , <EOL> u'<STR_LIT>' ] <EOL> return u'<STR_LIT:\n>' . join ( s ) <EOL> def fi_ns_desc ( self ) : <EOL> s = [ u'<STR_LIT>' ] <EOL> writes = ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> desc = RAW_PERMS [ u'<STR_LIT>' ] <EOL> s . append ( u'<STR_LIT>' % desc . path ) <EOL> s . append ( u'<STR_LIT>' ) <EOL> s . append ( u'<STR_LIT>' % ( u'<STR_LIT>' , unicode ( self . read ) ) ) <EOL> s . append ( u'<STR_LIT>' ) <EOL> wPerms = [ ] <EOL> for ( fi , fdb ) in zip ( desc . actions , desc . names ) : <EOL> if fdb in writes : <EOL> w = unicode ( self . __dict__ [ fdb ] ) <EOL> wPerms . append ( w ) <EOL> s . append ( u'<STR_LIT>' % ( u'<STR_LIT>' % ( fi , fdb ) , w ) ) <EOL> s . append ( u'<STR_LIT>' ) <EOL> s . append ( u'<STR_LIT>' % ( u'<STR_LIT>' , self . control ) ) <EOL> if self . compressIfPoss and all ( w == wPerms [ <NUM_LIT:0> ] for w in wPerms [ <NUM_LIT:1> : ] ) : <EOL> s = [ u'<STR_LIT>' % unicode ( self . read ) , <EOL> u'<STR_LIT>' % unicode ( wPerms [ <NUM_LIT:0> ] ) , <EOL> u'<STR_LIT>' % unicode ( self . control ) ] <EOL> s . append ( u'<STR_LIT>' ) <EOL> return u'<STR_LIT:\n>' . join ( s ) <EOL> def __unicode__ ( self ) : <EOL> if self . isTag is None : <EOL> raise Exception <EOL> if not self . valid : <EOL> return '<STR_LIT>' <EOL> return self . fi_tag_desc ( ) if self . isTag else self . fi_ns_desc ( ) <EOL> def string_format ( n ) : <EOL> return u'<STR_LIT>' % n <EOL> def len_exc ( exceptions , owner ) : <EOL> return len ( exceptions ) - <NUM_LIT:1> if owner in exceptions else len ( exceptions ) <EOL> def combined_status ( list_ ) : <EOL> L = list_ [ <NUM_LIT:0> ] <EOL> return L if all ( ell == L for ell in list_ ) else u'<STR_LIT:/>' <EOL> def to_string_grid ( items , pageWidth = <NUM_LIT> , maxCols = <NUM_LIT:9> ) : <EOL> if items == [ ] : <EOL> return u'<STR_LIT>' <EOL> widest = max ( [ len ( s ) for s in items ] ) <EOL> nCols = min ( max ( pageWidth / ( widest + <NUM_LIT:1> ) , <NUM_LIT:1> ) , maxCols ) <EOL> colWidth = int ( math . ceil ( float ( pageWidth ) / nCols ) ) - <NUM_LIT:1> <EOL> fmt = string_format ( colWidth ) <EOL> nItems = len ( items ) <EOL> nRows = int ( math . ceil ( float ( nItems ) / nCols ) ) <EOL> return u'<STR_LIT:\n>' . join ( [ u'<STR_LIT:U+0020>' . join ( [ fmt % items [ col * nRows + row ] <EOL> for col in range ( nCols ) <EOL> if col * nRows + row < nItems ] ) <EOL> for row in range ( nRows ) ] ) <EOL> class ExtendedFluidinfo ( fishlib . Fluidinfo ) : <EOL> def __init__ ( self , credentials = None , host = None , debug = False , <EOL> encoding = fishlib . DEFAULT_ENCODING , unixStylePaths = None , <EOL> saveOut = False , cache = None , webapp = False ) : <EOL> fishlib . Fluidinfo . __init__ ( self , credentials , host , debug , <EOL> encoding , unixStylePaths , saveOut , <EOL> cache , webapp ) <EOL> def list_namespace ( self , ns , returnDescription = True , <EOL> returnNamespaces = True , returnTags = True ) : <EOL> status , content = self . call ( u'<STR_LIT:GET>' , u'<STR_LIT>' % ns , None , <EOL> returnDescription = returnDescription , <EOL> returnNamespaces = returnNamespaces , <EOL> returnTags = returnTags ) <EOL> return content if status == fishlib . STATUS . OK else status <EOL> def list_r_namespace ( self , rootns ) : <EOL> L = self . list_namespace ( rootns , returnDescription = False ) <EOL> if L == fishlib . STATUS . NOT_FOUND : <EOL> return fishlib . STATUS . NOT_FOUND <EOL> if type ( L ) in ( int , long ) : <EOL> return { u'<STR_LIT>' : [ ] , u'<STR_LIT>' : [ ] , u'<STR_LIT>' : True } <EOL> failures = False <EOL> namespaces = [ u'<STR_LIT>' % ( rootns , space ) <EOL> for space in L [ u'<STR_LIT>' ] ] <EOL> tags = [ u'<STR_LIT>' % ( rootns , tag ) for tag in L [ u'<STR_LIT>' ] ] <EOL> subns = [ ] <EOL> subtags = [ ] <EOL> for s in namespaces : <EOL> L = self . list_namespace ( s , returnDescription = False ) <EOL> if type ( L ) in ( int , long ) : <EOL> failures = True <EOL> else : <EOL> subns . extend ( [ u'<STR_LIT>' % ( s , space ) <EOL> for space in L [ u'<STR_LIT>' ] ] ) <EOL> subtags . extend ( [ u'<STR_LIT>' % ( s , space ) <EOL> for space in L [ u'<STR_LIT>' ] ] ) <EOL> namespaces . extend ( subns ) <EOL> tags . extend ( subtags ) <EOL> return { u'<STR_LIT>' : namespaces , u'<STR_LIT>' : tags , <EOL> u'<STR_LIT>' : failures } <EOL> def rm_r ( self , rootns ) : <EOL> L = self . list_r_namespace ( rootns ) <EOL> if L == fishlib . STATUS . NOT_FOUND : <EOL> return L <EOL> elif L [ u'<STR_LIT>' ] : <EOL> return <NUM_LIT:1> <EOL> for items , fn in ( ( L [ u'<STR_LIT>' ] , self . delete_abstract_tag ) , <EOL> ( L [ u'<STR_LIT>' ] , self . delete_namespace ) ) : <EOL> si = [ ( i . split ( u'<STR_LIT:/>' ) , i ) for i in items ] <EOL> z = [ ( len ( s ) , i ) for ( s , i ) in si ] <EOL> z . sort ( ) <EOL> z . reverse ( ) <EOL> failed = <NUM_LIT:0> <EOL> for ( n , i ) in z : <EOL> r = fn ( u'<STR_LIT>' % i ) <EOL> failed = failed or ( r if r != fishlib . STATUS . NO_CONTENT <EOL> else <NUM_LIT:0> ) <EOL> if failed : <EOL> return failed <EOL> return self . delete_namespace ( u'<STR_LIT:/>' + rootns ) <EOL> def rm_all_tag_values ( self , tag ) : <EOL> self . untag_by_query ( ) <EOL> def list_sorted_ns ( self , ns , long_ = False , columns = True , recurse = False , <EOL> prnt = False , longer = False , longest = False ) : <EOL> h = self . list_namespace ( ns ) <EOL> return self . list_sorted_nshash ( h , ns , long_ , columns , recurse , <EOL> prnt = prnt , longer = longer , <EOL> longest = longest ) <EOL> def list_sorted_nshash ( self , h , ns , long_ = False , columns = True , <EOL> recurse = False , prnt = False , longer = False , <EOL> longest = False ) : <EOL> if type ( h ) in ( int , long ) : <EOL> if h == fishlib . STATUS . UNAUTHORIZED : <EOL> return u'<STR_LIT>' <EOL> else : <EOL> return u'<STR_LIT>' % h <EOL> tagNames = h [ u'<STR_LIT>' ] <EOL> tagNames . sort ( ) <EOL> spaces = h [ u'<STR_LIT>' ] <EOL> spaces . sort ( ) <EOL> items = tagNames [ : ] + [ u'<STR_LIT>' % space for space in spaces ] <EOL> items . sort ( ) <EOL> if items : <EOL> fmt = string_format ( max ( [ len ( item ) for item in items ] ) ) <EOL> if recurse : <EOL> self . Print ( u'<STR_LIT>' % ns ) <EOL> if long_ or longer or longest : <EOL> res = [ ] <EOL> for item in items : <EOL> r = self . full_perms ( ns + u'<STR_LIT:/>' + fmt % item , longer , <EOL> longest = longest ) <EOL> res . append ( r ) <EOL> if prnt : <EOL> self . Print ( r ) <EOL> result = u'<STR_LIT:\n>' . join ( res ) <EOL> elif columns == False : <EOL> result = u'<STR_LIT:\n>' . join ( items ) <EOL> if prnt : <EOL> self . Print ( result ) <EOL> else : <EOL> result = to_string_grid ( items ) <EOL> if prnt : <EOL> self . Print ( result ) <EOL> if recurse : <EOL> others = u'<STR_LIT:\n>' . join ( [ self . list_sorted_ns ( u'<STR_LIT>' % ( ns , space ) , <EOL> long_ , columns , recurse , <EOL> prnt = prnt , longer = longer , <EOL> longest = longest ) <EOL> for space in spaces ] ) <EOL> return u'<STR_LIT>' % ( ns , result , others ) <EOL> else : <EOL> return result <EOL> def get_raw_perm ( self , entity , name , action , isTag ) : <EOL> assert entity in RAW_PERM_ENTITIES <EOL> owner = entity . split ( u'<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> perm = RAW_PERMS [ entity ] <EOL> assert action in perm . actions <EOL> path = u'<STR_LIT>' % ( perm . path , name ) <EOL> status , content = self . call ( u'<STR_LIT:GET>' , path , None , action = action ) <EOL> return ( FluidinfoPerm ( owner , hash = content , name = name , action = action , <EOL> isTag = isTag ) <EOL> if status == fishlib . STATUS . OK else status ) <EOL> def get_raw_policy ( self , entity , owner , action ) : <EOL> assert entity in RAW_PERM_ENTITIES <EOL> perm = RAW_PERMS [ entity ] <EOL> assert action in perm . actions <EOL> path = u'<STR_LIT>' % ( owner , perm . path , action ) <EOL> status , content = self . call ( u'<STR_LIT:GET>' , path , None , action = action ) <EOL> return ( FluidinfoPerm ( owner , hash = content , name = owner , action = action , <EOL> isPolicy = True ) <EOL> if status == fishlib . STATUS . OK else status ) <EOL> def get_tag_perms_hash ( self , tag ) : <EOL> h = { } <EOL> for entity in [ u'<STR_LIT>' , u'<STR_LIT>' ] : <EOL> desc = RAW_PERMS [ entity ] <EOL> for ( action , name ) in zip ( desc . actions , desc . names ) : <EOL> h [ name ] = self . get_raw_perm ( entity , tag , action , True ) <EOL> return h <EOL> def get_ns_perms_hash ( self , ns ) : <EOL> h = { } <EOL> for entity in [ u'<STR_LIT>' ] : <EOL> desc = RAW_PERMS [ entity ] <EOL> for ( action , name ) in zip ( desc . actions , desc . names ) : <EOL> h [ name ] = self . get_raw_perm ( entity , ns , action , False ) <EOL> return h <EOL> def tag_perms_string ( self , tag , group = False ) : <EOL> h = self . get_tag_perms_hash ( tag ) <EOL> s = [ ] <EOL> owner = tag . split ( u'<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> r = h [ u'<STR_LIT>' ] <EOL> a , t = h [ u'<STR_LIT>' ] , h [ u'<STR_LIT>' ] <EOL> writes = ( h [ u'<STR_LIT>' ] , h [ u'<STR_LIT>' ] , h [ u'<STR_LIT>' ] , h [ u'<STR_LIT>' ] ) <EOL> ownerRead = r . accessible ( u'<STR_LIT:r>' , owner ) <EOL> ownerWrites = [ w . accessible ( u'<STR_LIT:w>' , owner ) for w in writes ] <EOL> ownerControl = combined_status ( ( t . accessible ( u'<STR_LIT:c>' , owner ) , <EOL> a . accessible ( u'<STR_LIT:c>' , owner ) ) ) <EOL> worldControlT = t . isOpen ( u'<STR_LIT:c>' ) <EOL> worldControlA = a . isOpen ( u'<STR_LIT:c>' ) <EOL> worldControl = ( worldControlT if worldControlT == worldControlA <EOL> else u'<STR_LIT:/>' ) <EOL> worldRead = r . isOpen ( u'<STR_LIT:r>' ) <EOL> worldWrites = [ w . isOpen ( u'<STR_LIT:w>' ) for w in writes ] <EOL> ownerWrite = write_status ( ownerWrites ) <EOL> worldWrite = write_status ( worldWrites ) <EOL> groupRead = self . group_perm ( u'<STR_LIT:r>' , r , owner ) <EOL> groupWrite = combined_status ( [ self . group_perm ( u'<STR_LIT:w>' , w , owner ) <EOL> for w in writes ] ) <EOL> groupControl = combined_status ( [ self . group_perm ( u'<STR_LIT:c>' , c , owner ) <EOL> for c in ( a , t ) ] ) <EOL> ps = u'<STR_LIT>' % ( ownerRead , ownerWrite , ownerControl , <EOL> groupRead , groupWrite , groupControl , <EOL> worldRead , worldWrite , worldControl ) <EOL> if group : <EOL> return ps + u'<STR_LIT:U+0020>' + self . group_members ( r , writes , owner ) <EOL> else : <EOL> return ps <EOL> def group_perm ( self , code , perm , owner ) : <EOL> n = len_exc ( perm . exceptions , owner ) <EOL> if perm . policy == u'<STR_LIT>' : <EOL> return code if n > <NUM_LIT:0> else u'<STR_LIT:->' <EOL> else : <EOL> return u'<STR_LIT:->' if n > <NUM_LIT:0> else code <EOL> def fi_perm_desc ( self , perm ) : <EOL> return ( u'<STR_LIT>' <EOL> % ( perm . policy , <EOL> u'<STR_LIT:U+002CU+0020>' . join ( u for u in perm . exceptions ) ) ) <EOL> def ns_perms_string ( self , ns , group = False ) : <EOL> h = self . get_ns_perms_hash ( ns ) <EOL> for k in h : <EOL> if type ( h [ k ] ) in ( int , long ) : <EOL> return '<STR_LIT>' <EOL> s = [ ] <EOL> owner = ns . split ( u'<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> r = h [ u'<STR_LIT>' ] <EOL> control = h [ u'<STR_LIT>' ] <EOL> writes = ( h [ u'<STR_LIT>' ] , h [ u'<STR_LIT>' ] , h [ u'<STR_LIT>' ] ) <EOL> ownerRead = r . accessible ( u'<STR_LIT:r>' , owner ) <EOL> ownerWrites = [ w . accessible ( u'<STR_LIT:w>' , owner ) for w in writes ] <EOL> worldRead = r . isOpen ( u'<STR_LIT:r>' ) <EOL> worldWrites = [ w . isOpen ( u'<STR_LIT:w>' ) for w in writes ] <EOL> ownerWrite = write_status ( ownerWrites ) <EOL> worldWrite = write_status ( worldWrites ) <EOL> ownerControl = control . accessible ( u'<STR_LIT:c>' , owner ) <EOL> worldControl = control . isOpen ( u'<STR_LIT:c>' ) <EOL> groupRead = self . group_perm ( u'<STR_LIT:r>' , r , owner ) <EOL> groupWrite = combined_status ( [ self . group_perm ( u'<STR_LIT:w>' , w , owner ) <EOL> for w in writes ] ) <EOL> groupControl = self . group_perm ( u'<STR_LIT:c>' , control , owner ) <EOL> ps = u'<STR_LIT>' % ( ownerRead , ownerWrite , ownerControl , <EOL> groupRead , groupWrite , groupControl , <EOL> worldRead , worldWrite , worldControl ) <EOL> if group : <EOL> return ps + u'<STR_LIT:U+0020>' + self . group_members ( r , writes , owner ) <EOL> else : <EOL> return ps <EOL> def group_members ( self , r , writes , owner ) : <EOL> if r . isOpen ( u'<STR_LIT:r>' ) == u'<STR_LIT:r>' : <EOL> gr = u'<STR_LIT>' . join ( ( u'<STR_LIT>' % e ) for e in r . exceptions <EOL> if not e == owner ) <EOL> else : <EOL> gr = u'<STR_LIT:+>' . join ( e for e in r . exceptions if not e == owner ) <EOL> gw = [ ] <EOL> for w in writes : <EOL> if w . isOpen ( u'<STR_LIT:w>' ) == u'<STR_LIT:w>' : <EOL> g = u'<STR_LIT>' . join ( ( u'<STR_LIT>' % e ) for e in w . exceptions <EOL> if not e == owner ) <EOL> else : <EOL> g = u'<STR_LIT:+>' . join ( e for e in w . exceptions if not e == owner ) <EOL> gw . append ( g ) <EOL> gw = gw [ <NUM_LIT:0> ] if all ( w == gw [ <NUM_LIT:0> ] for w in gw ) else u'<STR_LIT>' <EOL> if gw == u'<STR_LIT>' : <EOL> gw = u'<STR_LIT>' <EOL> if gr == u'<STR_LIT>' : <EOL> gr = u'<STR_LIT>' <EOL> if gw == gr : <EOL> gs = gr <EOL> else : <EOL> gs = u'<STR_LIT>' % ( gr , gw ) <EOL> return gs <EOL> def perms_string ( self , tagOrNS , longer = False , group = False , longest = False ) : <EOL> tagOrNS = tagOrNS . strip ( ) <EOL> if tagOrNS . endswith ( u'<STR_LIT:/>' ) : <EOL> if longer or longest : <EOL> p = FluidinfoPerms ( self , u'<STR_LIT:/>' + tagOrNS [ : - <NUM_LIT:1> ] , isTag = False ) <EOL> p . compressIfPoss = not longest <EOL> return unicode ( p ) <EOL> else : <EOL> return self . ns_perms_string ( tagOrNS [ : - <NUM_LIT:1> ] , group ) <EOL> else : <EOL> if longer or longest : <EOL> p = FluidinfoPerms ( self , u'<STR_LIT:/>' + tagOrNS , isTag = True ) <EOL> p . compressIfPoss = not longest <EOL> return unicode ( p ) <EOL> else : <EOL> try : <EOL> return self . tag_perms_string ( tagOrNS , group ) <EOL> except AttributeError : <EOL> raise PermissionsError ( u'<STR_LIT>' <EOL> u'<STR_LIT>' % tagOrNS ) <EOL> def full_perms ( self , tagOrNS , longer , group = False , longest = False ) : <EOL> perms = self . perms_string ( tagOrNS , longer , group , longest ) <EOL> if longer or longest : <EOL> return u'<STR_LIT>' % ( tagOrNS , perms ) <EOL> else : <EOL> return u'<STR_LIT>' % ( perms , tagOrNS ) <EOL> def set_raw_perm ( self , entity , path , action , policy , exceptions ) : <EOL> assert entity in RAW_PERM_ENTITIES <EOL> perm = RAW_PERMS [ entity ] <EOL> assert action in perm . actions <EOL> assert policy in ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> assert not type ( exceptions ) in types . StringTypes <EOL> body = json . dumps ( { u'<STR_LIT>' : policy , u'<STR_LIT>' : exceptions } ) <EOL> path = u'<STR_LIT>' % ( perm . path , path ) <EOL> if self . debug : <EOL> self . Print ( u'<STR_LIT>' % ( path , body , action ) ) <EOL> status , content = self . call ( u'<STR_LIT>' , path , body , action = action ) <EOL> return <NUM_LIT:0> if status == fishlib . STATUS . NO_CONTENT else status <EOL> def write_status ( writes ) : <EOL> if all ( w == u'<STR_LIT:w>' for w in writes ) : <EOL> return u'<STR_LIT:w>' <EOL> else : <EOL> return u'<STR_LIT:->' if all ( w == u'<STR_LIT:->' for w in writes ) else u'<STR_LIT:/>' <EOL> def execute_ls_command ( db , objs , tags , options , credentials , unixPaths = None ) : <EOL> long_ = options . long or options . group or options . longest <EOL> if len ( tags ) == <NUM_LIT:0> : <EOL> tags = [ ( u'<STR_LIT:/>' if db . unixStyle else u'<STR_LIT>' ) + db . credentials . username ] <EOL> for tag in tags : <EOL> fulltag = db . abs_tag_path ( tag , inPref = True ) <EOL> if options . namespace or options . ns : <EOL> if db . ns_exists ( fulltag ) : <EOL> if long_ or options . longer or options . longest : <EOL> nsResult = db . full_perms ( fulltag [ <NUM_LIT:1> : ] + u'<STR_LIT:/>' , <EOL> options . longer , options . group , <EOL> options . longest ) <EOL> else : <EOL> nsResult = fulltag <EOL> db . Print ( nsResult ) <EOL> else : <EOL> nsResult = u'<STR_LIT>' <EOL> else : <EOL> nsResult = db . list_sorted_ns ( fulltag [ <NUM_LIT:1> : ] , long_ = long_ , <EOL> recurse = options . recurse , prnt = True , <EOL> longer = options . longer , <EOL> longest = options . longest ) <EOL> tagExists = db . tag_exists ( fulltag ) <EOL> if nsResult == '<STR_LIT>' : <EOL> if not tagExists : <EOL> db . Print ( u'<STR_LIT>' % fulltag ) <EOL> if tagExists : <EOL> if long_ or options . longer or options . longest : <EOL> db . Print ( db . full_perms ( fulltag [ <NUM_LIT:1> : ] , options . longer , <EOL> options . group , options . longest ) ) <EOL> else : <EOL> db . Print ( tag ) <EOL> def execute_rm_command ( db , objs , tags , options , credentials , unixPaths = None ) : <EOL> if len ( tags ) == <NUM_LIT:0> : <EOL> raise RemoveError ( '<STR_LIT>' ) <EOL> failures = [ ] <EOL> for tag in tags : <EOL> nsDone = tagDone = False <EOL> fulltag = db . abs_tag_path ( tag , inPref = True ) <EOL> if db . ns_exists ( fulltag ) : <EOL> if options . recurse : <EOL> nsResult = db . rm_r ( fulltag [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> nsResult = db . delete_namespace ( fulltag ) <EOL> if nsResult : <EOL> raise RemoveError ( fishlib . human_status ( nsResult , <EOL> db . abs_tag_path ( tag , True , True ) , <EOL> { <NUM_LIT> : '<STR_LIT>' } ) ) <EOL> nsDone = True <EOL> if db . tag_exists ( fulltag ) : <EOL> if options . force or options . recurse : <EOL> db . untag_by_query ( u'<STR_LIT>' % fulltag [ <NUM_LIT:1> : ] , <EOL> [ fulltag [ <NUM_LIT:1> : ] ] ) <EOL> else : <EOL> ids = db . query ( u'<STR_LIT>' % fulltag [ <NUM_LIT:1> : ] ) <EOL> if type ( ids ) in ( int , long ) : <EOL> raise RemoveError ( fishlib . human_status ( ids ) ) <EOL> elif len ( ids ) > <NUM_LIT:0> : <EOL> raise RemoveError ( u'<STR_LIT>' <EOL> % ( flags . Plural ( len ( ids ) , <EOL> '<STR_LIT:object>' ) . decode ( '<STR_LIT>' ) , <EOL> db . abs_tag_path ( tag , True , True ) , <EOL> u'<STR_LIT>' ) ) <EOL> tagResult = db . delete_abstract_tag ( fulltag ) <EOL> if tagResult : <EOL> raise RemoveError ( fishlib . human_status ( tagResult , <EOL> db . abs_tag_path ( tag , True , True ) ) ) <EOL> tagDone = True <EOL> if not nsDone and not tagDone : <EOL> failures . append ( tag ) <EOL> if failures : <EOL> if not options . force : <EOL> raise RemoveError ( u'<STR_LIT>' <EOL> % u'<STR_LIT:U+0020>' . join ( failures ) ) <EOL> def execute_chmod_command ( db , objs , args , options , credentials , unixPaths = None ) : <EOL> db . warning ( '<STR_LIT>' ) <EOL> return <EOL> def execute_perms_command ( db , objs , args , options , credentials , unixPaths = None ) : <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> db . Print ( u'<STR_LIT>' ) <EOL> return <EOL> spec = args [ <NUM_LIT:0> ] <EOL> primitives = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> if not ( spec in [ u'<STR_LIT>' , u'<STR_LIT:default>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] + primitives ) : <EOL> raise PermissionsError ( u'<STR_LIT>' <EOL> % u'<STR_LIT:U+002CU+0020>' . join ( spec + primitives ) ) <EOL> isGroup = spec . startswith ( u'<STR_LIT>' ) <EOL> if isGroup : <EOL> group = args [ <NUM_LIT:1> ] . split ( u'<STR_LIT:+>' ) <EOL> if len ( args ) < <NUM_LIT:3> : <EOL> raise PermissionsError ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' % spec ) <EOL> if spec in primitives : <EOL> errorText = ( u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' % ( spec , spec ) ) <EOL> if len ( args ) < <NUM_LIT:3> or not args [ <NUM_LIT:1> ] in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> raise PermissionsError ( errorText ) <EOL> policy = args [ <NUM_LIT:1> ] <EOL> exceptions = args [ <NUM_LIT:3> ] . split ( u'<STR_LIT:+>' ) if args [ <NUM_LIT:2> ] == u'<STR_LIT>' else [ ] <EOL> fullpaths = ( db . abs_tag_path ( t , inPref = True ) <EOL> for t in args [ <NUM_LIT:2> + <NUM_LIT:2> * bool ( exceptions ) : ] ) <EOL> if options . extravals : <EOL> for v in options . extravals : <EOL> assert v in ALL_NAMES <EOL> else : <EOL> fullpaths = ( db . abs_tag_path ( t , inPref = True ) <EOL> for t in args [ <NUM_LIT:1> + isGroup : ] ) <EOL> for path in fullpaths : <EOL> done = False <EOL> owner = path . split ( u'<STR_LIT:/>' ) [ <NUM_LIT:1> ] <EOL> permsToSet = ALL_NAMES <EOL> for ( exists , isTag ) in ( ( db . tag_exists , True ) , ( db . ns_exists , False ) ) : <EOL> if exists ( path ) : <EOL> inPerms = FluidinfoPerms ( db , path , isTag = isTag , <EOL> getFromFI = False ) <EOL> if spec == u'<STR_LIT>' : <EOL> inPerms . set_to_private ( ) <EOL> elif spec == u'<STR_LIT:default>' : <EOL> inPerms . set_to_default ( ) <EOL> elif spec == u'<STR_LIT>' : <EOL> inPerms = FluidinfoPerms ( db , path , isTag = isTag , <EOL> getFromFI = True ) <EOL> inPerms . lock ( ) <EOL> elif spec == u'<STR_LIT>' : <EOL> inPerms = FluidinfoPerms ( db , path , isTag = isTag , <EOL> getFromFI = True ) <EOL> inPerms . unlock ( ) <EOL> elif isGroup : <EOL> inPerms = FluidinfoPerms ( db , path , isTag = isTag , <EOL> getFromFI = True ) <EOL> if spec in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> inPerms . set_group_readable ( group ) <EOL> if spec in ( u'<STR_LIT>' , u'<STR_LIT>' ) : <EOL> inPerms . set_group_writable ( group ) <EOL> else : <EOL> if spec == u'<STR_LIT>' : <EOL> permsToSet = CONTROL_NAMES <EOL> elif spec == u'<STR_LIT>' : <EOL> permsToSet = WRITE_NAMES <EOL> else : <EOL> permsToSet = READ_NAMES <EOL> for name in permsToSet : <EOL> if hasattr ( inPerms , name ) : <EOL> inPerms . __dict__ [ name ] . policy = policy <EOL> inPerms . __dict__ [ name ] . exceptions = exceptions <EOL> inPerms . update_fluidinfo ( db , permsToSet , options . force , <EOL> restrict_to = options . extravals , <EOL> verbose = options . verbose ) <EOL> done = True <EOL> if not done : <EOL> db . Print ( '<STR_LIT>' % db . abs_tag_path ( path , <EOL> outPref = True ) ) </s>
