90
93
# load stored LP credentials
92
print _("Get Launchpad Settings")
96
print _("Get Launchpad Settings")
93
98
lp_cred_file = open(lp_cred, 'r')
94
99
credentials = Credentials()
95
100
credentials.load(lp_cred_file)
96
101
lp_cred_file.close()
97
launchpad = Launchpad(credentials, SERVICE_ROOT, lp_cache_dir)
99
print _('Initial Launchpad binding. You must choose "Change Anything"')
100
launchpad = Launchpad.get_token_and_login('quickly', SERVICE_ROOT, lp_cache_dir)
101
lp_cred_file = open(lp_cred, 'w')
102
launchpad.credentials.save(lp_cred_file)
107
(return_code, suggestion) = bzrbinding.bzr_set_login(me.display_name, me.preferred_email_address.email, me.name)
109
if launchpad is None or return_code != 0:
110
if suggestion is None:
111
suggestion = _("Unknown reason")
113
die(_("Couldn't setup Launchpad for quickly ; %s") % suggestion)
114
print _("Launchpad connexion is ok")
103
launchpad = Launchpad(credentials, SERVICE_ROOT, lp_cache_dir)
104
except httplib2.ServerNotFoundError, e:
105
raise launchpad_connection_error(e)
106
except (IOError, HTTPError):
108
# case where autorization on Launchpad was removed
110
os.remove(lp_cred_file.name)
111
print _('Previous Launchpad values seems to have been removed. You must choose again "Change Anything"')
113
print _('Initial Launchpad binding. You must choose "Change Anything"')
114
launchpad = Launchpad.get_token_and_login('quickly', SERVICE_ROOT, lp_cache_dir)
115
lp_cred_file = open(lp_cred, 'w')
116
launchpad.credentials.save(lp_cred_file)
121
(return_code, suggestion) = bzrbinding.bzr_set_login(me.display_name, me.preferred_email_address.email, me.name)
124
if launchpad is None or return_code != 0:
125
if suggestion is None:
126
suggestion = _("Unknown reason")
128
raise launchpad_connection_error(_("Couldn't setup Launchpad for quickly ; %s") % suggestion)
129
print _("Launchpad connection is ok")
119
def link_project(launchpad, question):
134
def link_project(launchpad, question, lp_project_name=None):
120
135
''' Link to launchpad project, erasing previous one if already set
123
138
: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.")
140
# if config not already loaded
141
if not configurationhandler.project_config:
142
configurationhandler.loadConfig()
144
if not lp_project_name:
148
lp_id = raw_input("%s, leave blank to abort.\nLaunchpad project name: " % question)
150
raise launchpad_project_error(_("No launchpad project given, aborting."))
152
prospective_projects = launchpad.projects.search(text=lp_id)
155
for project in prospective_projects:
156
print (_('''---------------- [%s] ----------------
158
--------------------------------------
162
''') % (project_number, project.title, project.display_name, launchpad_url, project.name, project.summary))
163
project_names.append(project.name)
166
if not list(prospective_projects):
167
message = _("No project found")
169
message = _("Choose your project number")
170
choice = raw_input("%s, leave blank to abort, 0 for another search.\nYour choice: " % message)
174
if choice in range(1, project_number):
175
project = launchpad.projects[project_names[choice - 1]]
179
raise launchpad_project_error(_("No right number given, aborting."))
181
# we got a project name, check that it exists
184
project = launchpad.projects[lp_project_name]
186
raise launchpad_project_error(_("Can't find %s project on Launchpad. You can try to find it interactively without providing a project name.") % lp_project_name)
162
188
configurationhandler.project_config['lp_id'] = project.name
163
189
configurationhandler.saveConfig()