syncpackage:

- Show changes to be synced when performing native syncs.
- Support --bug (extra bugs to be closed by the sync) with
  native syncs. (Bugs are closed one individually, via the API, post-sync)
This commit is contained in:
Benjamin Drung 2011-09-03 22:39:04 +02:00
commit a3378ee9fc
3 changed files with 66 additions and 14 deletions

7
debian/changelog vendored
View File

@ -15,7 +15,12 @@ ubuntu-dev-tools (0.129) UNRELEASED; urgency=low
- lp-set-dup
- lp-shell
-- Jelmer Vernooij <jelmer@debian.org> Thu, 01 Sep 2011 19:38:53 +0200
[ Stefano Rivera ]
* syncpackage: Show changes to be synced when performing native syncs.
* syncpackage: Support --bug (extra bugs to be closed by the sync) with
native syncs. (Bugs are closed one individually, via the API, post-sync)
-- Stefano Rivera <stefanor@debian.org> Sat, 03 Sep 2011 21:04:38 +0200
ubuntu-dev-tools (0.128) unstable; urgency=low

View File

@ -35,11 +35,13 @@ from lazr.restfulclient.errors import HTTPError
from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage,
DownloadError)
from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.requestsync.common import getDebianChangelog
from ubuntutools.requestsync.mail import (getDebianSrcPkg
as requestsync_mail_getDebianSrcPkg)
from ubuntutools.requestsync.lp import getDebianSrcPkg, getUbuntuSrcPkg
from ubuntutools.lp import udtexceptions
from ubuntutools.lp.lpapicache import Distribution, Launchpad
from ubuntutools.lp.lpapicache import (Distribution, Launchpad,
SourcePackagePublishingHistory)
from ubuntutools.misc import split_release_pocket
from ubuntutools.question import YesNoQuestion
from ubuntutools import subprocess
@ -100,7 +102,7 @@ def add_fixed_bugs(changes, bugs):
changes = [l for l in changes.split("\n") if l.strip() != ""]
# Remove duplicates
bugs = set(bugs)
bugs = set(str(bug) for bug in bugs)
for i in xrange(len(changes)):
if changes[i].startswith("Launchpad-Bugs-Fixed:"):
@ -308,7 +310,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror):
return DebianSourcePackage(package, version.full_version, component,
mirrors=mirrors)
def copy(src_pkg, release, simulate=False, force=False):
def copy(src_pkg, release, bugs, simulate=False, force=False):
"""Copy a source package from Debian to Ubuntu using the Launchpad API."""
ubuntu = Distribution('ubuntu')
debian_archive = Distribution('debian').getArchive()
@ -321,10 +323,12 @@ def copy(src_pkg, release, simulate=False, force=False):
# Ensure that the provided Debian version actually exists.
try:
debian_archive.getPublishedSources(
source_name=src_pkg.source,
version=src_pkg.version.full_version,
exact_match=True)[0]
debian_spph = SourcePackagePublishingHistory(
debian_archive.getPublishedSources(
source_name=src_pkg.source,
version=src_pkg.version.full_version,
exact_match=True)[0]
)
except IndexError:
Logger.error('Debian version %s does not exist!', src_pkg.version)
sys.exit(1)
@ -342,6 +346,7 @@ def copy(src_pkg, release, simulate=False, force=False):
ubuntu_pkg.version, src_pkg.version)
ubuntu_version = Version(ubuntu_pkg.version.full_version)
base_version = ubuntu_version.get_related_debian_version()
if not force and ubuntu_version.is_modified_in_ubuntu():
Logger.error('--force is required to discard Ubuntu changes.')
sys.exit(1)
@ -354,9 +359,15 @@ def copy(src_pkg, release, simulate=False, force=False):
'mismatch. A fake sync using --no-lp is required.')
sys.exit(1)
except udtexceptions.PackageNotFoundException:
base_version = Version('~')
Logger.normal('Source %s -> %s/%s: not in Ubuntu, new version %s',
src_pkg.source, ubuntu_series, ubuntu_pocket,
src_pkg.version)
changes = getDebianChangelog(debian_spph, base_version).strip()
if changes:
Logger.normal("New Changes:\n%s", changes)
if simulate:
return
@ -380,6 +391,16 @@ def copy(src_pkg, release, simulate=False, force=False):
Logger.normal('Request succeeded; you should get an e-mail once it is '
'processed.')
bugs = sorted(set(bugs))
if bugs:
Logger.normal("Launchpad bugs to be closed: %s",
', '.join(str(bug) for bug in bugs))
Logger.normal('Please wait for the sync to be successful before '
'closing bugs.')
answer = YesNoQuestion().ask("Close bugs", "yes")
if answer == "yes":
close_bugs(bugs, src_pkg.source, src_pkg.version.full_version,
changes)
def is_blacklisted(query):
""""Determine if package "query" is in the sync blacklist
@ -419,6 +440,29 @@ def is_blacklisted(query):
applicable_comments.append(comment)
return False
def close_bugs(bugs, package, version, changes):
"""Close the correct task on all bugs, with changes"""
ubuntu = Launchpad.distributions['ubuntu']
message = ("This bug was fixed in the package %s - %s"
"\n\n---------------\n%s" % (
package, version, changes))
for bug in bugs:
bug = Launchpad.bugs[bug]
if bug.duplicate_of is not None:
bug = bug.duplicate_of
for task in bug.bug_tasks:
target = task.target
if target == ubuntu or (target.name == package and
getattr(target, 'distribution', None) == ubuntu):
if task.status != 'Fix Released':
Logger.normal("Closed bug %s", task.web_link)
task.status = 'Fix Released'
task.lp_save()
bug.newMessage(content=message)
break
else:
Logger.error(u"Cannot find any tasks on LP: #%i to close.", bug.id)
def main():
usage = "%prog [options] <.dsc URL/path or package name>"
epilog = "See %s(1) for more info." % os.path.basename(sys.argv[0])
@ -496,10 +540,10 @@ def main():
parser.error('Multiple .dsc URLs/paths or package names specified: '
+ ', '.join(args))
invalid_bug_numbers = [bug for bug in options.bugs if not bug.isdigit()]
if len(invalid_bug_numbers) > 0:
parser.error('Invalid bug number(s) specified: '
+ ', '.join(invalid_bug_numbers))
try:
options.bugs = map(int, options.bugs)
except TypeError:
parser.error('Invalid bug number(s) specified.')
if options.component not in (None, "main", "contrib", "non-free"):
parser.error('%s is not a valid Debian component. '
@ -560,7 +604,8 @@ def main():
sys.exit(1)
if options.lp:
copy(src_pkg, options.release, options.simulate, options.force)
copy(src_pkg, options.release, options.bugs, options.simulate,
options.force)
else:
os.environ['DEB_VENDOR'] = 'Ubuntu'
sync_dsc(src_pkg, options.dist, options.release, options.uploader_name,

View File

@ -38,9 +38,11 @@ def raw_input_exit_on_ctrlc(*args, **kwargs):
print '\nAbort requested. No sync request filed.'
sys.exit(1)
# TODO: Move this into requestsync.mail, and implement an LP version
# when LP: #833384 is fixed
def getDebianChangelog(srcpkg, version):
'''
Return the new changelog entries upto 'version'.
Return the new changelog entries since 'version'.
'''
pkgname = srcpkg.getPackageName()
pkgversion = srcpkg.getVersion()