aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Dartiguelongue <eva@gentoo.org>2017-01-22 13:18:00 +0100
committerGilles Dartiguelongue <eva@gentoo.org>2017-01-22 13:23:56 +0100
commit5e7347647516660603dddeedcf570d0cfef27b1a (patch)
tree9b32328eed88eb75298ba2cc9183e83a06168212
parentsync: sort imports according to PEP8 (diff)
downloadgrumpy-5e7347647516660603dddeedcf570d0cfef27b1a.tar.gz
grumpy-5e7347647516660603dddeedcf570d0cfef27b1a.tar.bz2
grumpy-5e7347647516660603dddeedcf570d0cfef27b1a.zip
sync: define project keys default values
Costs less than checking for it in each loop iteration and does no harm later to loop on empty lists.
-rw-r--r--backend/lib/sync.py64
1 files changed, 33 insertions, 31 deletions
diff --git a/backend/lib/sync.py b/backend/lib/sync.py
index 5e8240d..0aab3bc 100644
--- a/backend/lib/sync.py
+++ b/backend/lib/sync.py
@@ -28,7 +28,10 @@ def get_project_data():
if proj_elem.tag.lower() != 'project':
print("Skipping unknown <projects> subtag <%s>" % proj_elem.tag)
continue
- proj = {}
+ proj = {
+ 'members': [],
+ 'subprojects': [],
+ }
for elem in proj_elem:
tag = elem.tag.lower()
if tag in ['email']:
@@ -46,14 +49,11 @@ def get_project_data():
if member_tag in ['name', 'role']:
member[member_tag] = member_elem.text
if 'email' in member:
- if 'members' not in proj:
- proj['members'] = []
proj['members'].append(member)
elif tag == 'subproject':
if 'ref' in elem.attrib:
- if 'subprojects' not in proj:
- proj['subprojects'] = []
- # subprojects will be a list of (subproject_email, inherit-members) tuples where inherit-members is True or False. TODO: Might change if sync code will want it differently
+ # subprojects will be a list of (subproject_email, inherit-members) tuples where inherit-members is True or False.
+ # TODO: Might change if sync code will want it differently
proj['subprojects'].append((elem.attrib['ref'].lower(), True if ('inherit-members' in elem.attrib and elem.attrib['inherit-members'] == '1') else False))
else:
print("Invalid <subproject> tag inside project %s - required 'ref' attribute missing" % proj['email'] if 'email' in proj else "<unknown>")
@@ -86,32 +86,34 @@ def sync_projects():
new_maintainer = Maintainer(email=email, is_project=True, description=data['description'], name=data['name'], url=data['url'])
db.session.add(new_maintainer)
existing_maintainers[email] = new_maintainer
+
members = []
- if 'subprojects' in data:
- for subproject_email, inherit_members in data['subprojects']:
- # TODO: How should we handle inherit_members?
- if subproject_email in existing_maintainers:
- members.append(existing_maintainers[subproject_email])
- else:
- print("Creating new project entry for subproject: %s" % subproject_email)
- new_subproject = Maintainer(email=subproject_email, is_project=True)
- db.session.add(new_subproject)
- existing_maintainers[subproject_email] = new_subproject
- members.append(new_subproject)
- if 'members' in data:
- for member in data['members']:
- if member['email'] in existing_maintainers:
- # TODO: Stop overwriting the name from master data, if/once we have a proper sync source for individual maintainers (Gentoo LDAP?)
- if 'name' in member:
- existing_maintainers[member['email']].name = member['name']
- members.append(existing_maintainers[member['email']])
- else:
- print("Adding individual maintainer %s" % member['email'])
- new_maintainer = Maintainer(email=member['email'], is_project=False, name=member['name'] if 'name' in member else None)
- db.session.add(new_maintainer)
- existing_maintainers[member['email']] = new_maintainer
- members.append(new_maintainer)
- # TODO: Include role information in the association?
+
+ for subproject_email, inherit_members in data['subprojects']:
+ # TODO: How should we handle inherit_members?
+ if subproject_email in existing_maintainers:
+ members.append(existing_maintainers[subproject_email])
+ else:
+ print("Creating new project entry for subproject: %s" % subproject_email)
+ new_subproject = Maintainer(email=subproject_email, is_project=True)
+ db.session.add(new_subproject)
+ existing_maintainers[subproject_email] = new_subproject
+ members.append(new_subproject)
+
+ for member in data['members']:
+ if member['email'] in existing_maintainers:
+ # TODO: Stop overwriting the name from master data, if/once we have a proper sync source for individual maintainers (Gentoo LDAP?)
+ if 'name' in member:
+ existing_maintainers[member['email']].name = member['name']
+ members.append(existing_maintainers[member['email']])
+ else:
+ print("Adding individual maintainer %s" % member['email'])
+ new_maintainer = Maintainer(email=member['email'], is_project=False, name=member['name'] if 'name' in member else None)
+ db.session.add(new_maintainer)
+ existing_maintainers[member['email']] = new_maintainer
+ members.append(new_maintainer)
+
+ # TODO: Include role information in the association?
existing_maintainers[email].members = members
db.session.commit()