本文整理汇总了Python中DIRAC.ConfigurationSystem.private.Modificator.Modificator.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Modificator.commit方法的具体用法?Python Modificator.commit怎么用?Python Modificator.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ConfigurationSystem.private.Modificator.Modificator
的用法示例。
在下文中一共展示了Modificator.commit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import commit [as 别名]
#.........这里部分代码省略.........
properties[ prop ] = List.fromChar( usersCFG[ user ][ prop ] )
else:
properties[ prop ] = usersCFG[ user ][ prop ]
if not self.modifyUser( user, properties, createIfNonExistant = True ):
done = False
return S_OK( done )
def sortUsersAndGroups( self ):
self.__csMod.sortAlphabetically( "%s/Users" % self.__baseSecurity )
self.__csMod.sortAlphabetically( "%s/Hosts" % self.__baseSecurity )
for group in self.__csMod.getSections( "%s/Groups" % self.__baseSecurity ):
usersOptionPath = "%s/Groups/%s/Users" % ( self.__baseSecurity, group )
users = self.__csMod.getValue( usersOptionPath )
usersList = List.fromChar( users )
usersList.sort()
sortedUsers = ", ".join( usersList )
if users != sortedUsers:
self.__csMod.setOptionValue( usersOptionPath, sortedUsers )
def checkForUnexistantUsersInGroups( self ):
allUsers = self.__csMod.getSections( "%s/Users" % self.__baseSecurity )
allGroups = self.__csMod.getSections( "%s/Groups" % self.__baseSecurity )
for group in allGroups:
usersInGroup = self.__csMod.getValue( "%s/Groups/%s/Users" % ( self.__baseSecurity, group ) )
if usersInGroup:
filteredUsers = []
usersInGroup = List.fromChar( usersInGroup )
for user in usersInGroup:
if user in allUsers:
filteredUsers.append( user )
self.__csMod.setOptionValue( "%s/Groups/%s/Users" % ( self.__baseSecurity, group ),
",".join( filteredUsers ) )
def commitChanges( self, sortUsers = True ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
if self.__csModified:
self.checkForUnexistantUsersInGroups()
if sortUsers:
self.sortUsersAndGroups()
retVal = self.__csMod.commit()
if not retVal[ 'OK' ]:
gLogger.error( "Can't commit new data: %s" % retVal[ 'Message' ] )
return retVal
return self.downloadCSData()
return S_OK()
def commit( self ):
""" Commit the accumulated changes to the CS server
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
if self.__csModified:
retVal = self.__csMod.commit()
if not retVal[ 'OK' ]:
gLogger.error( "Can't commit new data: %s" % retVal[ 'Message' ] )
return retVal
return self.downloadCSData()
return S_OK()
def mergeFromCFG( self, cfg ):
""" Merge the internal CFG data with the input
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
self.__csMod.mergeFromCFG( cfg )
示例2: CSAPI
# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import commit [as 别名]
#.........这里部分代码省略.........
else:
properties[ prop ] = usersCFG[ user ][ prop ]
if not self.modifyUser( user, properties, createIfNonExistant = True ):
done = False
return S_OK( done )
def sortUsersAndGroups( self ):
self.__csMod.sortAlphabetically( "%s/Users" % self.__baseSecurity )
self.__csMod.sortAlphabetically( "%s/Hosts" % self.__baseSecurity )
for group in self.__csMod.getSections( "%s/Groups" % self.__baseSecurity ):
usersOptionPath = "%s/Groups/%s/Users" % ( self.__baseSecurity, group )
users = self.__csMod.getValue( usersOptionPath )
if users:
usersList = List.fromChar( users )
usersList.sort()
sortedUsers = ", ".join( usersList )
if users != sortedUsers:
self.__csMod.setOptionValue( usersOptionPath, sortedUsers )
def checkForUnexistantUsersInGroups( self ):
allUsers = self.__csMod.getSections( "%s/Users" % self.__baseSecurity )
allGroups = self.__csMod.getSections( "%s/Groups" % self.__baseSecurity )
for group in allGroups:
usersInGroup = self.__csMod.getValue( "%s/Groups/%s/Users" % ( self.__baseSecurity, group ) )
if usersInGroup:
filteredUsers = []
usersInGroup = List.fromChar( usersInGroup )
for user in usersInGroup:
if user in allUsers:
filteredUsers.append( user )
self.__csMod.setOptionValue( "%s/Groups/%s/Users" % ( self.__baseSecurity, group ),
",".join( filteredUsers ) )
def commitChanges( self, sortUsers = True ):
if not self.__initialized[ 'OK' ]:
return self.__initialized
if self.csModified:
self.checkForUnexistantUsersInGroups()
if sortUsers:
self.sortUsersAndGroups()
retVal = self.__csMod.commit()
if not retVal[ 'OK' ]:
gLogger.error( "Can't commit new configuration data", "%s" % retVal[ 'Message' ] )
return retVal
return self.downloadCSData()
return S_OK()
def commit( self ):
""" Commit the accumulated changes to the CS server
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
if self.csModified:
retVal = self.__csMod.commit()
if not retVal[ 'OK' ]:
gLogger.error( "Can't commit new configuration data", "%s" % retVal[ 'Message' ] )
return retVal
return self.downloadCSData()
return S_OK()
def mergeFromCFG( self, cfg ):
""" Merge the internal CFG data with the input
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
self.__csMod.mergeFromCFG( cfg )
示例3: CSShellCLI
# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import commit [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 commit [as 别名]
#.........这里部分代码省略.........
self.printPair( option, self.modificator.getValue( optionPath ), "=" )
else:
print "Option %s does not exist" % optionPath
except:
_showTraceback()
def do_writeToServer( self, dummy ):
"""
Sends changes to server.
Usage: writeToServer
"""
if not self.connected:
print "You are not connected!"
return
try:
if not self.writeEnabled:
print "This server can't receive data modifications"
return
if not self.modifiedData:
while True:
choice = raw_input( "Data has not been modified, do you still want to upload changes? yes/no [no]: " )
choice = choice.lower()
if choice in ( "yes", "y" ):
break
else:
print "Commit aborted"
return
choice = raw_input( "Do you really want to send changes to server? yes/no [no]: " )
choice = choice.lower()
if choice in ( "yes", "y" ):
print "Uploading changes to %s (It may take some seconds)..." % self.masterURL
response = self.modificator.commit()
if response[ 'OK' ]:
self.modifiedData = False
print "Data sent to server."
self.modificator.loadFromRemote()
else:
print "Error sending data, server said: %s" % response['Message']
return
else:
print "Commit aborted"
except Exception as x:
_showTraceback()
print "Could not upload changes. ", str( x )
def do_set( self, args ):
"""
Sets option's value
Usage: set <optionPath> <value>...
From second argument until the last one is considered option's value
NOTE: If specified section does not exist it is created.
"""
try:
argsList = args.split()
if len( argsList ) < 2:
print "Must specify option and value to use"
return
optionPath = argsList[0].strip()
value = " ".join( argsList[1:] ).strip()
self.modificator.setOptionValue( optionPath, value )
self.modifiedData = True