diff options
author | Mart Raudsepp <leio@gentoo.org> | 2016-12-04 08:26:47 +0200 |
---|---|---|
committer | Mart Raudsepp <leio@gentoo.org> | 2016-12-04 08:26:47 +0200 |
commit | d1965a898e3f92f94accb630d4daf68d156a0d0c (patch) | |
tree | a63c668a3ccbea4ffb912bff5a16aaea6055fe45 | |
parent | models: Add association table and ORM relationship between projects and members (diff) | |
download | grumpy-d1965a898e3f92f94accb630d4daf68d156a0d0c.tar.gz grumpy-d1965a898e3f92f94accb630d4daf68d156a0d0c.tar.bz2 grumpy-d1965a898e3f92f94accb630d4daf68d156a0d0c.zip |
sync: Project members and subprojects syncing to DB
-rw-r--r-- | backend/lib/sync.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/backend/lib/sync.py b/backend/lib/sync.py index 6ed8e01..57a7cb1 100644 --- a/backend/lib/sync.py +++ b/backend/lib/sync.py @@ -78,9 +78,33 @@ def sync_projects(): print ("Adding project %s" % email) new_maintainer = Maintainer(email=data['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: + members.append(existing_maintainers[member['email']]) + else: + print("Adding individual %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() - def sync_categories(): url = pkg_url_base + "categories.json" data = http_session.get(url) |