Monty Taylor | 6c9634c | 2012-07-28 11:27:47 -0500 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # Copyright (C) 2011 OpenStack, LLC. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | # Add launchpad ids listed in the wiki CLA page to the CLA group in LP. |
| 17 | |
| 18 | import os |
| 19 | import urllib |
| 20 | import re |
| 21 | |
| 22 | from launchpadlib.launchpad import Launchpad |
| 23 | from launchpadlib.uris import LPNET_SERVICE_ROOT |
| 24 | |
| 25 | DEBUG = False |
| 26 | |
| 27 | LP_CACHE_DIR = '~/.launchpadlib/cache' |
| 28 | LP_CREDENTIALS = '~/.launchpadlib/creds' |
| 29 | CONTRIBUTOR_RE = re.compile(r'.*?\|\|\s*(?P<name>.*?)\s*\|\|\s*(?P<login>.*?)\s*\|\|\s*(?P<trans>.*?)\s*\|\|.*?') |
| 30 | LINK_RE = re.compile(r'\[\[.*\|\s*(?P<name>.*)\s*\]\]') |
| 31 | |
| 32 | for check_path in (os.path.dirname(LP_CACHE_DIR), |
| 33 | os.path.dirname(LP_CREDENTIALS)): |
| 34 | if not os.path.exists(check_path): |
| 35 | os.makedirs(check_path) |
| 36 | |
| 37 | wiki_members = [] |
| 38 | for line in urllib.urlopen('http://wiki.openstack.org/Contributors?action=raw'): |
| 39 | m = CONTRIBUTOR_RE.match(line) |
| 40 | if m and m.group('login') and m.group('trans'): |
| 41 | login = m.group('login') |
| 42 | if login=="<#c0c0c0>'''Launchpad ID'''": continue |
| 43 | l = LINK_RE.match(login) |
| 44 | if l: |
| 45 | login = l.group('name') |
| 46 | wiki_members.append(login) |
| 47 | |
| 48 | launchpad = Launchpad.login_with('CLA Team Sync', LPNET_SERVICE_ROOT, |
| 49 | LP_CACHE_DIR, |
Clark Boylan | 29c6965 | 2012-08-16 14:10:45 -0700 | [diff] [blame] | 50 | credentials_file = LP_CREDENTIALS, |
| 51 | version='devel') |
Monty Taylor | 6c9634c | 2012-07-28 11:27:47 -0500 | [diff] [blame] | 52 | |
| 53 | lp_members = [] |
| 54 | |
| 55 | team = launchpad.people['openstack-cla'] |
| 56 | for detail in team.members_details: |
| 57 | user = None |
| 58 | # detail.self_link == |
| 59 | # 'https://api.launchpad.net/1.0/~team/+member/${username}' |
| 60 | login = detail.self_link.split('/')[-1] |
| 61 | status = detail.status |
| 62 | lp_members.append(login) |
| 63 | |
| 64 | for wm in wiki_members: |
| 65 | if wm not in lp_members: |
| 66 | print "Need to add %s to LP" % (wm) |
| 67 | try: |
| 68 | person = launchpad.people[wm] |
| 69 | except: |
| 70 | print 'Unable to find %s on LP'%wm |
| 71 | continue |
| 72 | status = team.addMember(person=person, status="Approved") |