1
# -*- coding: utf-8 -*-
3
from launchpadlib.launchpad import Launchpad
4
from launchpadlib.credentials import Credentials
5
from launchpadlib.errors import HTTPError
6
from launchpadlib.launchpad import EDGE_SERVICE_ROOT
8
from teams.models import *
15
def lp_login(lp_instance=EDGE_SERVICE_ROOT):
16
cachedir = os.path.join(settings.PROJECT_PATH, 'lp_data/cache')
17
creddir = os.path.join(settings.PROJECT_PATH, 'lp_data/lp_credentials')
18
if not os.path.isdir(creddir):
20
cred = os.path.join(creddir, 'loco-directory.credentials')
22
if os.path.exists(cred):
23
credentials = Credentials()
24
credentials.load(open(cred))
25
launchpad = Launchpad(credentials, lp_instance, cachedir)
28
launchpad = Launchpad.get_token_and_login('loco-directory',
29
lp_instance, cachedir)
31
print >> sys.stderr, 'Error connecting to Launchpad: %s' % str(e)
35
launchpad.credentials.save(f)
39
def is_user_on_loco_council(user):
42
team = lp.people['ubuntu-lococouncil']
44
print >> sys.stderr, 'Something went wrong.'
46
return unicode(user) in [a.name for a in team.members]
48
def is_admin_or_owner(username, team):
49
# check just using the LD data
50
if username == team.owner:
52
if team.admins.filter(lpid=username):
55
# more complicated check :-/
58
lp_team = lp.people[team.lp_name]
60
print >> sys.stderr, 'Something went wrong.'
62
if lp_team.team_owner.is_team:
63
if filter(lambda a: a.name == username, lp_team.team_owner.members):