1
# -*- coding: utf-8 -*-
2
# Copyright 2009 Canonical Ltd.
3
# Author 2009 Didier Roche
5
# This file is part of Quickly
7
#This program is free software: you can redistribute it and/or modify it
8
#under the terms of the GNU General Public License version 3, as published
9
#by the Free Software Foundation.
11
#This program is distributed in the hope that it will be useful, but
12
#WITHOUT ANY WARRANTY; without even the implied warranties of
13
#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
#PURPOSE. See the GNU General Public License for more details.
16
#You should have received a copy of the GNU General Public License along
17
#with this program. If not, see <http://www.gnu.org/licenses/>.
24
LAUNCHPAD_URL = "https://launchpad.net"
25
LAUNCHPAD_STAGING_URL = "https://staging.launchpad.net"
26
LAUNCHPAD_CODE_STAGING_URL = "https://code.staging.launchpad.net"
30
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT, STAGING_SERVICE_ROOT
31
from launchpadlib.errors import HTTPError
32
from launchpadlib.credentials import Credentials
34
suggestion = _("Check whether python-launchpadlib is installed")
37
from quickly import bzrbinding
38
from quickly import configurationhandler
41
from gettext import gettext as _
44
# if config not already loaded
45
if not configurationhandler.project_config:
46
configurationhandler.loadConfig()
48
# check if there is no global variable specifying staging
49
if os.getenv('QUICKLY') is not None and "staging" in os.getenv('QUICKLY').lower():
50
launchpad_url = LAUNCHPAD_STAGING_URL
53
launchpad_url = LAUNCHPAD_URL
60
print >> sys.stderr, _("Fatal: ") + message
65
''' Initialize launchpad binding, asking for crendential
67
:return the launchpad object
72
# setup right cache, credential and server
73
lp_cache_dir = os.path.expanduser('~/.quickly-data/cache/')
74
if not os.path.isdir(lp_cache_dir):
75
os.makedirs(lp_cache_dir)
77
lp_cred_dir = os.path.expanduser("~/.quickly-data/lp_credentials/")
78
if not os.path.isdir(lp_cred_dir):
79
os.makedirs(lp_cred_dir)
80
os.chmod(lp_cred_dir, 0700)
82
# check which server to address
83
if lp_server == "staging":
84
lp_cred = lp_cred_dir + "quickly-cred-staging"
85
SERVICE_ROOT = STAGING_SERVICE_ROOT
86
print _("WARNING: you are using staging and not launchpad real production server")
88
lp_cred = lp_cred_dir + "quickly-cred"
89
SERVICE_ROOT = EDGE_SERVICE_ROOT
91
# load stored LP credentials
93
print _("Get Launchpad Settings")
94
lp_cred_file = open(lp_cred, 'r')
95
credentials = Credentials()
96
credentials.load(lp_cred_file)
98
launchpad = Launchpad(credentials, SERVICE_ROOT, lp_cache_dir)
100
print _('Initial Launchpad binding. You must choose "Change Anything"')
101
launchpad = Launchpad.get_token_and_login('quickly', SERVICE_ROOT, lp_cache_dir)
102
lp_cred_file = open(lp_cred, 'w')
103
launchpad.credentials.save(lp_cred_file)
108
bzrbinding.bzr_set_login(me.display_name, me.preferred_email_address.email, me.name)
110
if launchpad is None:
111
if suggestion is None:
112
suggestion = _("Unknown reason")
113
die(_("Couldn't setup Launchpad for quickly ; %s") % suggestion)
114
print _("Launchpad connexion is ok")
119
def link_project(launchpad, question):
120
''' Link to launchpad project, erasing previous one if already set
123
:return project object'''
128
lp_id = raw_input("%s, leave blank to abort.\nLaunchpad project name: " % question)
130
print _("No launchpad project give, aborting.")
133
prospective_projects = launchpad.projects.search(text=lp_id)
136
for project in prospective_projects:
137
print ("---------------- [%s] ----------------") % project_number
138
print " " + project.title
139
print ("--------------------------------------")
140
print _("Project name: %s") % project.display_name
141
print _("Launchpad url: %s/%s") % (launchpad_url, project.name)
142
project_names.append(project.name)
143
print project.summary
147
if not list(prospective_projects):
148
message = _("No project found")
150
message = _("Choose your project number")
151
choice = raw_input("%s, leave blank to abort, 0 for another search.\nYour choice: " % message)
155
if choice in range(1, project_number):
156
project = launchpad.projects[project_names[choice - 1]]
160
print _("No right number given, aborting.")
162
configurationhandler.project_config['lp_id'] = project.name
163
configurationhandler.saveConfig()
167
def get_project(launchpad):
168
''' Get quickly project through launchpad.
170
:return project object
175
lp_id = configurationhandler.project_config['lp_id']
176
project = launchpad.projects[lp_id]
178
# else, bind the project to LP
180
project = link_project(launchpad, "No Launchpad project set")