本文整理匯總了Python中DIRAC.ConfigurationSystem.private.Modificator.Modificator.getOptions方法的典型用法代碼示例。如果您正苦於以下問題:Python Modificator.getOptions方法的具體用法?Python Modificator.getOptions怎麽用?Python Modificator.getOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DIRAC.ConfigurationSystem.private.Modificator.Modificator
的用法示例。
在下文中一共展示了Modificator.getOptions方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 別名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getOptions [as 別名]
#.........這裏部分代碼省略.........
users = self.__csMod.getValue( "%s/Groups/%s/Users" % ( self.__baseSecurity, group ) )
if not users:
return S_OK( [] )
else:
return S_OK( List.fromChar( users ) )
def listHosts( self ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__csMod.getSections( "%s/Hosts" % self.__baseSecurity ) )
def describeUsers( self, users = False ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__describeEntity( users ) )
def describeHosts( self, hosts = False ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__describeEntity( hosts, True ) )
def __describeEntity( self, mask, hosts = False ):
if hosts:
csSection = "%s/Hosts" % self.__baseSecurity
else:
csSection = "%s/Users" % self.__baseSecurity
if mask:
entities = [ entity for entity in self.__csMod.getSections( csSection ) if entity in mask ]
else:
entities = self.__csMod.getSections( csSection )
entitiesDict = {}
for entity in entities:
entitiesDict[ entity ] = {}
for option in self.__csMod.getOptions( "%s/%s" % ( csSection, entity ) ):
entitiesDict[ entity ][ option ] = self.__csMod.getValue( "%s/%s/%s" % ( csSection, entity, option ) )
if not hosts:
groupsDict = self.describeGroups()[ 'Value' ]
entitiesDict[ entity ][ 'Groups' ] = []
for group in groupsDict:
if 'Users' in groupsDict[ group ] and entity in groupsDict[ group ][ 'Users' ]:
entitiesDict[ entity ][ 'Groups' ].append( group )
entitiesDict[ entity ][ 'Groups' ].sort()
return entitiesDict
def listGroups( self ):
"""
List all groups
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__csMod.getSections( "%s/Groups" % self.__baseSecurity ) )
def describeGroups( self, mask = False ):
"""
List all groups that are in the mask (or all if no mask) with their properties
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
groups = [ group for group in self.__csMod.getSections( "%s/Groups" % self.__baseSecurity ) if not mask or ( mask and group in mask ) ]
groupsDict = {}
for group in groups:
groupsDict[ group ] = {}
for option in self.__csMod.getOptions( "%s/Groups/%s" % ( self.__baseSecurity, group ) ):
groupsDict[ group ][ option ] = self.__csMod.getValue( "%s/Groups/%s/%s" % ( self.__baseSecurity, group, option ) )
if option in ( "Users", "Properties" ):
groupsDict[ group ][ option ] = List.fromChar( groupsDict[ group ][ option ] )
示例2: CSAPI
# 需要導入模塊: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 別名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getOptions [as 別名]
#.........這裏部分代碼省略.........
else:
return S_OK( List.fromChar( users ) )
def listHosts( self ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__csMod.getSections( "%s/Hosts" % self.__baseSecurity ) )
def describeUsers( self, users = None ):
if users is None: users = []
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__describeEntity( users ) )
def describeHosts( self, hosts = None ):
if hosts is None:
hosts = []
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__describeEntity( hosts, True ) )
def __describeEntity( self, mask, hosts = False ):
if hosts:
csSection = "%s/Hosts" % self.__baseSecurity
else:
csSection = "%s/Users" % self.__baseSecurity
if mask:
entities = [ entity for entity in self.__csMod.getSections( csSection ) if entity in mask ]
else:
entities = self.__csMod.getSections( csSection )
entitiesDict = {}
for entity in entities:
entitiesDict[ entity ] = {}
for option in self.__csMod.getOptions( "%s/%s" % ( csSection, entity ) ):
entitiesDict[ entity ][ option ] = self.__csMod.getValue( "%s/%s/%s" % ( csSection, entity, option ) )
if not hosts:
groupsDict = self.describeGroups()[ 'Value' ]
entitiesDict[ entity ][ 'Groups' ] = []
for group in groupsDict:
if 'Users' in groupsDict[ group ] and entity in groupsDict[ group ][ 'Users' ]:
entitiesDict[ entity ][ 'Groups' ].append( group )
entitiesDict[ entity ][ 'Groups' ].sort()
return entitiesDict
def listGroups( self ):
"""
List all groups
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
return S_OK( self.__csMod.getSections( "%s/Groups" % self.__baseSecurity ) )
def describeGroups( self, mask = None ):
"""
List all groups that are in the mask (or all if no mask) with their properties
"""
if mask is None: mask = []
if not self.__initialized[ 'OK' ]:
return self.__initialized
groups = [ group for group in self.__csMod.getSections( "%s/Groups" % self.__baseSecurity ) if not mask or ( mask and group in mask ) ]
groupsDict = {}
for group in groups:
groupsDict[ group ] = {}
for option in self.__csMod.getOptions( "%s/Groups/%s" % ( self.__baseSecurity, group ) ):
groupsDict[ group ][ option ] = self.__csMod.getValue( "%s/Groups/%s/%s" % ( self.__baseSecurity, group, option ) )
if option in ( "Users", "Properties" ):
示例3: CSShellCLI
# 需要導入模塊: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 別名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getOptions [as 別名]
class CSShellCLI(CLI):
def __init__(self):
CLI.__init__(self)
self.serverURL = ""
self.serverName = ""
self.modificator = None
self.connected = False
self.dirty = False
self.root = "/"
self.do_connect("")
def update_prompt(self):
if self.connected:
self.prompt = "[" + colorize(self.serverName, "green") + ":" + self.root + " ]% "
else:
self.prompt = "[" + colorize("disconnected", "red") + ":" + self.root + " ]% "
def do_connect(self, line):
"""connect
Connect to the CS
Usage: connect <URL> (Connect to the CS at the specified URL)
connect (Connect to the default CS URL of your config)
"""
if line == "":
self.serverURL = gConfigurationData.getMasterServer()
self.serverName = gConfigurationData.getName()
else:
self.serverURL = self.serverName = line
if self.serverURL == None:
print "Unable to connect to the default server. Maybe you don't have a proxy ?"
return self.do_disconnect("")
print "Trying to connect to " + self.serverURL + "...",
self.modificator = Modificator(RPCClient(self.serverURL))
rv = self.modificator.loadFromRemote()
rv2 = self.modificator.loadCredentials()
if rv["OK"] == False or rv2["OK"] == False:
print "failed: ",
if rv["OK"] == False:
print rv["Message"]
else:
print rv2["Message"]
self.connected = False
self.update_prompt()
else:
self.connected = True
self.update_prompt()
print "done."
def do_disconnect(self, _line):
"""Disconnect from CS"""
if self.connected and self.dirty:
res = raw_input("Do you want to commit your changes into the CS ? [y/N] ")
if res.lower() in ["y", "yes"]:
self.do_commit("")
self.serverURL = self.serverName = ""
self.modificator = None
self.connected = False
self.update_prompt()
def do_ls(self, line):
"""ls
List the sections and options of CS of the current root"""
if self.connected:
secs = self.modificator.getSections(self.root)
opts = self.modificator.getOptions(self.root)
if line.startswith("-") and "l" in line:
for i in secs:
print colorize(i, "blue") + " "
for i in opts:
print i + " "
else:
for i in secs:
print colorize(i, "blue") + " ",
for i in opts:
print i + " ",
print ""
def do_cd(self, line):
"""cd
Go one directory deeper in the CS"""
# Check if invariant holds
if self.connected:
assert self.root == "/" or not self.root.endswith("/")
assert self.root.startswith("/")
secs = self.modificator.getSections(self.root)
if line == "..":
self.root = os.path.dirname(self.root)
self.update_prompt()
else:
if os.path.normpath(line) in secs:
if self.root == "/":
self.root = self.root + os.path.normpath(line)
else:
self.root = self.root + "/" + os.path.normpath(line)
#.........這裏部分代碼省略.........
示例4: CSCLI
# 需要導入模塊: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 別名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getOptions [as 別名]
#.........這裏部分代碼省略.........
if argList:
baseSection = argList[0].strip()
else:
baseSection = "/"
if not self.modificator.existsSection( baseSection ):
print "Section %s does not exist" % baseSection
return
sectionList = self.modificator.getSections( baseSection )
if not sectionList:
print "Section %s is empty" % baseSection
return
for section in sectionList:
section = "%s/%s" % ( baseSection, section )
self.printPair( section, self.modificator.getComment( section ) , " #" )
except:
_showTraceback()
def do_options( self, args ):
"""
Shows all options and values of a specified section
Usage: options <section>
"""
try:
argList = args.split()
if argList:
section = argList[0].strip()
else:
print "Which section?"
return
if not self.modificator.existsSection( section ):
print "Section %s does not exist" % section
return
optionsList = self.modificator.getOptions( section )
if not optionsList:
print "Section %s has no options" % section
return
for option in optionsList:
_printComment( self.modificator.getComment( "%s/%s" % ( section, option ) ) )
self.printPair( option, self.modificator.getValue( "%s/%s" % ( section, option ) ), "=" )
except:
_showTraceback()
def do_get( self, args ):
"""
Shows value and comment for specified option in section
Usage: get <path to option>
"""
try:
argList = args.split()
if argList:
optionPath = argList[0].strip()
else:
print "Which option?"
return
if self.modificator.existsOption( optionPath ):
option = optionPath.split( "/" )[-1]
_printComment( self.modificator.getComment( optionPath ) )
self.printPair( option, self.modificator.getValue( optionPath ), "=" )
else:
print "Option %s does not exist" % optionPath
except:
_showTraceback()
def do_writeToServer( self, dummy ):