本文整理汇总了Python中DIRAC.ConfigurationSystem.private.Modificator.Modificator类的典型用法代码示例。如果您正苦于以下问题:Python Modificator类的具体用法?Python Modificator怎么用?Python Modificator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Modificator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__( self ):
cmd.Cmd.__init__( self )
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator ( self.rpcClient )
else:
self.modificator = Modificator()
self.identSpace = 20
self.backupFilename = "dataChanges"
self._initSignals()
#User friendly hack
self.do_exit = self.do_quit
# store history
histfilename = os.path.basename(sys.argv[0])
historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
if not os.path.exists( os.path.dirname(historyFile) ):
os.makedirs( os.path.dirname(historyFile) )
if os.path.isfile( historyFile ):
readline.read_history_file( historyFile )
readline.set_history_length(1000)
atexit.register( readline.write_history_file, historyFile )
示例2: __getRemoteConfiguration
def __getRemoteConfiguration(self):
rpcClient = getRPCClient(gConfig.getValue("/DIRAC/Configuration/MasterServer", "Configuration/Server"))
modCfg = Modificator(rpcClient)
retVal = modCfg.loadFromRemote()
if retVal["OK"]:
session["cfgData"] = str(modCfg)
session["csName"] = "%s Configuration" % (modCfg.getValue("/DIRAC/VirtualOrganization"))
session.save()
c.cfgData = modCfg.cfgData
c.csName = session["csName"]
return retVal
示例3: __getRemoteConfiguration
def __getRemoteConfiguration(self, funcName):
rpcClient = RPCClient(gConfig.getValue("/DIRAC/Configuration/MasterServer", "Configuration/Server"))
modCfg = Modificator(rpcClient)
retVal = modCfg.loadFromRemote()
if not retVal[ 'OK' ]:
return {"success":0, "op":"getSubnodes", "message":"The configuration cannot be read from the remote !"}
self.__configData[ 'cfgData' ] = modCfg
self.__configData[ 'strCfgData' ] = str(modCfg)
version = str(modCfg.getCFG()["DIRAC"]["Configuration"]["Version"])
configName = str(modCfg.getCFG()["DIRAC"]["Configuration"]["Name"])
return {"success":1, "op":funcName, "version":version, "name":configName}
示例4: CSShellCmd
class CSShellCmd(cmd.Cmd):
def __init__(self):
cmd.Cmd.__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:
示例5: do_connect
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()
示例6: __init__
def __init__(self):
cmd.Cmd.__init__(self)
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator(self.rpcClient)
else:
self.modificator = Modificator()
self.identSpace = 20
self.backupFilename = "dataChanges"
self._initSignals()
# User friendly hack
self.do_exit = self.do_quit
示例7: __init__
def __init__( self ):
CLI.__init__( self )
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator ( self.rpcClient )
else:
self.modificator = Modificator()
self.indentSpace = 20
self.backupFilename = "dataChanges"
# store history
histfilename = os.path.basename(sys.argv[0])
historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
mkDir(os.path.dirname(historyFile))
if os.path.isfile( historyFile ):
readline.read_history_file( historyFile )
readline.set_history_length(1000)
atexit.register( readline.write_history_file, historyFile )
示例8: initialize
def initialize( self ):
if not gConfig.useServerCertificate():
res = self.__getProxyID()
else:
res = self.__getCertificateID()
if not res:
return False
retVal = gConfig.getOption( "/DIRAC/Configuration/MasterServer" )
if not retVal[ 'OK' ]:
gLogger.warn( "Master server is not known. Is everything initialized?" )
return False
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' ]:
gLogger.error( "Can not download the remote cfg. Is everything initialized?" )
return False
return True
示例9: initialize
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
示例10: __init__
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
#.........这里部分代码省略.........
示例11: CSCLI
class CSCLI( cmd.Cmd ):
def __init__( self ):
cmd.Cmd.__init__( self )
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator ( self.rpcClient )
else:
self.modificator = Modificator()
self.identSpace = 20
self.backupFilename = "dataChanges"
self._initSignals()
#User friendly hack
self.do_exit = self.do_quit
# store history
histfilename = os.path.basename(sys.argv[0])
historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
if not os.path.exists( os.path.dirname(historyFile) ):
os.makedirs( os.path.dirname(historyFile) )
if os.path.isfile( historyFile ):
readline.read_history_file( historyFile )
readline.set_history_length(1000)
atexit.register( readline.write_history_file, historyFile )
def start( self ):
if self.connected:
self.modificator.loadFromRemote()
retVal = self.modificator.loadCredentials()
if not retVal[ 'OK' ]:
print "There was an error gathering your credentials"
print retVal[ 'Message' ]
self._setStatus( False )
try:
self.cmdloop()
except KeyboardInterrupt:
gLogger.warn( "Received a keyboard interrupt." )
self.do_quit( "" )
def _initSignals( self ):
"""
Registers signal handlers
"""
for sigNum in ( signal.SIGINT, signal.SIGQUIT, signal.SIGKILL, signal.SIGTERM ):
try:
signal.signal( sigNum, self.do_quit )
except:
pass
def _setConnected( self, connected, writeEnabled ):
self.connected = connected
self.modifiedData = False
self.writeEnabled = writeEnabled
if connected:
if writeEnabled:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected", "green" ) )
else:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected (RO)", "yellow" ) )
else:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Disconnected", "red" ) )
def _printPair( self, key, value, separator = ":" ):
valueList = value.split( "\n" )
print "%s%s%s %s" % ( key, " " * ( self.identSpace - len( key ) ), separator, valueList[0].strip() )
for valueLine in valueList[ 1:-1 ]:
print "%s %s" % ( " " * self.identSpace, valueLine.strip() )
def do_quit( self, dummy ):
"""
Exits the application without sending changes to server
Usage: quit
"""
if self.modifiedData:
print "Changes are about to be written to file for later use."
self.do_writeToFile( self.backupFilename )
print "Changes written to %s.cfg" % self.backupFilename
sys.exit( 0 )
def do_EOF( self, args ):
"""
Accepts ctrl^D to quit CLI
"""
print ""
self.do_quit( args )
def do_help( self, args ):
"""
Shows help information
Usage: help <command>
If no command is specified all commands are shown
#.........这里部分代码省略.........
示例12: CSShellCLI
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)
#.........这里部分代码省略.........
示例13: CSAPI
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 ):
#.........这里部分代码省略.........
示例14: CSCLI
class CSCLI( CLI ):
def __init__( self ):
CLI.__init__( self )
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator ( self.rpcClient )
else:
self.modificator = Modificator()
self.indentSpace = 20
self.backupFilename = "dataChanges"
# store history
histfilename = os.path.basename(sys.argv[0])
historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
if not os.path.exists( os.path.dirname(historyFile) ):
os.makedirs( os.path.dirname(historyFile) )
if os.path.isfile( historyFile ):
readline.read_history_file( historyFile )
readline.set_history_length(1000)
atexit.register( readline.write_history_file, historyFile )
def start( self ):
if self.connected:
self.modificator.loadFromRemote()
retVal = self.modificator.loadCredentials()
if not retVal[ 'OK' ]:
print "There was an error gathering your credentials"
print retVal[ 'Message' ]
self._setStatus( False )
try:
self.cmdloop()
except KeyboardInterrupt:
gLogger.warn( "Received a keyboard interrupt." )
self.do_quit( "" )
def _setConnected( self, connected, writeEnabled ):
self.connected = connected
self.modifiedData = False
self.writeEnabled = writeEnabled
if connected:
if writeEnabled:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected", "green" ) )
else:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected (RO)", "yellow" ) )
else:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Disconnected", "red" ) )
def do_quit( self, dummy ):
"""
Exits the application without sending changes to server
Usage: quit
"""
print
if self.modifiedData:
print "Changes are about to be written to file for later use."
self.do_writeToFile( self.backupFilename )
print "Changes written to %s.cfg" % self.backupFilename
sys.exit( 0 )
# def retrieveData( self ):
# if not self.connected:
# return False
# response = self.rpcClient.dumpCompressed()
# if response[ 'Status' ] == 'OK':
# self.cDataHolder.loadFromCompressedSource( response[ 'Value' ] )
# gLogger.info( "Data retrieved from server." )
# return True
# else:
# gLogger.error( "Can't retrieve updated data from server." )
# return False
def _setStatus( self, connected = True ):
if not connected:
self.masterURL = "unset"
self._setConnected( False, False )
else:
retVal = self.rpcClient.writeEnabled()
if retVal[ 'OK' ]:
if retVal[ 'Value' ] == True:
self._setConnected( True, True )
else:
self._setConnected( True, False )
else:
print "Server returned an error: %s" % retVal[ 'Message' ]
self._setConnected( True, False )
def _tryConnection( self ):
print "Trying connection to %s" % self.masterURL
try:
self.rpcClient = RPCClient( self.masterURL )
self._setStatus()
except Exception, x:
#.........这里部分代码省略.........
示例15: CSCLI
class CSCLI( CLI ):
def __init__( self ):
CLI.__init__( self )
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator ( self.rpcClient )
else:
self.modificator = Modificator()
self.indentSpace = 20
self.backupFilename = "dataChanges"
# store history
histfilename = os.path.basename(sys.argv[0])
historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
mkDir(os.path.dirname(historyFile))
if os.path.isfile( historyFile ):
readline.read_history_file( historyFile )
readline.set_history_length(1000)
atexit.register( readline.write_history_file, historyFile )
def start( self ):
if self.connected:
self.modificator.loadFromRemote()
retVal = self.modificator.loadCredentials()
if not retVal[ 'OK' ]:
print "There was an error gathering your credentials"
print retVal[ 'Message' ]
self._setStatus( False )
try:
self.cmdloop()
except KeyboardInterrupt:
gLogger.warn( "Received a keyboard interrupt." )
self.do_quit( "" )
def _setConnected( self, connected, writeEnabled ):
self.connected = connected
self.modifiedData = False
self.writeEnabled = writeEnabled
if connected:
if writeEnabled:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected", "green" ) )
else:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected (RO)", "yellow" ) )
else:
self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Disconnected", "red" ) )
def do_quit( self, dummy ):
"""
Exits the application without sending changes to server
Usage: quit
"""
print
if self.modifiedData:
print "Changes are about to be written to file for later use."
self.do_writeToFile( self.backupFilename )
print "Changes written to %s.cfg" % self.backupFilename
sys.exit( 0 )
# def retrieveData( self ):
# if not self.connected:
# return False
# response = self.rpcClient.dumpCompressed()
# if response[ 'Status' ] == 'OK':
# self.cDataHolder.loadFromCompressedSource( response[ 'Value' ] )
# gLogger.info( "Data retrieved from server." )
# return True
# else:
# gLogger.error( "Can't retrieve updated data from server." )
# return False
def _setStatus( self, connected = True ):
if not connected:
self.masterURL = "unset"
self._setConnected( False, False )
else:
retVal = self.rpcClient.writeEnabled()
if retVal[ 'OK' ]:
if retVal[ 'Value' ] == True:
self._setConnected( True, True )
else:
self._setConnected( True, False )
else:
print "Server returned an error: %s" % retVal[ 'Message' ]
self._setConnected( True, False )
def _tryConnection( self ):
print "Trying connection to %s" % self.masterURL
try:
self.rpcClient = RPCClient( self.masterURL )
self._setStatus()
except Exception as x:
gLogger.error( "Couldn't connect to master CS server", "%s (%s)" % ( self.masterURL, str( x ) ) )
#.........这里部分代码省略.........