From 083d44f676856384fded7369c3373be41b28c075 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 5 May 2012 19:34:02 +0200 Subject: [PATCH 01/15] submittodebian: Use optparse to display --help (LP: #988009) --- debian/changelog | 1 + submittodebian | 5 +++++ ubuntutools/test/test_help.py | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 6d209e0..2068a91 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,7 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * mk-sbuild: Support kmod, when checking for overlayfs availability. * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) + * submittodebian: Use optparse to display --help (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/submittodebian b/submittodebian index 48122a7..6085bf4 100755 --- a/submittodebian +++ b/submittodebian @@ -22,6 +22,7 @@ # # ################################################################## +import optparse import os import re import shutil @@ -190,6 +191,10 @@ reportbug --configure for its configuration wizard. sys.exit(1) def main(): + parser = optparse.OptionParser( + description='Submit the Ubuntu changes in a package to Debian. ' + 'Run inside an unpacked Ubuntu source package.') + parser.parse_args() check_reportbug_config() changelog_file = (check_file('debian/changelog', critical = False) or check_file('../debian/changelog')) diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index e07eeb9..00cab1e 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -30,7 +30,6 @@ BLACKLIST = { 'grep-merges': 'No Help', 'pbuilder-dist-simple': 'No Help', 'setup-packaging-environment': 'Throws Error', - 'submittodebian': 'No Help', 'ubuntu-iso': 'No Help', } TIMEOUT = 5 From b26dbaee681e400a52706c001b486900e8fdc4c4 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 5 May 2012 19:37:41 +0200 Subject: [PATCH 02/15] check-mir: Use optparse to display --help --- check-mir | 10 +++++++++- debian/changelog | 2 +- ubuntutools/test/test_help.py | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/check-mir b/check-mir index a63bd99..2d707db 100755 --- a/check-mir +++ b/check-mir @@ -21,10 +21,13 @@ # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import apt import sys +import optparse import os.path +import apt + + def check_support(apt_cache, pkgname, alt=False): '''Check if pkgname is in main or restricted. @@ -118,6 +121,11 @@ def check_binary_dependencies(apt_cache, control): return any_unsupported def main(): + parser = optparse.OptionParser( + description="Check if any of a package's build or binary " + "dependencies are in universe or multiverse. " + "Run this inside an unpacked source package") + parser.parse_args() apt_cache = apt.Cache() if not os.path.exists('debian/control'): diff --git a/debian/changelog b/debian/changelog index 2068a91..84e3eab 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,7 +3,7 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * mk-sbuild: Support kmod, when checking for overlayfs availability. * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) - * submittodebian: Use optparse to display --help (LP: #988009) + * submittodebian, check-mir: Use optparse to display --help (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index 00cab1e..3d0c32a 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -25,7 +25,6 @@ from ubuntutools import subprocess from ubuntutools.test import unittest BLACKLIST = { - 'check-mir': 'No Help', 'check-symbols': 'No Help', 'grep-merges': 'No Help', 'pbuilder-dist-simple': 'No Help', From d69622fa9c6e8a546d8eb9ab68c4bac9073cb7b5 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 05:12:40 +0200 Subject: [PATCH 03/15] check-symbols: Use optparse to display --help --- check-symbols | 56 ++++++++++++++++++++++++++++------- debian/changelog | 3 +- ubuntutools/test/test_help.py | 1 - 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/check-symbols b/check-symbols index c0a0a03..bcb8b7f 100755 --- a/check-symbols +++ b/check-symbols @@ -29,21 +29,55 @@ # * nm (from binutils) DISTRO=$(lsb_release -c -s) -VERSION=$(apt-cache madison "$1" | grep -- "$DISTRO"'/.*Sources$' | awk '{print $3}') -PACKAGES=$(apt-cache showsrc "$1" | grep-dctrl -s Binary -F Version "$VERSION" | sed 's/Binary\:\ //g;s/\,//g' | sort -u) DEBLINE="" DEBUG=False -if [[ -z $1 ]]; then - echo "Missing argument: source package name." - exit 1 +usage() { + prog=$(basename $0) + cat <&2 + usage 1 + fi + POSITION=$(($POSITION+1)) + esac + shift +done + +if [ $POSITION -eq 0 ]; then + echo "Missing argument: source package name." >&2 + usage 1 fi -if [[ -z $2 ]]; then - DEBDIR="/var/cache/pbuilder/result" -else - DEBDIR="$2" -fi +VERSION=$(apt-cache madison "$PACKAGE" | grep -- "$DISTRO"'/.*Sources$' | awk '{print $3}') +PACKAGES=$(apt-cache showsrc "$PACKAGE" | grep-dctrl -s Binary -F Version "$VERSION" | sed 's/Binary\:\ //g;s/\,//g' | sort -u) if [ `id -u` != "0" ] then @@ -67,7 +101,7 @@ do done if [[ -z $DEBLINE ]]; then - echo "Package doesn't exist: $1." + echo "Package doesn't exist: $PACKAGE." exit 1 fi diff --git a/debian/changelog b/debian/changelog index 84e3eab..06349d0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,7 +3,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * mk-sbuild: Support kmod, when checking for overlayfs availability. * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) - * submittodebian, check-mir: Use optparse to display --help (LP: #988009) + * submittodebian, check-mir, check-symbols: Do enough argument parsing to + handle --help (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index 3d0c32a..e3af9ba 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -25,7 +25,6 @@ from ubuntutools import subprocess from ubuntutools.test import unittest BLACKLIST = { - 'check-symbols': 'No Help', 'grep-merges': 'No Help', 'pbuilder-dist-simple': 'No Help', 'setup-packaging-environment': 'Throws Error', From 927947841c8dccb6543113ff20409263378f17ad Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 05:18:05 +0200 Subject: [PATCH 04/15] ubuntu-iso: Use optparse to display --help --- debian/changelog | 4 ++-- ubuntu-iso | 6 +++++- ubuntutools/test/test_help.py | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 06349d0..69ed718 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * mk-sbuild: Support kmod, when checking for overlayfs availability. * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) - * submittodebian, check-mir, check-symbols: Do enough argument parsing to - handle --help (LP: #988009) + * submittodebian, check-mir, check-symbols, ubuntu-iso: Do enough argument + parsing to handle --help (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/ubuntu-iso b/ubuntu-iso index 5c1309d..04a2e30 100755 --- a/ubuntu-iso +++ b/ubuntu-iso @@ -20,6 +20,7 @@ # # ################################################################## +import optparse import sys from ubuntutools import subprocess @@ -37,7 +38,10 @@ def extract(iso, path): return stdout def main(): - isos = sys.argv[1:] + parser = optparse.OptionParser(usage='%prog [options] iso...', + description='Given an ISO, %prog will display the Ubuntu version ' + 'information') + isos = parser.parse_args()[1] err = False for iso in isos: diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index e3af9ba..3e8f2ee 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -28,7 +28,6 @@ BLACKLIST = { 'grep-merges': 'No Help', 'pbuilder-dist-simple': 'No Help', 'setup-packaging-environment': 'Throws Error', - 'ubuntu-iso': 'No Help', } TIMEOUT = 5 From ed96c35dc1f817835d45a209ec489ea0149229a5 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 05:24:14 +0200 Subject: [PATCH 05/15] grep-merges: Use optparse to display --help --- debian/changelog | 4 ++-- grep-merges | 14 +++++++++++--- ubuntutools/test/test_help.py | 1 - 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index 69ed718..541e904 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * mk-sbuild: Support kmod, when checking for overlayfs availability. * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) - * submittodebian, check-mir, check-symbols, ubuntu-iso: Do enough argument - parsing to handle --help (LP: #988009) + * check-mir, check-symbols, grep-merges, submittodebian, ubuntu-iso: Do + enough argument parsing to handle --help (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/grep-merges b/grep-merges index 20023a0..d9cfb3a 100755 --- a/grep-merges +++ b/grep-merges @@ -19,6 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import optparse import sys import json @@ -28,12 +29,19 @@ import ubuntutools.misc def main(): - ubuntutools.misc.require_utf8() - if len(sys.argv) > 1: - match = sys.argv[1] + parser = optparse.OptionParser(usage='%prog [options] [string]', + description='List pending merges from Debian matching string') + args = parser.parse_args()[1] + + if len(args) > 1: + parser.error('Too many arguments') + elif len(args) == 1: + match = args[0] else: match = None + ubuntutools.misc.require_utf8() + for component in ('main', 'main-manual', 'restricted', 'restricted-manual', 'universe', 'universe-manual', diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index 3e8f2ee..3c0930d 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -25,7 +25,6 @@ from ubuntutools import subprocess from ubuntutools.test import unittest BLACKLIST = { - 'grep-merges': 'No Help', 'pbuilder-dist-simple': 'No Help', 'setup-packaging-environment': 'Throws Error', } From 2a2e420353e0392203525ed0d1d18f6ff4b0678f Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 06:03:14 +0200 Subject: [PATCH 06/15] pbuilder-dist-simple: Display help --- debian/changelog | 5 +-- pbuilder-dist-simple | 61 ++++++++++++++++++++++------------- ubuntutools/test/test_help.py | 1 - 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index 541e904..8120757 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,9 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * mk-sbuild: Support kmod, when checking for overlayfs availability. * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) - * check-mir, check-symbols, grep-merges, submittodebian, ubuntu-iso: Do - enough argument parsing to handle --help (LP: #988009) + * check-mir, check-symbols, grep-merges, pbuilder-dist-simple, + submittodebian, ubuntu-iso: Do enough argument parsing to handle --help + (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/pbuilder-dist-simple b/pbuilder-dist-simple index 6aad2eb..6160494 100755 --- a/pbuilder-dist-simple +++ b/pbuilder-dist-simple @@ -30,29 +30,44 @@ OPERATION=$1 DISTRIBUTION=`basename $0 | cut -f2 -d '-'` PROCEED=false BASE_DIR="$HOME/pbuilder" + +usage() { + prog=$(basename $0) + cat < Date: Sun, 6 May 2012 06:06:41 +0200 Subject: [PATCH 07/15] setup-packaging-environment: Display help --- debian/changelog | 4 ++-- setup-packaging-environment | 25 +++++++++++++++++++++++++ ubuntutools/test/test_help.py | 6 ------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8120757..4c8ccd5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,8 +4,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * pbuilder-dist: improve bash_completion for *.dsc files. Thanks Maarten Bezemer. (Closes: #670924, LP: #770529) * check-mir, check-symbols, grep-merges, pbuilder-dist-simple, - submittodebian, ubuntu-iso: Do enough argument parsing to handle --help - (LP: #988009) + setup-packaging-environment, submittodebian, ubuntu-iso: + Do enough argument parsing to handle --help (LP: #988009) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/setup-packaging-environment b/setup-packaging-environment index 2144011..dce699c 100755 --- a/setup-packaging-environment +++ b/setup-packaging-environment @@ -37,6 +37,31 @@ await_response() { echo } +usage() { + prog=$(basename $0) + cat < Date: Sun, 6 May 2012 06:27:32 +0200 Subject: [PATCH 08/15] dgetlp: Require a UTF-8 locale, or it'll crash when displaying errors (LP: #979117) --- debian/changelog | 2 ++ dgetlp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/debian/changelog b/debian/changelog index 4c8ccd5..2e0977f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * check-mir, check-symbols, grep-merges, pbuilder-dist-simple, setup-packaging-environment, submittodebian, ubuntu-iso: Do enough argument parsing to handle --help (LP: #988009) + * dgetlp: Require a UTF-8 locale, or it'll crash when displaying errors + (LP: #979117) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/dgetlp b/dgetlp index 91337dc..f114848 100755 --- a/dgetlp +++ b/dgetlp @@ -43,6 +43,7 @@ except ImportError: sys.exit(1) from ubuntutools import subprocess +import ubuntutools.misc USAGE = u"""Usage: %prog [-d|(-v|-q)] @@ -253,6 +254,8 @@ def main(): default=False, help="Never print any output") (options, args) = parser.parse_args() + ubuntutools.misc.require_utf8() + if len(args) != 1: parser.error("Missing URL") Debug = options.debug From 4dbde5f8861ebbf4bda37d635a647c3ac061db3b Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 08:36:37 +0200 Subject: [PATCH 09/15] pbuilder-dist: Don't try to enable -updates for Debian testing (LP: #993006) --- debian/changelog | 2 ++ pbuilder-dist | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2e0977f..912bf8a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low Do enough argument parsing to handle --help (LP: #988009) * dgetlp: Require a UTF-8 locale, or it'll crash when displaying errors (LP: #979117) + * pbuilder-dist: Don't try to enable -updates for Debian testing + (LP: #993006) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/pbuilder-dist b/pbuilder-dist index bb6227d..8757678 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -266,11 +266,14 @@ class PbuilderDist: othermirrors = [] if self.target_distro in self._debian_distros: debian_info = DebianDistroInfo() - if (debian_info.codename(self.target_distro) or self.target_distro - in (debian_info.devel(), 'experimental')): + codename = debian_info.codename(self.target_distro, + default=self.target_distro) + if codename in (debian_info.devel(), 'experimental'): self.enable_security = False self.enable_updates = False self.enable_proposed = False + elif codename == 'testing': + self.enable_updates = False if self.enable_security: othermirrors.append('deb %s %s/updates %s' From 343ac49b39898883ff33051143dc28fb8f8bb126 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 10:15:54 +0200 Subject: [PATCH 10/15] pbuilder-dist, pull-debian-source, pull-lp-source, requestsync, reverse-depends, submittodebian, syncpackage: Handle outdated distro-info data. Fall back to sane defaults where possible. --- debian/changelog | 4 ++++ pbuilder-dist | 17 +++++++++++++---- pull-debian-source | 7 +++++-- pull-lp-source | 8 ++++++-- requestsync | 9 ++++++--- reverse-depends | 19 +++++++++++++++---- submittodebian | 8 ++++++-- syncpackage | 12 ++++++++++-- ubuntutools/requestsync/lp.py | 7 +++++-- ubuntutools/requestsync/mail.py | 7 +++++-- 10 files changed, 75 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index 912bf8a..d4815ff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,10 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low (LP: #979117) * pbuilder-dist: Don't try to enable -updates for Debian testing (LP: #993006) + * pbuilder-dist, pull-debian-source, pull-lp-source, requestsync, + reverse-depends, submittodebian, syncpackage: + Handle outdated distro-info data. Fall back to sane defaults where + possible. -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/pbuilder-dist b/pbuilder-dist index 8757678..347289c 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -33,7 +33,7 @@ import os import sys from devscripts.logger import Logger -from distro_info import DebianDistroInfo, UbuntuDistroInfo +from distro_info import DebianDistroInfo, UbuntuDistroInfo, DistroDataOutdated import ubuntutools.misc from ubuntutools.config import UDTConfig @@ -266,8 +266,11 @@ class PbuilderDist: othermirrors = [] if self.target_distro in self._debian_distros: debian_info = DebianDistroInfo() - codename = debian_info.codename(self.target_distro, - default=self.target_distro) + try: + codename = debian_info.codename(self.target_distro, + default=self.target_distro) + except DistroDataOutdated, e: + Logger.warn(e) if codename in (debian_info.devel(), 'experimental'): self.enable_security = False self.enable_updates = False @@ -286,7 +289,13 @@ class PbuilderDist: othermirrors.append('deb %s %s-proposed-updates %s' % (mirror, self.target_distro, components)) else: - if self.target_distro == UbuntuDistroInfo().devel(): + try: + dev_release = self.target_distro == UbuntuDistroInfo().devel() + except DistroDataOutdated, e: + Logger.warn(e) + dev_release = True + + if dev_release: self.enable_security = False self.enable_updates = False self.enable_proposed = False diff --git a/pull-debian-source b/pull-debian-source index 176cee9..36a9caf 100755 --- a/pull-debian-source +++ b/pull-debian-source @@ -22,7 +22,7 @@ import sys import urllib2 from devscripts.logger import Logger -from distro_info import DebianDistroInfo +from distro_info import DebianDistroInfo, DistroDataOutdated from ubuntutools.archive import DebianSourcePackage, DownloadError, rmadison from ubuntutools.config import UDTConfig @@ -52,7 +52,10 @@ def is_suite(version): def source_package_for(binary, release): """Query DDE to find the source package for a particular binary""" - release = DebianDistroInfo().codename(release, default=release) + try: + release = DebianDistroInfo().codename(release, default=release) + except DistroDataOutdated, e: + Logger.warn(e) url = ('http://dde.debian.net/dde/q/udd/dist/d:debian/r:%s/p:%s/?t=json' % (release, binary)) try: diff --git a/pull-lp-source b/pull-lp-source index 38efbef..bd3d48a 100755 --- a/pull-lp-source +++ b/pull-lp-source @@ -30,7 +30,7 @@ import urllib2 from optparse import OptionParser from devscripts.logger import Logger -from distro_info import UbuntuDistroInfo +from distro_info import UbuntuDistroInfo, DistroDataOutdated from ubuntutools.archive import UbuntuSourcePackage, DownloadError from ubuntutools.config import UDTConfig @@ -89,7 +89,11 @@ def main(): if len(args) > 1: # Custom distribution specified. version = str(args[1]) else: - version = os.getenv('DIST') or ubuntu_info.devel() + try: + version = os.getenv('DIST') or ubuntu_info.devel() + except DistroDataOutdated, e: + Logger.warn("%s\nOr specify a distribution.", e) + sys.exit(1) component = None # Release, not package version number: diff --git a/requestsync b/requestsync index c6b01c0..f5956b9 100755 --- a/requestsync +++ b/requestsync @@ -31,7 +31,7 @@ import os import sys from debian.changelog import Version -from distro_info import UbuntuDistroInfo +from distro_info import UbuntuDistroInfo, DistroDataOutdated from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.lp import udtexceptions @@ -45,8 +45,11 @@ from ubuntutools.question import confirmation_prompt, EditBugReport def main(): ubu_info = UbuntuDistroInfo() DEFAULT_SOURCE = 'unstable' - if ubu_info.is_lts(ubu_info.devel()): - DEFAULT_SOURCE = 'testing' + try: + if ubu_info.is_lts(ubu_info.devel()): + DEFAULT_SOURCE = 'testing' + except DistroDataOutdated, e: + print >> sys.stderr, str(e) # Our usage options. usage = ('Usage: %prog [options] ' diff --git a/reverse-depends b/reverse-depends index d54857b..89d7ef0 100755 --- a/reverse-depends +++ b/reverse-depends @@ -18,6 +18,7 @@ import optparse import sys from devscripts.logger import Logger +from distro_info import DistroDataOutdated from ubuntutools.misc import (system_distribution, vendor_to_distroinfo, codename_to_distribution) @@ -26,15 +27,21 @@ from ubuntutools.rdepends import query_rdepends, RDependsException def main(): system_distro_info = vendor_to_distroinfo(system_distribution())() + try: + default_release = system_distro_info.devel() + except DistroDataOutdated, e: + Logger.warn(e) + default_release = 'unstable' + parser = optparse.OptionParser('%prog [options] package', description="List reverse-dependencies of package. " "If the package name is prefixed with src: then the " "reverse-dependencies of all the binary packages that " "the specified source package builds will be listed.") parser.add_option('-r', '--release', metavar='RELEASE', - default=system_distro_info.devel(), + default=default_release, help='Query dependencies in RELEASE. ' - 'Default: %s' % system_distro_info.devel()) + 'Default: %s' % default_release) parser.add_option('-R', '--without-recommends', action='store_false', dest='recommends', default=True, help='Only consider Depends relationships, ' @@ -76,8 +83,12 @@ def main(): if not distribution: parser.error('Unknown release codename %s' % options.release) distro_info = vendor_to_distroinfo(distribution)() - options.release = distro_info.codename(options.release, - default=options.release) + try: + options.release = distro_info.codename(options.release, + default=options.release) + except DistroDataOutdated: + # We already printed a warning + pass try: data = query_rdepends(package, options.release, options.arch, **opts) diff --git a/submittodebian b/submittodebian index 6085bf4..d1fe8d5 100755 --- a/submittodebian +++ b/submittodebian @@ -29,7 +29,7 @@ import shutil import sys from tempfile import mkdtemp -from distro_info import UbuntuDistroInfo +from distro_info import UbuntuDistroInfo, DistroDataOutdated from ubuntutools.config import ubu_email from ubuntutools.question import YesNoQuestion, EditFile @@ -119,7 +119,11 @@ def check_file(fname, critical = True): sys.exit(1) def submit_bugreport(body, debdiff, deb_version, changelog): - devel = UbuntuDistroInfo().devel() + try: + devel = UbuntuDistroInfo().devel() + except DistroDataOutdated, e: + print str(e) + devel = '' if os.path.dirname(sys.argv[0]).startswith('/usr/bin'): editor_path = '/usr/share/ubuntu-dev-tools' diff --git a/syncpackage b/syncpackage index acefbbe..e028cb6 100755 --- a/syncpackage +++ b/syncpackage @@ -31,7 +31,7 @@ import urllib import debian.debian_support from devscripts.logger import Logger -from distro_info import UbuntuDistroInfo +from distro_info import UbuntuDistroInfo, DistroDataOutdated from lazr.restfulclient.errors import HTTPError from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage, @@ -294,7 +294,15 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, if dist is None: ubu_info = UbuntuDistroInfo() - dist = 'testing' if ubu_info.is_lts(ubu_info.devel()) else 'unstable' + try: + if ubu_info.is_lts(ubu_info.devel()): + dist = 'testing' + else: + dist = 'unstable' + except DistroDataOutdated, e: + Logger.warn(e) + dist = 'unstable' + requested_version = version if type(version) == str: version = Version(version) diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py index 7addb9c..70f1df1 100644 --- a/ubuntutools/requestsync/lp.py +++ b/ubuntutools/requestsync/lp.py @@ -24,7 +24,7 @@ import re from debian.deb822 import Changes from devscripts.logger import Logger -from distro_info import DebianDistroInfo +from distro_info import DebianDistroInfo, DistroDataOutdated from httplib2 import Http, HttpLib2Error from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam, @@ -35,7 +35,10 @@ def get_debian_srcpkg(name, release): debian = Distribution('debian') debian_archive = debian.getArchive() - release = DebianDistroInfo().codename(release, None, release) + try: + release = DebianDistroInfo().codename(release, None, release) + except DistroDataOutdated, e: + Logger.warn(e) return debian_archive.getSourcePackage(name, release) diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index 1d94876..9b78884 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -29,7 +29,7 @@ import tempfile from debian.changelog import Changelog, Version from devscripts.logger import Logger -from distro_info import DebianDistroInfo +from distro_info import DebianDistroInfo, DistroDataOutdated from ubuntutools.archive import rmadison, FakeSPPH from ubuntutools.question import confirmation_prompt, YesNoQuestion @@ -49,7 +49,10 @@ def _get_srcpkg(distro, name, release): if distro == 'debian': # Canonicalise release: debian_info = DebianDistroInfo() - release = debian_info.codename(release, default=release) + try: + release = debian_info.codename(release, default=release) + except DistroDataOutdated, e: + Logger.warn(e) lines = list(rmadison(distro, name, suite=release, arch='source')) if not lines: From 314ed77d77f95dd777e2d7f7d38b6943228179bd Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 12:32:54 +0200 Subject: [PATCH 11/15] backportpackage: Avoid uploading orig tarballs if they are already present in the destination PPA (LP: #691897) --- backportpackage | 36 ++++++++++++++++++++++++++++++++++-- debian/changelog | 2 ++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/backportpackage b/backportpackage index de24221..55c98a7 100755 --- a/backportpackage +++ b/backportpackage @@ -18,6 +18,7 @@ # # ################################################################## +import glob import optparse import os import shutil @@ -25,8 +26,8 @@ import sys import tempfile import lsb_release - from devscripts.logger import Logger +from httplib2 import Http, HttpLib2Error from ubuntutools.archive import (SourcePackage, DebianSourcePackage, UbuntuSourcePackage, DownloadError) @@ -232,6 +233,31 @@ def do_upload(workdir, package, bp_version, changes, upload, prompt): check_call(['dput', upload, changes], cwd=workdir) +def orig_needed(upload, workdir, pkg): + '''Avoid a -sa if possible''' + if not upload or not upload.startswith('ppa:'): + return True + ppa = upload.split(':', 1)[1] + user, ppa = ppa.split('/', 1) + + version = pkg.version.full_version + if pkg.version.epoch: + version = version.split(pkg.version.epoch, 1)[1] + + h = Http() + for filename in glob.glob(os.path.join(workdir, + '%s_%s.orig*' % (pkg.source, version))): + url = ('https://launchpad.net/~%s/+archive/%s/+files/%s' + % (user, ppa, filename)) + try: + headers, body = h.request(url, 'HEAD') + if headers.status != 200: + return True + except HttpLib2Error, e: + Logger.info(e) + return True + return False + def do_backport(workdir, pkg, suffix, release, release_pocket, build, builder, update, upload, prompt): dirname = '%s-%s' % (pkg.source, release) @@ -257,7 +283,13 @@ def do_backport(workdir, pkg, suffix, release, release_pocket, build, builder, '--distribution', bp_dist, 'No-change backport to %s' % release], cwd=srcdir) - check_call(['debuild', '--no-lintian', '-S', '-nc', '-sa'], cwd=srcdir) + + cmd = ['debuild', '--no-lintian', '-S', '-nc'] + if orig_needed(upload, workdir, pkg): + cmd.append('-sa') + else: + cmd.append('-sd') + check_call(cmd, cwd=srcdir) fn_base = pkg.source + '_' + bp_version.split(':', 1)[-1] diff --git a/debian/changelog b/debian/changelog index d4815ff..ed360fc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,6 +14,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low reverse-depends, submittodebian, syncpackage: Handle outdated distro-info data. Fall back to sane defaults where possible. + * backportpackage: Avoid uploading orig tarballs if they are already present + in the destination PPA (LP: #691897) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 From b84c4d85304d0bf67d9ca01c1326041e6ce23270 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 12:40:47 +0200 Subject: [PATCH 12/15] Allow mk-sbuild to be run by root if a configuration file exists (LP: #888736) --- debian/changelog | 2 ++ mk-sbuild | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index ed360fc..4d35c65 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low possible. * backportpackage: Avoid uploading orig tarballs if they are already present in the destination PPA (LP: #691897) + * Allow mk-sbuild to be run by root if a configuration file exists + (LP: #888736) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/mk-sbuild b/mk-sbuild index d79f672..e11d959 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -175,9 +175,15 @@ done # will not exist in the chroot. cd / -# Make sure we've got a regular user -if [ -w /etc/passwd ]; then - echo "Please run this script as a regular user, not root." >&2 +if [ -w /etc/passwd -a ! -e ~/.sbuildrc -a ! -e ~/.mk-sbuild.rc ]; then + cat >&2 < Date: Sun, 6 May 2012 13:09:54 +0200 Subject: [PATCH 13/15] backportpackage: Allow unsigned backports (LP: #992739) --- backportpackage | 22 ++++++++++++++++++---- debian/changelog | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backportpackage b/backportpackage index 55c98a7..dd04e66 100755 --- a/backportpackage +++ b/backportpackage @@ -86,6 +86,11 @@ def parse(args): parser.add_option('-u', '--upload', metavar='UPLOAD', help='Specify an upload destination') + parser.add_option("-k", "--key", + help="Specify the key ID to be used for signing.") + parser.add_option('--dont-sign', + dest='key', action='store_false', + help='Do not sign the upload.') parser.add_option('-y', '--yes', dest='prompt', default=True, @@ -130,6 +135,8 @@ def parse(args): opts.lpinstance = config.get_value('LPINSTANCE') if opts.upload is None: opts.upload = config.get_value('UPLOAD') + if opts.keyid is None: + opts.keyid = config.get_value('KEYID') if not opts.upload and not opts.workdir: parser.error('Please specify either a working dir or an upload target!') if opts.upload and opts.upload.startswith('ppa:'): @@ -259,7 +266,7 @@ def orig_needed(upload, workdir, pkg): return False def do_backport(workdir, pkg, suffix, release, release_pocket, build, builder, - update, upload, prompt): + update, upload, keyid, prompt): dirname = '%s-%s' % (pkg.source, release) srcdir = os.path.join(workdir, dirname) @@ -284,7 +291,7 @@ def do_backport(workdir, pkg, suffix, release, release_pocket, build, builder, 'No-change backport to %s' % release], cwd=srcdir) - cmd = ['debuild', '--no-lintian', '-S', '-nc'] + cmd = ['debuild', '--no-lintian', '-S', '-nc', '-uc', '-us'] if orig_needed(upload, workdir, pkg): cmd.append('-sa') else: @@ -292,13 +299,19 @@ def do_backport(workdir, pkg, suffix, release, release_pocket, build, builder, check_call(cmd, cwd=srcdir) fn_base = pkg.source + '_' + bp_version.split(':', 1)[-1] + changes = fn_base + '_source.changes' if build: if 0 != do_build(workdir, fn_base + '.dsc', release, builder, update): sys.exit(1) + if keyid != False: + cmd = ['debsign'] + if keyid: + cmd.append('-k' + keyid) + cmd.append(changes) + check_call(cmd, cwd=workdir) if upload: - do_upload(workdir, pkg.source, bp_version, fn_base + '_source.changes', - upload, prompt) + do_upload(workdir, pkg.source, bp_version, changes, upload, prompt) shutil.rmtree(srcdir) @@ -343,6 +356,7 @@ def main(args): opts.builder, opts.update, opts.upload, + opts.key, opts.prompt) except DownloadError, e: error(str(e)) diff --git a/debian/changelog b/debian/changelog index 4d35c65..b193dfa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low in the destination PPA (LP: #691897) * Allow mk-sbuild to be run by root if a configuration file exists (LP: #888736) + * backportpackage: Allow unsigned backports (LP: #992739) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 From d692d7b79ba40f1e6d445ff143cbd0c1a8a45957 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 19:42:39 +0200 Subject: [PATCH 14/15] update-maintainer: Add a function to restore the original maintainer. --- debian/changelog | 1 + ubuntutools/update_maintainer.py | 97 +++++++++++++++++++++++--------- update-maintainer | 18 +++++- 3 files changed, 88 insertions(+), 28 deletions(-) diff --git a/debian/changelog b/debian/changelog index b193dfa..4cf1892 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,7 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low * Allow mk-sbuild to be run by root if a configuration file exists (LP: #888736) * backportpackage: Allow unsigned backports (LP: #992739) + * update-maintainer: Add a function to restore the original maintainer. -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/ubuntutools/update_maintainer.py b/ubuntutools/update_maintainer.py index 25f7ba8..9e74924 100644 --- a/ubuntutools/update_maintainer.py +++ b/ubuntutools/update_maintainer.py @@ -30,6 +30,11 @@ _PREVIOUS_UBUNTU_MAINTAINER = ( ) _UBUNTU_MAINTAINER = "Ubuntu Developers " + +class MaintainerUpdateException(Exception): + pass + + class Control(object): """Represents a debian/control file""" @@ -79,6 +84,12 @@ class Control(object): self._content = pattern.sub(r"\1\n" + original_maintainer, self._content) + def remove_original_maintainer(self): + """Strip out out the XSBC-Original-Maintainer line""" + pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*?$.*?^", + re.MULTILINE | re.DOTALL) + self._content = pattern.sub('', self._content) + def _get_distribution(changelog_file): """get distribution of latest changelog entry""" @@ -88,6 +99,38 @@ def _get_distribution(changelog_file): # Strip things like "-proposed-updates" or "-security" from distribution return distribution.split("-", 1)[0] + +def _find_files(debian_directory, verbose): + """Find possible control files. + Returns (changelog, control files list) + Raises an exception if none can be found. + """ + possible_contol_files = [os.path.join(debian_directory, f) for + f in ["control.in", "control"]] + + changelog_file = os.path.join(debian_directory, "changelog") + control_files = [f for f in possible_contol_files if os.path.isfile(f)] + + # Make sure that a changelog and control file is available + if len(control_files) == 0: + raise MaintainerUpdateException( + "No control file found in %s." % debian_directory) + if not os.path.isfile(changelog_file): + raise MaintainerUpdateException( + "No changelog file found in %s." % debian_directory) + + # If the rules file accounts for XSBC-Original-Maintainer, we should not + # touch it in this package (e.g. the python package). + rules_file = os.path.join(debian_directory, "rules") + if os.path.isfile(rules_file) and \ + 'XSBC-Original-' in open(rules_file).read(): + if verbose: + print "XSBC-Original is managed by 'rules' file. Doing nothing." + control_files = [] + + return (changelog_file, control_files) + + def update_maintainer(debian_directory, verbose=False): """updates the Maintainer field of an Ubuntu package @@ -99,38 +142,20 @@ def update_maintainer(debian_directory, verbose=False): Policy: https://wiki.ubuntu.com/DebianMaintainerField """ - possible_contol_files = [os.path.join(debian_directory, f) for - f in ["control.in", "control"]] - - changelog_file = os.path.join(debian_directory, "changelog") - control_files = [f for f in possible_contol_files if os.path.isfile(f)] - - # Make sure that a changelog and control file is available - if len(control_files) == 0: - Logger.error("No control file found in %s.", debian_directory) - return(1) - if not os.path.isfile(changelog_file): - Logger.error("No changelog file found in %s.", debian_directory) - return(1) - - # If the rules file accounts for XSBC-Original-Maintainer, we should not - # touch it in this package (e.g. the python package). - rules_file = os.path.join(debian_directory, "rules") - if os.path.isfile(rules_file) and \ - 'XSBC-Original-' in open(rules_file).read(): - if verbose: - print "XSBC-Original is managed by 'rules' file. Doing nothing." - return(0) + try: + changelog_file, control_files = _find_files(debian_directory, verbose) + except MaintainerUpdateException, e: + Logger.error(str(e)) + raise distribution = _get_distribution(changelog_file) - for control_file in control_files: control = Control(control_file) original_maintainer = control.get_maintainer() if original_maintainer is None: Logger.error("No Maintainer field found in %s.", control_file) - return(1) + raise MaintainerUpdateException("No Maintainer field found") if original_maintainer.strip().lower() in _PREVIOUS_UBUNTU_MAINTAINER: if verbose: @@ -149,7 +174,7 @@ def update_maintainer(debian_directory, verbose=False): if distribution in ("stable", "testing", "unstable", "experimental"): if verbose: print "The package targets Debian. Doing nothing." - return(0) + return if control.get_original_maintainer() is not None: Logger.warn("Overwriting original maintainer: %s", @@ -162,4 +187,24 @@ def update_maintainer(debian_directory, verbose=False): control.set_maintainer(_UBUNTU_MAINTAINER) control.save() - return(0) + return + + +def restore_maintainer(debian_directory, verbose=False): + """Restore the original maintainer""" + try: + changelog_file, control_files = _find_files(debian_directory, verbose) + except MaintainerUpdateException, e: + Logger.error(str(e)) + raise + + for control_file in control_files: + control = Control(control_file) + orig_maintainer = control.get_original_maintainer() + if not orig_maintainer: + continue + if verbose: + print "Restoring original maintainer: %s" % orig_maintainer + control.set_maintainer(orig_maintainer) + control.remove_original_maintainer() + control.save() diff --git a/update-maintainer b/update-maintainer index 8914ff2..2ec5d57 100755 --- a/update-maintainer +++ b/update-maintainer @@ -18,7 +18,10 @@ import optparse import os import sys -from ubuntutools.update_maintainer import update_maintainer +from ubuntutools.update_maintainer import (update_maintainer, + restore_maintainer, + MaintainerUpdateException) + def main(): script_name = os.path.basename(sys.argv[0]) @@ -28,6 +31,9 @@ def main(): parser.add_option("-d", "--debian-directory", dest="debian_directory", help="location of the 'debian' directory (default: " "%default).", metavar="PATH", default="./debian") + parser.add_option("-r", "--restore", + help="Restore the original maintainer", + action='store_true', default=False) parser.add_option("-q", "--quiet", help="print no informational messages", dest="quiet", action="store_true", default=False) (options, args) = parser.parse_args() @@ -37,7 +43,15 @@ def main(): "specified: %s") % (script_name, ", ".join(args)) sys.exit(1) - sys.exit(update_maintainer(options.debian_directory, not options.quiet)) + if not options.restore: + operation = update_maintainer + else: + operation = restore_maintainer + + try: + operation(options.debian_directory, not options.quiet) + except MaintainerUpdateException: + sys.exit(1) if __name__ == "__main__": main() From 055dce8f402826bdf37b47d4d15b60bbd29e4475 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 6 May 2012 19:46:05 +0200 Subject: [PATCH 15/15] submittodebian: Revert Ubuntu Maintainer mangling, and re-build the source package before diffing. (LP: #902233) --- debian/changelog | 2 ++ submittodebian | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/debian/changelog b/debian/changelog index 4cf1892..0940448 100644 --- a/debian/changelog +++ b/debian/changelog @@ -20,6 +20,8 @@ ubuntu-dev-tools (0.142) UNRELEASED; urgency=low (LP: #888736) * backportpackage: Allow unsigned backports (LP: #992739) * update-maintainer: Add a function to restore the original maintainer. + * submittodebian: Revert Ubuntu Maintainer mangling, and re-build the source + package before diffing. (LP: #902233) -- Stefano Rivera Wed, 25 Apr 2012 17:38:58 +0200 diff --git a/submittodebian b/submittodebian index d1fe8d5..7b21499 100755 --- a/submittodebian +++ b/submittodebian @@ -34,6 +34,7 @@ from distro_info import UbuntuDistroInfo, DistroDataOutdated from ubuntutools.config import ubu_email from ubuntutools.question import YesNoQuestion, EditFile from ubuntutools.subprocess import call, check_call, Popen, PIPE +from ubuntutools.update_maintainer import update_maintainer, restore_maintainer try: from debian.changelog import Changelog @@ -70,6 +71,13 @@ Thanks for considering the patch. """ % ("\n".join([a for a in entry.changes()])) return msg +def build_source_package(): + if os.path.isdir('.bzr'): + cmd = ['bzr', 'bd', '-S', '--', '-uc', '-us', '-nc'] + else: + cmd = ['debuild', '-S', '-uc', '-us', '-nc'] + check_call(cmd) + def gen_debdiff(tmpdir, changelog): pkg = changelog.package @@ -213,8 +221,16 @@ def main(): fp.write(bug_body) fp.close() + restore_maintainer('debian') + build_source_package() + update_maintainer('debian') + debdiff = gen_debdiff(tmpdir, changelog) + # Build again as the user probably doesn't expect the Maintainer to be + # reverted in the most recent build + build_source_package() + EditFile(debdiff, 'debdiff').edit(optional=True) submit_bugreport(body, debdiff, deb_version, changelog)