[sysadmin-bin] Improve performance
- From: Andrea Veri <averi src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Improve performance
- Date: Wed, 19 May 2021 13:05:12 +0000 (UTC)
commit d4bf30ce6e75c67d71b5fd42e5e5d2eaee8777d3
Author: Andrea Veri <averi redhat com>
Date: Wed May 19 15:04:57 2021 +0200
Improve performance
gitlab/gitlab-operations.py | 122 +++++++++++++++-----------------------------
1 file changed, 42 insertions(+), 80 deletions(-)
---
diff --git a/gitlab/gitlab-operations.py b/gitlab/gitlab-operations.py
index b0be633..3d65ccd 100755
--- a/gitlab/gitlab-operations.py
+++ b/gitlab/gitlab-operations.py
@@ -5,7 +5,6 @@ import gitlab
import re
sys.path.append('/home/admin/bin')
-sys.path.append('/home/admin/bin/git')
import gnome_ldap_utils as Glu
import semi_rdf
@@ -21,79 +20,51 @@ gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RW_TOKEN, api_vers
DOAP = "http://usefulinc.com/ns/doap#"
GNOME = "http://api.gnome.org/doap-extensions#"
-ldapusers = gl.users.list(all=True)
-ldapusers_dict = {}
-gnomecvs_members = glu.get_uids_from_group('gnomecvs')
-group = gl.groups.get(8, with_projects=False)
-gnomeusers = group.members.list(all=True)
-l10n_group = gl.groups.get(13336, with_projects=False)
-gnomeusers_dict = {}
-projects = group.projects.list(all=True)
-gnomecvs_exceptions = glu.get_uids_from_group('gnomecvs_exceptions')
-
-for user in ldapusers:
- for index, _ in enumerate(user.attributes['identities']):
- if user.attributes['identities'][index]['provider'] == 'ldapmain':
- ldapusers_dict[user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=',
'')] = user.attributes['id']
-
-for person in gnomeusers:
- # Slower but needed as group.member.get(id) does not return all the attributes we need
- user = gl.users.get(person.attributes['id'])
- for index, _ in enumerate(user.attributes['identities']):
- if user.attributes['identities'][index]['provider'] == 'ldapmain':
- gnomeusers_dict[user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=',
'')] = user.attributes['id']
-
-for username, id in ldapusers_dict.items():
- ssh_key = glu.get_attributes_from_ldap(username, 'ipaSshPubKey')
-
- if ssh_key is not None:
- user = gl.users.get(id)
- try:
- user.keys.create({'title': 'Imported from account.gnome.org', 'key': ssh_key.decode('utf-8')})
-
- print(f"Key for username { username } with id { id } has been added")
- except gitlab.exceptions.GitlabCreateError as e:
- if e.response_code == 400:
- pass
+committers = glu.get_uids_from_group('gnomecvs')
+committers_exceptions = glu.get_uids_from_group('gnomecvs_exceptions')
- try:
- # An else statement would be ideal here in terms of performances but
- # not all the users that logged in into Gitlab using the LDAP auth
- # backend are part of the gnomecvs group while the opposite is always true
- # as gnomecvs is effectively an LDAP POSIX group.
- if username in gnomecvs_members:
- group.members.create({'user_id': id,
- 'access_level': gitlab.DEVELOPER_ACCESS})
-
- print(f"Username { username } with id { id } has been added to the GNOME group")
- except gitlab.exceptions.GitlabCreateError as e:
- if e.response_code == 409:
- pass
+_committers = dict()
+for uid in committers:
+ try:
+ _committers[uid] = gl.users.list(extern_uid=(f"uid={ uid },{ LDAP_USER_BASE }"), \
+ provider='ldapmain')[0].id
+ except IndexError:
+ continue
+
+_committers_exceptions = dict()
+for uid in committers_exceptions:
+ try:
+ _committers_exceptions[uid] = gl.users.list(extern_uid=(f"uid={ uid },{ LDAP_USER_BASE }"), \
+ provider='ldapmain')[0].id
+ except IndexError:
+ continue
- try:
- if username in gnomecvs_members:
- l10n_group.members.create({'user_id': id,
- 'access_level': gitlab.REPORTER_ACCESS})
+gnome_group = gl.groups.get(8, with_projects=False)
+gnome_group_users = [ { i.username : i.id for i in gnome_group.members.list(all=True) } ]
+gnome_projects = gnome_group.projects.list(all=True)
- print(f"Username { username } with id { id } has been added to the Teams/Translation group")
- except gitlab.exceptions.GitlabCreateError as e:
- if e.response_code == 409:
- pass
+l10n_group = gl.groups.get(13336, with_projects=False)
-for username, id in gnomeusers_dict.items():
- if username not in gnomecvs_members:
- # Hardcode the list of GNOME group owners here
- if username in gnomecvs_exceptions:
- pass
- else:
- group.members.delete(id)
- print(f"Username { username } with id { id } has been removed from the GNOME group")
+for username, id in _committers.items():
+ if id not in gnome_group_users[0].values():
+ gnome_group.members.create({'user_id': id, 'access_level': gitlab.DEVELOPER_ACCESS})
+ print(f"Account with username { username } and with id { id } has been added to the GNOME group")
+
+ l10n_group.members.create({'user_id': id, 'access_level': gitlab.REPORTER_ACCESS})
+ print(f"Account with username { username } and id { id } has been added to the Teams/Translation
group")
+
+for username, id in gnome_group_users[0].items():
+ if id not in _committers.values() and id not in _committers_exceptions.values():
+ role = gnome_group.members.get(id).access_level
+ if role != 20 and id != 1:
+ gnome_group.members.delete(id)
+ print(f"Account with username { username } with id { id } has been removed from the GNOME group")
l10n_group.members.delete(id)
- print(f"Username { username } with id { id } has been removed from the Teams/Translation group")
+ print(f"Account with username { username } and id { id } has been removed from the
Teams/Translation group")
maints = dict()
-for project in projects:
+for project in gnome_projects:
project_name = project.attributes['path']
uids = []
@@ -156,22 +127,13 @@ for project in maints:
continue
for user in maints[project]:
- if user in gnomeusers_dict:
- userid = gnomeusers_dict[user]
- try:
- proj.members.create({'user_id': userid, 'access_level':
- gitlab.MASTER_ACCESS})
+ if user in _committers.keys():
+ userid = _committers[user]
+ if proj.members.get(userid).access_level != 40:
+ member = proj.members.get(userid)
+ proj.members.create({'user_id': userid, 'access_level': gitlab.MASTER_ACCESS})
print(f"Landed master level access to { user } against repository { project }")
- except gitlab.exceptions.GitlabCreateError as e:
- if e.response_code == 409:
- member = proj.members.get(userid)
- if member.attributes['access_level'] != 40:
- proj.members.delete(userid)
- proj.members.create({'user_id': userid, 'access_level':
- gitlab.MASTER_ACCESS})
-
- print(f"Landed master level access to { user } against repository { project }") %
(user, project)
members = proj.members.list()
members_dict = {}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]