本文整理匯總了Python中DIRAC.ConfigurationSystem.private.Modificator.Modificator.sortAlphabetically方法的典型用法代碼示例。如果您正苦於以下問題:Python Modificator.sortAlphabetically方法的具體用法?Python Modificator.sortAlphabetically怎麽用?Python Modificator.sortAlphabetically使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DIRAC.ConfigurationSystem.private.Modificator.Modificator
的用法示例。
在下文中一共展示了Modificator.sortAlphabetically方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 別名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import sortAlphabetically [as 別名]
#.........這裏部分代碼省略.........
prevVal = self.__csMod.getValue( "%s/Hosts/%s/%s" % ( self.__baseSecurity, hostname, prop ) )
if not prevVal or prevVal != properties[ prop ]:
gLogger.info( "Setting %s property for host %s to %s" % ( prop, hostname, properties[ prop ] ) )
self.__csMod.setOptionValue( "%s/Hosts/%s/%s" % ( self.__baseSecurity, hostname, prop ), properties[ prop ] )
modifiedHost = True
if modifiedHost:
gLogger.info( "Modified host %s" % hostname )
self.__csModified = True
else:
gLogger.info( "Nothing to modify for host %s" % hostname )
return S_OK( True )
def syncUsersWithCFG( self, usersCFG ):
"""
Sync users with the cfg contents. Usernames have to be sections containing
DN, Groups, and extra properties as parameters
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
done = True
for user in usersCFG.listSections():
properties = {}
propList = usersCFG[ user ].listOptions()
for prop in propList:
if prop == "Groups":
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()
示例2: CSAPI
# 需要導入模塊: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 別名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import sortAlphabetically [as 別名]
#.........這裏部分代碼省略.........
prevVal = self.__csMod.getValue( "%s/Hosts/%s/%s" % ( self.__baseSecurity, hostname, prop ) )
if not prevVal or prevVal != properties[ prop ]:
gLogger.info( "Setting %s property for host %s to %s" % ( prop, hostname, properties[ prop ] ) )
self.__csMod.setOptionValue( "%s/Hosts/%s/%s" % ( self.__baseSecurity, hostname, prop ), properties[ prop ] )
modifiedHost = True
if modifiedHost:
gLogger.info( "Modified host %s" % hostname )
self.csModified = True
else:
gLogger.info( "Nothing to modify for host %s" % hostname )
return S_OK( True )
def syncUsersWithCFG( self, usersCFG ):
"""
Sync users with the cfg contents. Usernames have to be sections containing
DN, Groups, and extra properties as parameters
"""
if not self.__initialized[ 'OK' ]:
return self.__initialized
done = True
for user in usersCFG.listSections():
properties = {}
propList = usersCFG[ user ].listOptions()
for prop in propList:
if prop == "Groups":
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 )
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()