本文整理汇总了Python中DIRAC.ConfigurationSystem.private.Modificator.Modificator.getSections方法的典型用法代码示例。如果您正苦于以下问题:Python Modificator.getSections方法的具体用法?Python Modificator.getSections怎么用?Python Modificator.getSections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ConfigurationSystem.private.Modificator.Modificator
的用法示例。
在下文中一共展示了Modificator.getSections方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getSections [as 别名]
class CSAPI:
def __init__( self ):
"""
Initialization function
"""
self.__csModified = False
self.__baseSecurity = "/Registry"
self.__userDN = ''
self.__userGroup = ''
self.__rpcClient = None
self.__csMod = None
self.__initialized = S_ERROR( "Not initialized" )
self.initialize()
if not self.__initialized[ 'OK' ]:
gLogger.error( self.__initialized )
def __getProxyID( self ):
proxyLocation = Locations.getProxyLocation()
if not proxyLocation:
gLogger.error( "No proxy found!" )
return False
chain = X509Chain()
if not chain.loadProxyFromFile( proxyLocation ):
gLogger.error( "Can't read proxy!", proxyLocation )
return False
retVal = chain.getIssuerCert()
if not retVal[ 'OK' ]:
gLogger.error( "Can't parse proxy!", retVal[ 'Message' ] )
return False
idCert = retVal[ 'Value' ]
self.__userDN = idCert.getSubjectDN()[ 'Value' ]
self.__userGroup = idCert.getDIRACGroup()[ 'Value' ]
return True
def __getCertificateID( self ):
certLocation = Locations.getHostCertificateAndKeyLocation()
if not certLocation:
gLogger.error( "No certificate found!" )
return False
chain = X509Chain()
retVal = chain.loadChainFromFile( certLocation[ 0 ] )
if not retVal[ 'OK' ]:
gLogger.error( "Can't parse certificate!", retVal[ 'Message' ] )
return False
idCert = chain.getIssuerCert()[ 'Value' ]
self.__userDN = idCert.getSubjectDN()[ 'Value' ]
self.__userGroup = 'host'
return True
def initialize( self ):
if self.__initialized[ 'OK' ]:
return self.__initialized
if not gConfig.useServerCertificate():
res = self.__getProxyID()
else:
res = self.__getCertificateID()
if not res:
self.__initialized = S_ERROR( "Cannot locate client credentials" )
return self.__initialized
retVal = gConfig.getOption( "/DIRAC/Configuration/MasterServer" )
if not retVal[ 'OK' ]:
self.__initialized = S_ERROR( "Master server is not known. Is everything initialized?" )
return self.__initialized
self.__rpcClient = RPCClient( gConfig.getValue( "/DIRAC/Configuration/MasterServer", "" ) )
self.__csMod = Modificator( self.__rpcClient, "%s - %s" % ( self.__userGroup, self.__userDN ) )
retVal = self.downloadCSData()
if not retVal[ 'OK' ]:
self.__initialized = S_ERROR( "Can not download the remote cfg. Is everything initialized?" )
return self.__initialized
self.__initialized = S_OK()
return self.__initialized
def downloadCSData( self ):
if not self.__csMod:
return S_ERROR( "CSAPI not yet initialized" )
result = self.__csMod.loadFromRemote()
if not result[ 'OK' ]:
return result
self.__csModified = False
self.__csMod.updateGConfigurationData()
return S_OK()
def listUsers( self , group = False ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
if not group:
return S_OK( self.__csMod.getSections( "%s/Users" % self.__baseSecurity ) )
else:
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
#.........这里部分代码省略.........
示例2: CSAPI
# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getSections [as 别名]
class CSAPI( object ):
""" CSAPI objects need an initialization phase
"""
def __init__( self ):
"""
Initialization function
"""
self.csModified = False
self.__baseSecurity = "/Registry"
self.__userDN = ''
self.__userGroup = ''
self.__rpcClient = None
self.__csMod = None
self.__initialized = S_ERROR( "Not initialized" )
self.initialize()
if not self.__initialized[ 'OK' ]:
gLogger.error( self.__initialized )
def __getProxyID( self ):
proxyLocation = Locations.getProxyLocation()
if not proxyLocation:
gLogger.error( "No proxy found!" )
return False
chain = X509Chain()
if not chain.loadProxyFromFile( proxyLocation ):
gLogger.error( "Can't read proxy!", proxyLocation )
return False
retVal = chain.getIssuerCert()
if not retVal[ 'OK' ]:
gLogger.error( "Can't parse proxy!", retVal[ 'Message' ] )
return False
idCert = retVal[ 'Value' ]
self.__userDN = idCert.getSubjectDN()[ 'Value' ]
self.__userGroup = chain.getDIRACGroup()[ 'Value' ]
return True
def __getCertificateID( self ):
certLocation = Locations.getHostCertificateAndKeyLocation()
if not certLocation:
gLogger.error( "No certificate found!" )
return False
chain = X509Chain()
retVal = chain.loadChainFromFile( certLocation[ 0 ] )
if not retVal[ 'OK' ]:
gLogger.error( "Can't parse certificate!", retVal[ 'Message' ] )
return False
idCert = chain.getIssuerCert()[ 'Value' ]
self.__userDN = idCert.getSubjectDN()[ 'Value' ]
self.__userGroup = 'host'
return True
def initialize( self ):
if self.__initialized[ 'OK' ]:
return self.__initialized
if not gConfig.useServerCertificate():
res = self.__getProxyID()
else:
res = self.__getCertificateID()
if not res:
self.__initialized = S_ERROR( "Cannot locate client credentials" )
return self.__initialized
retVal = gConfig.getOption( "/DIRAC/Configuration/MasterServer" )
if not retVal[ 'OK' ]:
self.__initialized = S_ERROR( "Master server is not known. Is everything initialized?" )
return self.__initialized
self.__rpcClient = RPCClient( gConfig.getValue( "/DIRAC/Configuration/MasterServer", "" ) )
self.__csMod = Modificator( self.__rpcClient, "%s - %s" % ( self.__userGroup, self.__userDN ) )
retVal = self.downloadCSData()
if not retVal[ 'OK' ]:
self.__initialized = S_ERROR( "Can not download the remote cfg. Is everything initialized?" )
return self.__initialized
self.__initialized = S_OK()
return self.__initialized
def downloadCSData( self ):
if not self.__csMod:
return S_ERROR( "CSAPI not yet initialized" )
result = self.__csMod.loadFromRemote()
if not result[ 'OK' ]:
return result
self.csModified = False
self.__csMod.updateGConfigurationData()
return S_OK()
def listUsers( self , group = False ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
if not group:
return S_OK( self.__csMod.getSections( "%s/Users" % self.__baseSecurity ) )
else:
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 ):
#.........这里部分代码省略.........
示例3: CSShellCLI
# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import getSections [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 getSections [as 别名]
#.........这里部分代码省略.........
Usage: connect <url>
"""
if not args or type( args ) not in types.StringTypes:
self.masterURL = gConfigurationData.getMasterServer()
if self.masterURL != "unknown" and self.masterURL:
self._tryConnection()
else:
self._setStatus( False )
else:
splitted = args.split()
if len( splitted ) == 0:
print "Must specify witch url to connect"
self._setStatus( False )
else:
self.masterURL = splitted[0].strip()
self._tryConnection()
def do_sections( self, args ):
"""
Shows all sections with their comments.
If no section is specified, root is taken.
Usage: sections <section>
"""
try:
argList = args.split()
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 ) ), "=" )