From e04d4df8894f5ec8becb143559acb767d2fb9a2d Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 24 Aug 2011 14:46:11 +0200 Subject: [PATCH 1/8] Check the sync blacklist --- syncpackage | 67 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/syncpackage b/syncpackage index ee4225c..74ad824 100755 --- a/syncpackage +++ b/syncpackage @@ -20,15 +20,17 @@ # # ################################################################## -import debian.deb822 -import debian.debian_support +import codecs import optparse import os +import re import shutil import sys +import urllib +import debian.deb822 +import debian.debian_support from devscripts.logger import Logger - from lazr.restfulclient.errors import HTTPError from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage, @@ -380,6 +382,27 @@ def copy(src_pkg, release, simulate=False, force=False): Logger.normal('Request succeeded; you should get an e-mail once it is ' 'processed.') +def is_blacklisted(query): + url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt' + with codecs.EncodedFile(urllib.urlopen(url), 'UTF-8') as f: + applicable_comments = [] + for line in f: + if not line.strip(): + applicable_comments = [] + continue + m = re.match(r'^\s*([a-z0-9.+-]+)?\s*(?:#\s*(.+)?)?$', line) + source, comment = m.groups() + if source and query == source: + if comment: + applicable_comments.append(comment) + if applicable_comments: + return u'; '.join(applicable_comments) + else: + return True + elif comment: + applicable_comments.append(comment) + return False + def main(): usage = "%prog [options] <.dsc URL/path or package name>" epilog = "See %s(1) for more info." % os.path.basename(sys.argv[0]) @@ -489,30 +512,32 @@ def main(): if args[0].endswith('.dsc'): parser.error('.dsc files can only be synced using --no-lp.') - if options.lpinstance is None: - options.lpinstance = config.get_value('LPINSTANCE') + if options.lpinstance is None: + options.lpinstance = config.get_value('LPINSTANCE') + try: + Launchpad.login(service=options.lpinstance, api_version='devel') + except IOError: + sys.exit(1) - try: - Launchpad.login(service=options.lpinstance, api_version='devel') - except IOError: - sys.exit(1) + if options.release is None: + ubuntu = Launchpad.distributions["ubuntu"] + options.release = ubuntu.current_series.name - src_pkg = fetch_source_pkg(args[0], options.dist, options.debversion, - options.component, options.release, None) + src_pkg = fetch_source_pkg(args[0], options.dist, options.debversion, + options.component, options.release, + options.debian_mirror) + blacklisted = is_blacklisted(src_pkg.source) + if blacklisted: + Logger.error("Source package is blacklisted") + if isinstance(blacklisted, basestring): + Logger.error(u"Reason: %s", blacklisted) + sys.exit(1) + + if options.lp: copy(src_pkg, options.release, options.simulate, options.force) else: - Launchpad.login_anonymously() - if options.release is None: - ubuntu = Launchpad.distributions["ubuntu"] - options.release = ubuntu.current_series.name - os.environ['DEB_VENDOR'] = 'Ubuntu' - - src_pkg = fetch_source_pkg(args[0], options.dist, options.debversion, - options.component, options.release, - options.debian_mirror) - sync_dsc(src_pkg, options.dist, options.release, options.uploader_name, options.uploader_email, options.bugs, options.ubuntu_mirror, options.keyid, options.simulate, options.force) From 1d1f86cb9c4784e57b229cbe37e4eabe71dddea9 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 24 Aug 2011 14:59:22 +0200 Subject: [PATCH 2/8] Docstring --- syncpackage | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syncpackage b/syncpackage index 74ad824..dafaf81 100755 --- a/syncpackage +++ b/syncpackage @@ -383,6 +383,10 @@ def copy(src_pkg, release, simulate=False, force=False): 'processed.') def is_blacklisted(query): + """"Determine if package "query" is in the sync blacklist + Returns True or a string of all relevant comments if blacklisted, + False if not + """ url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt' with codecs.EncodedFile(urllib.urlopen(url), 'UTF-8') as f: applicable_comments = [] From 1277344ec8820a8a2ace4583e50863a98ec17868 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 24 Aug 2011 19:52:21 +0200 Subject: [PATCH 3/8] Check the +localpackagediffs blacklist too --- syncpackage | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/syncpackage b/syncpackage index dafaf81..58b8ba6 100755 --- a/syncpackage +++ b/syncpackage @@ -387,6 +387,18 @@ def is_blacklisted(query): Returns True or a string of all relevant comments if blacklisted, False if not """ + # LP: + series = Launchpad.distributions['ubuntu'].current_series + diffs = series.getDifferencesTo(source_package_name_filter=query, + status='Needs attention') + if len(diffs) == 0: + comments = getDifferenceComments(source_package_name=query) + comment = '; '.join(c.body_text for c in comments) + if comment: + return comment + return True + + # Old blacklist: url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt' with codecs.EncodedFile(urllib.urlopen(url), 'UTF-8') as f: applicable_comments = [] From 76fabbe0baa1c6016b6ce1f9c41583d3a88d5e77 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 24 Aug 2011 19:54:02 +0200 Subject: [PATCH 4/8] Add blacklisting explanation --- syncpackage | 3 +++ 1 file changed, 3 insertions(+) diff --git a/syncpackage b/syncpackage index 58b8ba6..c00d1a9 100755 --- a/syncpackage +++ b/syncpackage @@ -548,6 +548,9 @@ def main(): Logger.error("Source package is blacklisted") if isinstance(blacklisted, basestring): Logger.error(u"Reason: %s", blacklisted) + Logger.error("If you think this package shouldn't be blacklisted, " + "please file a bug explaining your reasoning and " + "subscribe ~ubuntu-archive.") sys.exit(1) if options.lp: From 95e5437f44382345660144c0379a94fc1a04a332 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 24 Aug 2011 23:52:45 +0200 Subject: [PATCH 5/8] Note on LP bug to improve getDifferencesTo() --- syncpackage | 1 + 1 file changed, 1 insertion(+) diff --git a/syncpackage b/syncpackage index c00d1a9..491c210 100755 --- a/syncpackage +++ b/syncpackage @@ -388,6 +388,7 @@ def is_blacklisted(query): False if not """ # LP: + # TODO: Refactor when LP: #833080 is fixed series = Launchpad.distributions['ubuntu'].current_series diffs = series.getDifferencesTo(source_package_name_filter=query, status='Needs attention') From 91c70189fd07f878496242c4ea575019cfe99f98 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 25 Aug 2011 14:29:36 +0200 Subject: [PATCH 6/8] getDifferenceComments is a method on series --- syncpackage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncpackage b/syncpackage index 491c210..3c7e8ba 100755 --- a/syncpackage +++ b/syncpackage @@ -393,7 +393,7 @@ def is_blacklisted(query): diffs = series.getDifferencesTo(source_package_name_filter=query, status='Needs attention') if len(diffs) == 0: - comments = getDifferenceComments(source_package_name=query) + comments = series.getDifferenceComments(source_package_name=query) comment = '; '.join(c.body_text for c in comments) if comment: return comment From 497177760b1de7d3a357176734e3b1b557523590 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 25 Aug 2011 14:30:30 +0200 Subject: [PATCH 7/8] Allow --force ing a blacklist override, when doing a non-native sync --- syncpackage | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/syncpackage b/syncpackage index 3c7e8ba..1624c5d 100755 --- a/syncpackage +++ b/syncpackage @@ -469,7 +469,8 @@ def main(): "upload.") parser.add_option("-f", "--force", dest="force", action="store_true", default=False, - help="Force sync over the top of Ubuntu changes.") + help="Force sync over the top of Ubuntu changes " + "or a fake-sync when blacklisted.") parser.add_option('-D', '--debian-mirror', metavar='DEBIAN_MIRROR', dest='debian_mirror', help='Preferred Debian mirror ' @@ -552,7 +553,12 @@ def main(): Logger.error("If you think this package shouldn't be blacklisted, " "please file a bug explaining your reasoning and " "subscribe ~ubuntu-archive.") - sys.exit(1) + if options.force and not options.lp: + Logger.warning(u"Forcing fake-sync, overriding blacklist") + else: + Logger.error("--force and --no-lp are required to override the " + "blacklist, if this package needs a fakesync") + sys.exit(1) if options.lp: copy(src_pkg, options.release, options.simulate, options.force) From dbda709ce35ea7139a00e20a7f2400c350c15fe5 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 25 Aug 2011 14:32:07 +0200 Subject: [PATCH 8/8] Update manpage --- doc/syncpackage.1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/syncpackage.1 b/doc/syncpackage.1 index 009f654..fe0de27 100644 --- a/doc/syncpackage.1 +++ b/doc/syncpackage.1 @@ -72,6 +72,9 @@ Mark a Launchpad bug as being fixed by this upload. .TP \fB\-f\fR, \fB\-\-force\fR Force sync over the top of Ubuntu changes. +If a sync is blacklisted because of an .orig.tar mismatch, +\fB\-\-force\fR can be used to override the blacklist, when doing a +local sync (\fB\-\-no\-lp\fR). .TP .B \-d \fIDEBIAN_MIRROR\fR, \fB\-\-debian\-mirror\fR=\fIDEBIAN_MIRROR\fR Use the specified mirror.