2009-08-04 13:43:31 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# lp.py - methods used by requestsync while interacting
|
|
|
|
# directly with Launchpad
|
|
|
|
#
|
|
|
|
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
|
|
|
#
|
2009-08-05 23:10:05 +02:00
|
|
|
# This module may contain code written by other authors/contributors to
|
|
|
|
# the main requestsync script. See there for their names.
|
|
|
|
#
|
2009-08-04 13:43:31 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
2009-08-05 23:10:05 +02:00
|
|
|
# as published by the Free Software Foundation; version 2
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2009-08-04 13:43:31 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2009-08-05 23:10:05 +02:00
|
|
|
# Please see the /usr/share/common-licenses/GPL-2 file for the full text
|
2009-08-04 13:43:31 +02:00
|
|
|
# of the GNU General Public License license.
|
|
|
|
|
2014-12-18 20:45:58 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2011-09-10 10:28:41 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
from debian.deb822 import Changes
|
2012-05-06 10:15:54 +02:00
|
|
|
from distro_info import DebianDistroInfo, DistroDataOutdated
|
2011-11-22 15:57:02 +02:00
|
|
|
from httplib2 import Http, HttpLib2Error
|
2011-06-25 17:53:44 +02:00
|
|
|
|
2012-10-22 21:42:58 +02:00
|
|
|
from ubuntutools.lp import udtexceptions
|
2010-12-23 00:01:39 +02:00
|
|
|
from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam,
|
|
|
|
DistributionSourcePackage)
|
2013-03-19 00:18:02 +01:00
|
|
|
from ubuntutools.logger import Logger
|
2011-11-13 20:15:19 +02:00
|
|
|
from ubuntutools.question import confirmation_prompt
|
2009-08-04 13:43:31 +02:00
|
|
|
|
2012-10-22 21:42:58 +02:00
|
|
|
|
2011-09-10 15:42:40 +02:00
|
|
|
def get_debian_srcpkg(name, release):
|
2010-12-22 23:04:29 +02:00
|
|
|
debian = Distribution('debian')
|
|
|
|
debian_archive = debian.getArchive()
|
2009-08-04 13:43:31 +02:00
|
|
|
|
2012-05-06 10:15:54 +02:00
|
|
|
try:
|
|
|
|
release = DebianDistroInfo().codename(release, None, release)
|
2014-12-18 20:45:58 +00:00
|
|
|
except DistroDataOutdated as e:
|
2012-05-06 10:15:54 +02:00
|
|
|
Logger.warn(e)
|
2009-08-04 13:43:31 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
return debian_archive.getSourcePackage(name, release)
|
2009-08-06 00:23:58 +02:00
|
|
|
|
2012-10-22 21:42:58 +02:00
|
|
|
|
2011-09-10 15:42:40 +02:00
|
|
|
def get_ubuntu_srcpkg(name, release, pocket='Release'):
|
2010-12-22 23:04:29 +02:00
|
|
|
ubuntu = Distribution('ubuntu')
|
|
|
|
ubuntu_archive = ubuntu.getArchive()
|
2009-08-06 00:23:58 +02:00
|
|
|
|
2012-10-22 21:42:58 +02:00
|
|
|
try:
|
|
|
|
return ubuntu_archive.getSourcePackage(name, release, pocket)
|
|
|
|
except udtexceptions.PackageNotFoundException:
|
|
|
|
if pocket != 'Release':
|
2012-10-22 22:09:31 +02:00
|
|
|
parent_pocket = 'Release'
|
|
|
|
if pocket == 'Updates':
|
|
|
|
parent_pocket = 'Proposed'
|
|
|
|
return get_ubuntu_srcpkg(name, release, parent_pocket)
|
2012-10-22 21:42:58 +02:00
|
|
|
raise
|
|
|
|
|
2009-08-07 14:07:46 +02:00
|
|
|
|
2011-09-10 15:42:40 +02:00
|
|
|
def need_sponsorship(name, component, release):
|
2010-12-22 23:04:29 +02:00
|
|
|
'''
|
|
|
|
Check if the user has upload permissions for either the package
|
|
|
|
itself or the component
|
|
|
|
'''
|
|
|
|
archive = Distribution('ubuntu').getArchive()
|
|
|
|
distroseries = Distribution('ubuntu').getSeries(release)
|
|
|
|
|
2010-12-23 00:01:39 +02:00
|
|
|
need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries,
|
|
|
|
name, component)
|
2010-12-22 23:04:29 +02:00
|
|
|
if need_sponsor:
|
2014-12-18 20:45:58 +00:00
|
|
|
print('''You are not able to upload this package directly to Ubuntu.
|
2009-08-07 14:07:46 +02:00
|
|
|
Your sync request shall require an approval by a member of the appropriate
|
|
|
|
sponsorship team, who shall be subscribed to this bug report.
|
|
|
|
This must be done before it can be processed by a member of the Ubuntu Archive
|
2014-12-18 20:45:58 +00:00
|
|
|
team.''')
|
2011-11-13 20:15:19 +02:00
|
|
|
confirmation_prompt()
|
2009-08-07 14:07:46 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
return need_sponsor
|
2009-08-12 13:46:21 +02:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-09-10 15:42:40 +02:00
|
|
|
def check_existing_reports(srcpkg):
|
2010-12-22 23:04:29 +02:00
|
|
|
'''
|
|
|
|
Check existing bug reports on Launchpad for a possible sync request.
|
|
|
|
|
|
|
|
If found ask for confirmation on filing a request.
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Fetch the package's bug list from Launchpad
|
2011-09-10 10:28:41 +02:00
|
|
|
pkg = Distribution('ubuntu').getSourcePackage(name=srcpkg)
|
2011-09-10 15:42:40 +02:00
|
|
|
pkg_bug_list = pkg.searchTasks(status=["Incomplete", "New", "Confirmed",
|
|
|
|
"Triaged", "In Progress",
|
|
|
|
"Fix Committed"],
|
|
|
|
omit_duplicates=True)
|
2010-12-22 23:04:29 +02:00
|
|
|
|
|
|
|
# Search bug list for other sync requests.
|
2011-09-10 15:42:40 +02:00
|
|
|
for bug in pkg_bug_list:
|
2010-12-22 23:04:29 +02:00
|
|
|
# check for Sync or sync and the package name
|
|
|
|
if not bug.is_complete and 'ync %s' % srcpkg in bug.title:
|
2014-12-18 20:45:58 +00:00
|
|
|
print('The following bug could be a possible duplicate sync bug '
|
|
|
|
'on Launchpad:\n'
|
|
|
|
' * %s (%s)\n'
|
|
|
|
'Please check the above URL to verify this before '
|
|
|
|
'continuing.'
|
|
|
|
% (bug.title, bug.web_link))
|
2011-11-13 20:15:19 +02:00
|
|
|
confirmation_prompt()
|
2009-08-22 17:39:38 +02:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-09-10 15:42:40 +02:00
|
|
|
def get_ubuntu_delta_changelog(srcpkg):
|
2011-09-10 10:28:41 +02:00
|
|
|
'''
|
|
|
|
Download the Ubuntu changelog and extract the entries since the last sync
|
|
|
|
from Debian.
|
|
|
|
'''
|
|
|
|
archive = Distribution('ubuntu').getArchive()
|
|
|
|
spph = archive.getPublishedSources(source_name=srcpkg.getPackageName(),
|
|
|
|
exact_match=True, pocket='Release')
|
|
|
|
debian_info = DebianDistroInfo()
|
|
|
|
topline = re.compile(r'^(\w%(name_chars)s*) \(([^\(\) \t]+)\)'
|
|
|
|
r'((\s+%(name_chars)s+)+)\;'
|
|
|
|
% {'name_chars': '[-+0-9a-z.]'},
|
|
|
|
re.IGNORECASE)
|
|
|
|
delta = []
|
|
|
|
for record in spph:
|
|
|
|
changes_url = record.changesFileUrl()
|
|
|
|
if changes_url is None:
|
2011-09-10 16:06:56 +02:00
|
|
|
# Native sync
|
|
|
|
break
|
2011-11-22 15:57:02 +02:00
|
|
|
try:
|
|
|
|
response, body = Http().request(changes_url)
|
2014-12-18 20:45:58 +00:00
|
|
|
except HttpLib2Error as e:
|
2011-11-22 15:57:02 +02:00
|
|
|
Logger.error(str(e))
|
|
|
|
break
|
|
|
|
if response.status != 200:
|
|
|
|
Logger.error("%s: %s %s", changes_url, response.status,
|
|
|
|
response.reason)
|
|
|
|
break
|
|
|
|
|
|
|
|
changes = Changes(Http().request(changes_url)[1])
|
2011-09-10 10:28:41 +02:00
|
|
|
for line in changes['Changes'].splitlines():
|
|
|
|
line = line[1:]
|
|
|
|
m = topline.match(line)
|
|
|
|
if m:
|
|
|
|
distribution = m.group(3).split()[0].split('-')[0]
|
|
|
|
if debian_info.valid(distribution):
|
|
|
|
break
|
|
|
|
if line.startswith(u' '):
|
|
|
|
delta.append(line)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
|
|
|
|
return '\n'.join(delta)
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-09-10 15:42:40 +02:00
|
|
|
def post_bug(srcpkg, subscribe, status, bugtitle, bugtext):
|
2010-12-22 23:04:29 +02:00
|
|
|
'''
|
|
|
|
Use the LP API to file the sync request.
|
|
|
|
'''
|
|
|
|
|
2014-12-18 20:45:58 +00:00
|
|
|
print('The final report is:\nSummary: %s\nDescription:\n%s\n'
|
|
|
|
% (bugtitle, bugtext))
|
2011-11-13 20:15:19 +02:00
|
|
|
confirmation_prompt()
|
2010-12-22 23:04:29 +02:00
|
|
|
|
|
|
|
if srcpkg:
|
|
|
|
bug_target = DistributionSourcePackage(
|
|
|
|
'%subuntu/+source/%s' % (Launchpad._root_uri, srcpkg))
|
|
|
|
else:
|
|
|
|
# new source package
|
|
|
|
bug_target = Distribution('ubuntu')
|
|
|
|
|
|
|
|
# create bug
|
2010-12-23 00:01:39 +02:00
|
|
|
bug = Launchpad.bugs.createBug(title=bugtitle, description=bugtext,
|
|
|
|
target=bug_target())
|
2010-12-22 23:04:29 +02:00
|
|
|
|
|
|
|
# newly created bugreports have only one task
|
|
|
|
task = bug.bug_tasks[0]
|
|
|
|
# only members of ubuntu-bugcontrol can set importance
|
|
|
|
if PersonTeam.me.isLpTeamMember('ubuntu-bugcontrol'):
|
|
|
|
task.importance = 'Wishlist'
|
|
|
|
task.status = status
|
|
|
|
task.lp_save()
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
bug.subscribe(person=PersonTeam(subscribe)())
|
2010-12-22 23:04:29 +02:00
|
|
|
|
2014-12-18 20:45:58 +00:00
|
|
|
print('Sync request filed as bug #%i: %s'
|
|
|
|
% (bug.id, bug.web_link))
|