#NEWLINE# def import_distinct_roles( source , target ) : #NEWLINE# #INDENT# source_group_names = set ( [ group . name for group in source . getGroups ( ) ] ) #NEWLINE# required_target_group_names = [ group . name for group in target . getGroups ( ) if ( group . name in source_group_names ) ] #NEWLINE# required_for_import_role_names = set ( [ ] ) #NEWLINE# for name in required_target_group_names : #NEWLINE# #INDENT# required_for_import_role_names |= set ( [ ur . name for ur in source . getGroupRoles ( name ) ] ) #NEWLINE# #UNINDENT# roles = source . getRoles ( ) #NEWLINE# slave_role_names = set ( [ role . name for role in target . getRoles ( ) ] ) #NEWLINE# for role in roles : #NEWLINE# #INDENT# if ( role . name not in slave_role_names ) : #NEWLINE# #INDENT# if ( role . name in required_for_import_role_names ) : #NEWLINE# #INDENT# target . createRole ( group ) #NEWLINE# permissions = source . getRolePermissions ( role ) #NEWLINE# for permission in permissions : #NEWLINE# #INDENT# target . addPermissionToRole ( role , permission )