Merge branch 'python3' of git+ssh://git.launchpad.net/ubuntu-dev-tools

MR: https://code.launchpad.net/~ubuntu-dev/ubuntu-dev-tools/+git/ubuntu-dev-tools/+merge/372305
Signed-off-by: Mattia Rizzolo <mattia@debian.org>
This commit is contained in:
Mattia Rizzolo 2019-09-10 14:19:07 +02:00
commit 434ca8952e
No known key found for this signature in database
GPG Key ID: 0816B9E18C762BAD
54 changed files with 412 additions and 1068 deletions

182
404main
View File

@ -1,182 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2006-2007 (C) Pete Savage <petesavage@ubuntu.com>
# Copyright 2007 (C) Siegfried-A. Gevatter <rainct@ubuntu.com>
# Copyright 2009 (C) Canonical Ltd. (by Colin Watson <cjwatson@ubuntu.com>)
#
# ##################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# See file /usr/share/common-licenses/GPL for more details.
#
# ##################################################################
#
# This script is used to check if a package and all its build
# dependencies are in main or not.
import sys
import apt_pkg
import apt
from ubuntutools import subprocess
def process_deps(cache, deps):
"""Takes a list of (build) dependencies and processes it."""
for basedep in [d.or_dependencies[0] for d in deps]:
if basedep.name not in packages and basedep.name != '':
# Check the (build) dependencies recursively
find_main(cache, basedep.name)
def get_package_version(cache, distro, pack):
if pack not in cache:
return None
for version in (cache[pack].candidate, cache[pack].installed):
if not version:
continue
for origin in version.origins:
if origin.archive == distro:
return version
return None
# Cache::CompTypeDeb isn't exposed via python-apt
def comp_type_deb(op):
ops = ("", "<=", ">=", "<<", ">>", "=", "!=")
if (op & 15) < 7:
return ops[op & 15]
return ""
def find_main(cache, pack):
"""Searches the dependencies and build dependencies of a package recursively
to determine if they are all in the 'main' component or not."""
global packages
if pack in packages:
return
# Retrieve information about the package
version = get_package_version(cache, distro, pack)
if not version:
packages[pack] = False
return
elif [origin for origin in version.origins if origin.component == 'main']:
packages[pack] = True
return
else:
if pack not in packages:
packages[pack] = False
# Retrieve package dependencies
process_deps(cache, version.dependencies)
# Retrieve package build dependencies. There's no handy
# attribute on version for this, so unfortunately we have to
# do a lot of messing about with apt.
deps = []
src_records = apt_pkg.SourceRecords()
got_src = False
while src_records.lookup(version.source_name):
if pack in src_records.binaries:
got_src = True
break
if got_src:
# pylint: disable=E1101
for _, all_deps in src_records.build_depends.iteritems():
# pylint: enable=E1101
for or_deps in all_deps:
base_deps = []
for (name, ver, op) in or_deps:
# pylint: disable=too-many-function-args
base_deps.append(apt.package.BaseDependency(name, op,
ver, False))
# pylint: enable=too-many-function-args
# pylint: disable=no-value-for-parameter
deps.append(apt.package.Dependency(base_deps))
# pylint: enable=no-value-for-parameter
process_deps(cache, deps)
def usage(exit_code):
print 'Usage: %s <package name> [<distribution>]' % sys.argv[0]
sys.exit(exit_code)
def main():
global packages, distro
# Check if the amount of arguments is correct
if len(sys.argv) > 1 and sys.argv[1] in ('help', '-h', '--help'):
usage(0)
if len(sys.argv) < 2 or len(sys.argv) > 3:
usage(1)
cache = apt.cache.Cache()
if len(sys.argv) == 3 and sys.argv[2]:
distro = sys.argv[2]
if not get_package_version(cache, distro, 'bash'):
print u'«%s» is not a valid distribution.' % distro
print('Remember that for 404main to work with a certain distribution '
'it must be in your /etc/apt/sources.list file.')
sys.exit(1)
else:
cmd = ['lsb_release', '-cs']
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
distro = process.stdout.read().strip('\n')
if not get_package_version(cache, distro, sys.argv[1]):
print(u"Can't find package «%s» in distribution «%s»." % (sys.argv[1], distro))
sys.exit(1)
print(u'Checking package «%s» in distribution «%s»...' % (sys.argv[1], distro))
find_main(cache, sys.argv[1])
# True if everything checked until the point is in main
all_in_main = True
for package in packages:
if not packages[package]:
if all_in_main:
print 'The following packages aren\'t in main:'
all_in_main = False
print ' ', package
if all_in_main:
print((u'Package «%s» and all its dependencies and build dependencies are in main.') %
sys.argv[1])
if __name__ == '__main__':
# Global variable to hold the status of all packages
packages = {}
# Global variable to hold the target distribution
distro = ''
try:
main()
except KeyboardInterrupt:
print 'Aborted.'
sys.exit(1)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# ################################################################## # ##################################################################
# #
@ -22,6 +22,7 @@ import glob
import optparse import optparse
import os import os
import shutil import shutil
import subprocess
import sys import sys
import tempfile import tempfile
@ -39,7 +40,6 @@ from ubuntutools.logger import Logger
from ubuntutools.misc import (system_distribution, vendor_to_distroinfo, from ubuntutools.misc import (system_distribution, vendor_to_distroinfo,
codename_to_distribution) codename_to_distribution)
from ubuntutools.question import YesNoQuestion from ubuntutools.question import YesNoQuestion
from ubuntutools import subprocess
def error(msg): def error(msg):

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
"""Add 'bitesize' tag to bugs and add a comment.""" """Add 'bitesize' tag to bugs and add a comment."""
# Copyright (c) 2011 Canonical Ltd. # Copyright (c) 2011 Canonical Ltd.
@ -39,7 +39,7 @@ def error_out(msg):
def save_entry(entry): def save_entry(entry):
try: try:
entry.lp_save() entry.lp_save()
except HTTPError, error: except HTTPError as error:
error_out(error.content) error_out(error.content)
@ -73,7 +73,7 @@ def main():
# check that the new main bug isn't a duplicate # check that the new main bug isn't a duplicate
try: try:
bug = launchpad.bugs[args[0]] bug = launchpad.bugs[args[0]]
except HTTPError, error: except HTTPError as error:
if error.response.status == 401: if error.response.status == 401:
error_out("Don't have enough permissions to access bug %s. %s" % error_out("Don't have enough permissions to access bug %s. %s" %
(args[0], error.content)) (args[0], error.content))

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Check components of build dependencies and warn about universe/multiverse # Check components of build dependencies and warn about universe/multiverse
# ones, for a package destined for main/restricted # ones, for a package destined for main/restricted
@ -21,8 +21,6 @@
# this program; if not, write to the Free Software Foundation, Inc., # this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import print_function
import sys import sys
import optparse import optparse
import os.path import os.path
@ -103,7 +101,7 @@ def check_binary_dependencies(apt_cache, control):
print('\nChecking support status of binary dependencies...') print('\nChecking support status of binary dependencies...')
while True: while True:
try: try:
control.next() next(control)
except StopIteration: except StopIteration:
break break
@ -141,7 +139,7 @@ def main():
# get build dependencies from debian/control # get build dependencies from debian/control
control = apt.apt_pkg.TagFile(open('debian/control')) control = apt.apt_pkg.TagFile(open('debian/control'))
control.next() next(control)
unsupported_build_deps = check_build_dependencies(apt_cache, control) unsupported_build_deps = check_build_dependencies(apt_cache, control)
unsupported_binary_deps = check_binary_dependencies(apt_cache, control) unsupported_binary_deps = check_binary_dependencies(apt_cache, control)

10
debian/changelog vendored
View File

@ -4,12 +4,20 @@ ubuntu-dev-tools (0.173) UNRELEASED; urgency=medium
* pull-debian-debdiff: * pull-debian-debdiff:
+ Don't unpack the older source package, it will often use the same + Don't unpack the older source package, it will often use the same
directory as the newer one, and break. directory as the newer one, and break.
* merge-changelog:
+ Use ubuntutools.version.Version, to support Python 3.
* Drop 404main, it's been totally broken for years.
* Port all the Python scripts to Python 3, and remove Python 2 support.
Closes: #938740, LP: #1099537
[ Dan Streetman ] [ Dan Streetman ]
* pull-pkg: * pull-pkg:
+ Use ubuntutools.version.Version which has strip_epoch() instead + Use ubuntutools.version.Version which has strip_epoch() instead
of debian.debian_support.Version. of debian.debian_support.Version.
* Have ubuntu-dev-tools depend on the matching version of python-ubuntutools. * Have ubuntu-dev-tools depend on the matching version of python3-ubuntutools.
[ Scott Kitterman ]
* Update requestsync to python3. Closes: #927147
-- Mattia Rizzolo <mattia@debian.org> Tue, 10 Sep 2019 10:55:34 +0200 -- Mattia Rizzolo <mattia@debian.org> Tue, 10 Sep 2019 10:55:34 +0200

54
debian/control vendored
View File

@ -15,20 +15,10 @@ Build-Depends:
libwww-perl, libwww-perl,
lsb-release, lsb-release,
pylint (>= 2), pylint (>= 2),
python-all (>= 2.6.5-13~),
python-apt (>= 0.7.93~),
python-debian (>= 0.1.20~),
python-distro-info (>= 0.4~),
python-flake8,
python-httplib2,
python-launchpadlib (>= 1.5.7),
python-mock,
python-setuptools,
python-soappy,
python-unittest2,
python3-all, python3-all,
python3-apt, python3-apt,
python3-debian, python3-debian,
python3-debianbts,
python3-distro-info, python3-distro-info,
python3-flake8, python3-flake8,
python3-httplib2, python3-httplib2,
@ -54,17 +44,15 @@ Depends:
distro-info (>= 0.2~), distro-info (>= 0.2~),
dpkg-dev, dpkg-dev,
lsb-release, lsb-release,
python,
python-apt (>= 0.7.93~),
python-debian (>= 0.1.20~),
python-distro-info (>= 0.4~),
python-httplib2,
python-launchpadlib (>= 1.5.7),
python-lazr.restfulclient,
python-ubuntutools (= ${binary:Version}),
python3, python3,
python3-apt,
python3-debian,
python3-distro-info, python3-distro-info,
python3-ubuntutools (= ${binary:Version}), python3-ubuntutools (= ${binary:Version}),
python3-httplib2,
python3-launchpadlib,
python3-lazr.restfulclient,
python3-ubuntutools,
sensible-utils, sensible-utils,
sudo, sudo,
${misc:Depends}, ${misc:Depends},
@ -82,13 +70,12 @@ Recommends:
lintian, lintian,
patch, patch,
pbuilder | cowbuilder | sbuild, pbuilder | cowbuilder | sbuild,
python-dns, python3-debianbts,
python-soappy, python3-dns,
quilt, quilt,
reportbug (>= 3.39ubuntu1), reportbug (>= 3.39ubuntu1),
ubuntu-keyring | ubuntu-archive-keyring, ubuntu-keyring | ubuntu-archive-keyring,
Suggests: Suggests:
python-simplejson | python (>= 2.7),
qemu-user-static, qemu-user-static,
Description: useful tools for Ubuntu developers Description: useful tools for Ubuntu developers
This is a collection of useful tools that Ubuntu developers use to make their This is a collection of useful tools that Ubuntu developers use to make their
@ -96,8 +83,6 @@ Description: useful tools for Ubuntu developers
. .
Such tools include: Such tools include:
. .
- 404main - used to check what components a package's deps are in, for
doing a main inclusion report for example.
- backportpackage - helper to test package backports - backportpackage - helper to test package backports
- bitesize - add the 'bitesize' tag to a bug and comment that you are - bitesize - add the 'bitesize' tag to a bug and comment that you are
willing to help fix it. willing to help fix it.
@ -139,27 +124,6 @@ Description: useful tools for Ubuntu developers
package. package.
- update-maintainer - script to update maintainer field in ubuntu packages. - update-maintainer - script to update maintainer field in ubuntu packages.
Package: python-ubuntutools
Architecture: all
Section: python
Depends:
python-debian,
python-distro-info,
python-httplib2,
python-launchpadlib,
sensible-utils,
${misc:Depends},
${python:Depends},
Breaks:
ubuntu-dev-tools (<< 0.154),
Replaces:
ubuntu-dev-tools (<< 0.154),
Description: useful APIs for Ubuntu developer tools — Python 2 library
This package ships a collection of APIs, helpers and wrappers used to
develop useful utilities for Ubuntu developers.
.
This package installs the library for Python 2.
Package: python3-ubuntutools Package: python3-ubuntutools
Architecture: all Architecture: all
Section: python Section: python

4
debian/copyright vendored
View File

@ -39,9 +39,7 @@ License: GPL-2
On Debian systems, the complete text of the GNU General Public License On Debian systems, the complete text of the GNU General Public License
version 2 can be found in the /usr/share/common-licenses/GPL-2 file. version 2 can be found in the /usr/share/common-licenses/GPL-2 file.
Files: 404main Files: doc/import-bug-from-debian.1
doc/404main.1
doc/import-bug-from-debian.1
doc/pbuilder-dist-simple.1 doc/pbuilder-dist-simple.1
doc/pbuilder-dist.1 doc/pbuilder-dist.1
doc/submittodebian.1 doc/submittodebian.1

View File

@ -1 +0,0 @@
/usr/lib/python2.7

2
debian/rules vendored
View File

@ -1,4 +1,4 @@
#!/usr/bin/make -f #!/usr/bin/make -f
%: %:
dh $@ --with python2,python3 --buildsystem=pybuild dh $@ --with python3 --buildsystem=pybuild

View File

@ -1,29 +0,0 @@
.TH 404main 1 "February 17, 2008" "ubuntu-dev-tools"
.SH NAME
404main \- check if all build dependencies of a package are in main
.SH SYNOPSIS
\fB404main\fP <\fIpackage name\fP> [<\fIdistribution\fP>]
.SH DESCRIPTION
\fB404main\fP is a script that can be used to check if a package and
all its build dependencies are in Ubuntu's main component or not.
.SH CAVEATS
\fB404main\fP will take the dependencies and build dependencies of the
packages from the distribution you have first in your
/etc/apt/sources.list file.
.PP
Also, because of this the <\fIdistribution\fP> option is NOT trustworthy; if
the dependencies changed YOU WILL GET INCORRECT RESULTS.
.SH SEE ALSO
.BR apt-cache (8)
.SH AUTHORS
\fB404main\fP was written by Pete Savage <petesavage@ubuntu.com> and
this manpage by Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>.
.PP
Both are released under the GNU General Public License, version 2 or
later.

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
# #

View File

@ -1,4 +1,4 @@
#! /usr/bin/python #! /usr/bin/python3
# #
# grep-merges - search for pending merges from Debian # grep-merges - search for pending merges from Debian
# #
@ -51,12 +51,12 @@ def main():
url = 'https://merges.ubuntu.com/%s.json' % component url = 'https://merges.ubuntu.com/%s.json' % component
try: try:
headers, page = Http().request(url) headers, page = Http().request(url)
except HttpLib2Error, e: except HttpLib2Error as e:
print >> sys.stderr, str(e) print(str(e), file=sys.stderr)
sys.exit(1) sys.exit(1)
if headers.status != 200: if headers.status != 200:
print >> sys.stderr, "%s: %s %s" % (url, headers.status, print("%s: %s %s" % (url, headers.status, headers.reason),
headers.reason) file=sys.stderr)
sys.exit(1) sys.exit(1)
for merge in json.loads(page): for merge in json.loads(page):
@ -66,16 +66,12 @@ def main():
author = merge['user'] author = merge['user']
if merge.get('uploader'): if merge.get('uploader'):
uploader = '(%s)' % merge['uploader'] uploader = '(%s)' % merge['uploader']
try: teams = merge.get('teams', [])
teams = merge['teams']
except e:
teams = []
pretty_uploader = u'{} {}'.format(author, uploader) pretty_uploader = '{} {}'.format(author, uploader)
if (match is None or match in package or match in author if (match is None or match in package or match in author
or match in uploader or match in teams): or match in uploader or match in teams):
print '%s\t%s' % (package.encode("utf-8"), print('%s\t%s' % (package, pretty_uploader))
pretty_uploader.encode("utf-8"))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2007 Canonical Ltd., Daniel Holbach # Copyright (C) 2007 Canonical Ltd., Daniel Holbach
@ -57,8 +57,8 @@ def check_args():
# Check that we have an URL. # Check that we have an URL.
if not args: if not args:
print >> sys.stderr, "An URL pointing to a Launchpad bug list is " \ print("An URL pointing to a Launchpad bug list is required.",
"required." file=sys.stderr)
opt_parser.print_help() opt_parser.print_help()
sys.exit(1) sys.exit(1)
else: else:
@ -87,24 +87,25 @@ def main():
if len(url.split("?", 1)) == 2: if len(url.split("?", 1)) == 2:
# search options not supported, because there is no mapping web ui # search options not supported, because there is no mapping web ui
# options <-> API options # options <-> API options
print >> sys.stderr, "Options in url are not supported, url: %s" % url print("Options in url are not supported, url: %s" % url,
file=sys.stderr)
sys.exit(1) sys.exit(1)
launchpad = None launchpad = None
try: try:
launchpad = Launchpad.login_with("ubuntu-dev-tools", 'production') launchpad = Launchpad.login_with("ubuntu-dev-tools", 'production')
except IOError, error: except IOError as error:
print error print(error)
sys.exit(1) sys.exit(1)
api_url = translate_web_api(url, launchpad) api_url = translate_web_api(url, launchpad)
try: try:
product = launchpad.load(api_url) product = launchpad.load(api_url)
except Exception, error: except Exception as error:
response = getattr(error, "response", {}) response = getattr(error, "response", {})
if response.get("status", None) == "404": if response.get("status", None) == "404":
print >> sys.stderr, ("The URL at '%s' does not appear to be a " print(("The URL at '%s' does not appear to be a valid url to a "
"valid url to a product") % url "product") % url, file=sys.stderr)
sys.exit(1) sys.exit(1)
else: else:
raise raise
@ -112,28 +113,28 @@ def main():
bug_list = [b for b in product.searchTasks() if filter_unsolved(b)] bug_list = [b for b in product.searchTasks() if filter_unsolved(b)]
if not bug_list: if not bug_list:
print "Bug list of %s is empty." % url print("Bug list of %s is empty." % url)
sys.exit(0) sys.exit(0)
if howmany == -1: if howmany == -1:
howmany = len(bug_list) howmany = len(bug_list)
print """ print("""
## ||<rowbgcolor="#CCFFCC"> This task is done || somebody || || ## ||<rowbgcolor="#CCFFCC"> This task is done || somebody || ||
## ||<rowbgcolor="#FFFFCC"> This task is assigned || somebody || <status> || ## ||<rowbgcolor="#FFFFCC"> This task is assigned || somebody || <status> ||
## ||<rowbgcolor="#FFEBBB"> This task isn't || ... || || ## ||<rowbgcolor="#FFEBBB"> This task isn't || ... || ||
## ||<rowbgcolor="#FFCCCC"> This task is blocked on something || somebody || <explanation> || ## ||<rowbgcolor="#FFCCCC"> This task is blocked on something || somebody || <explanation> ||
|| Bug || Subject || Triager ||""" || Bug || Subject || Triager ||""")
for i in list(bug_list)[:howmany]: for i in list(bug_list)[:howmany]:
bug = i.bug bug = i.bug
print '||<rowbgcolor="#FFEBBB"> [%s %s] || %s || ||' % \ print('||<rowbgcolor="#FFEBBB"> [%s %s] || %s || ||'
(bug.web_link, bug.id, bug.title) % (bug.web_link, bug.id, bug.title))
if __name__ == '__main__': if __name__ == '__main__':
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
print >> sys.stderr, "Aborted." print("Aborted.", file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# Copyright © 2009 James Westby <james.westby@ubuntu.com>, # Copyright © 2009 James Westby <james.westby@ubuntu.com>,
@ -33,23 +33,15 @@ from ubuntutools.config import UDTConfig
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
try: try:
import SOAPpy import debianbts
except ImportError: except ImportError:
Logger.error("Please install 'python-soappy' in order to use this utility.") Logger.error("Please install 'python3-debianbts' in order to use this utility.")
sys.exit(1) sys.exit(1)
def main(): def main():
bug_re = re.compile(r"bug=(\d+)") bug_re = re.compile(r"bug=(\d+)")
url = 'http://bugs.debian.org/cgi-bin/soap.cgi'
namespace = 'Debbugs/SOAP'
debbugs = SOAPpy.SOAPProxy(url, namespace)
# debug
# debbugs.config.dumpSOAPOut = 1
# debbugs.config.dumpSOAPIn = 1
parser = OptionParser(usage="%prog [option] bug ...") parser = OptionParser(usage="%prog [option] bug ...")
parser.add_option("-b", "--browserless", parser.add_option("-b", "--browserless",
help="Don't open the bug in the browser at the end", help="Don't open the bug in the browser at the end",
@ -94,7 +86,7 @@ def main():
bug_num = int(bug_num) bug_num = int(bug_num)
bug_nums.append(bug_num) bug_nums.append(bug_num)
bugs = debbugs.get_status(*bug_nums) bugs = debianbts.get_status(*bug_nums)
if len(bug_nums) > 1: if len(bug_nums) > 1:
bugs = bugs[0] bugs = bugs[0]
@ -104,14 +96,14 @@ def main():
sys.exit(1) sys.exit(1)
for bug in bugs: for bug in bugs:
bug = bug.value
ubupackage = package = bug.source ubupackage = package = bug.source
if options.package: if options.package:
ubupackage = options.package ubupackage = options.package
bug_num = bug.bug_num bug_num = bug.bug_num
subject = bug.subject subject = bug.subject
log = debbugs.get_bug_log(bug_num) summary = bug.summary
summary = log[0][0] log = debianbts.get_bug_log(bug_num)
summary = log[0]['body']
target = ubuntu.getSourcePackage(name=ubupackage) target = ubuntu.getSourcePackage(name=ubupackage)
if target is None: if target is None:
Logger.error("Source package '%s' is not in Ubuntu. Please specify " Logger.error("Source package '%s' is not in Ubuntu. Please specify "

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright © 2008 Canonical Ltd. # Copyright © 2008 Canonical Ltd.
# Author: Scott James Remnant <scott at ubuntu.com>. # Author: Scott James Remnant <scott at ubuntu.com>.
@ -21,15 +21,17 @@
import re import re
import sys import sys
from debian.debian_support import Version
def usage(exit_code=1): def usage(exit_code=1):
print '''Usage: merge-changelog <left changelog> <right changelog> print('''Usage: merge-changelog <left changelog> <right changelog>
merge-changelog takes two changelogs that once shared a common source, merge-changelog takes two changelogs that once shared a common source,
merges them back together, and prints the merged result to stdout. This merges them back together, and prints the merged result to stdout. This
is useful if you need to manually merge a ubuntu package with a new is useful if you need to manually merge a ubuntu package with a new
Debian release of the package. Debian release of the package.
''' ''')
sys.exit(exit_code) sys.exit(exit_code)
######################################################################## ########################################################################
@ -51,15 +53,15 @@ def merge_changelog(left_changelog, right_changelog):
for right_ver, right_text in right_cl: for right_ver, right_text in right_cl:
while len(left_cl) and left_cl[0][0] > right_ver: while len(left_cl) and left_cl[0][0] > right_ver:
(left_ver, left_text) = left_cl.pop(0) (left_ver, left_text) = left_cl.pop(0)
print left_text print(left_text)
while len(left_cl) and left_cl[0][0] == right_ver: while len(left_cl) and left_cl[0][0] == right_ver:
(left_ver, left_text) = left_cl.pop(0) (left_ver, left_text) = left_cl.pop(0)
print right_text print(right_text)
for _, left_text in left_cl: for _, left_text in left_cl:
print left_text print(left_text)
return False return False
@ -98,174 +100,6 @@ def read_changelog(filename):
return entries return entries
########################################################################
# Version parsing code
########################################################################
# Regular expressions make validating things easy
VALID_EPOCH = re.compile(r'^[0-9]+$')
VALID_UPSTREAM = re.compile(r'^[A-Za-z0-9+:.~-]*$')
VALID_REVISION = re.compile(r'^[A-Za-z0-9+.~]+$')
# Character comparison table for upstream and revision components
CMP_TABLE = "~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-.:"
class Version(object):
"""Debian version number.
This class is designed to be reasonably transparent and allow you
to write code like:
| s.version >= '1.100-1'
The comparison will be done according to Debian rules, so '1.2' will
compare lower.
Properties:
epoch Epoch
upstream Upstream version
revision Debian/local revision
"""
def __init__(self, ver):
"""Parse a string or number into the three components."""
self.epoch = 0
self.upstream = None
self.revision = None
ver = str(ver)
if not len(ver):
raise ValueError
# Epoch is component before first colon
idx = ver.find(":")
if idx != -1:
self.epoch = ver[:idx]
if not len(self.epoch):
raise ValueError
if not VALID_EPOCH.search(self.epoch):
raise ValueError
ver = ver[idx+1:]
# Revision is component after last hyphen
idx = ver.rfind("-")
if idx != -1:
self.revision = ver[idx+1:]
if not len(self.revision):
raise ValueError
if not VALID_REVISION.search(self.revision):
raise ValueError
ver = ver[:idx]
# Remaining component is upstream
self.upstream = ver
if not len(self.upstream):
raise ValueError
if not VALID_UPSTREAM.search(self.upstream):
raise ValueError
self.epoch = int(self.epoch)
def get_without_epoch(self):
"""Return the version without the epoch."""
string = self.upstream
if self.revision is not None:
string += "-%s" % (self.revision,)
return string
without_epoch = property(get_without_epoch)
def __str__(self):
"""Return the class as a string for printing."""
string = ""
if self.epoch > 0:
string += "%d:" % (self.epoch,)
string += self.upstream
if self.revision is not None:
string += "-%s" % (self.revision,)
return string
def __repr__(self):
"""Return a debugging representation of the object."""
return "<%s epoch: %d, upstream: %r, revision: %r>" \
% (self.__class__.__name__, self.epoch,
self.upstream, self.revision)
def __cmp__(self, other):
"""Compare two Version classes."""
other = Version(other)
result = cmp(self.epoch, other.epoch)
if result != 0:
return result
result = deb_cmp(self.upstream, other.upstream)
if result != 0:
return result
result = deb_cmp(self.revision or "", other.revision or "")
if result != 0:
return result
return 0
def strcut(string, idx, accept):
"""Cut characters from string that are entirely in accept."""
ret = ""
while idx < len(string) and string[idx] in accept:
ret += string[idx]
idx += 1
return (ret, idx)
def deb_order(string, idx):
"""Return the comparison order of two characters."""
if idx >= len(string):
return 0
elif string[idx] == "~":
return -1
else:
return CMP_TABLE.index(string[idx])
def deb_cmp_str(x, y):
"""Compare two strings in a deb version."""
idx = 0
while (idx < len(x)) or (idx < len(y)):
result = deb_order(x, idx) - deb_order(y, idx)
if result < 0:
return -1
elif result > 0:
return 1
idx += 1
return 0
def deb_cmp(x, y):
"""Implement the string comparison outlined by Debian policy."""
x_idx = y_idx = 0
while x_idx < len(x) or y_idx < len(y):
# Compare strings
(x_str, x_idx) = strcut(x, x_idx, CMP_TABLE)
(y_str, y_idx) = strcut(y, y_idx, CMP_TABLE)
result = deb_cmp_str(x_str, y_str)
if result != 0:
return result
# Compare numbers
(x_str, x_idx) = strcut(x, x_idx, "0123456789")
(y_str, y_idx) = strcut(y, y_idx, "0123456789")
result = cmp(int(x_str or "0"), int(y_str or "0"))
if result != 0:
return result
return 0
def main(): def main():
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'): if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'):
usage(0) usage(0)

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python #! /usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2007-2010, Siegfried-A. Gevatter <rainct@ubuntu.com>, # Copyright (C) 2007-2010, Siegfried-A. Gevatter <rainct@ubuntu.com>,
@ -30,6 +30,7 @@
# that the target distribution is always meant to be Ubuntu Hardy. # that the target distribution is always meant to be Ubuntu Hardy.
import os import os
import subprocess
import sys import sys
import debian.deb822 import debian.deb822
@ -40,7 +41,6 @@ import ubuntutools.version
from ubuntutools.config import UDTConfig from ubuntutools.config import UDTConfig
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.question import YesNoQuestion from ubuntutools.question import YesNoQuestion
from ubuntutools import subprocess
class PbuilderDist(object): class PbuilderDist(object):
@ -279,7 +279,7 @@ class PbuilderDist(object):
try: try:
codename = debian_info.codename(self.target_distro, codename = debian_info.codename(self.target_distro,
default=self.target_distro) default=self.target_distro)
except DistroDataOutdated, error: except DistroDataOutdated as error:
Logger.warn(error) Logger.warn(error)
if codename in (debian_info.devel(), 'experimental'): if codename in (debian_info.devel(), 'experimental'):
self.enable_security = False self.enable_security = False
@ -306,7 +306,7 @@ class PbuilderDist(object):
else: else:
try: try:
dev_release = self.target_distro == UbuntuDistroInfo().devel() dev_release = self.target_distro == UbuntuDistroInfo().devel()
except DistroDataOutdated, error: except DistroDataOutdated as error:
Logger.warn(error) Logger.warn(error)
dev_release = True dev_release = True
@ -396,7 +396,7 @@ def show_help(exit_code=0):
Print a help message for pbuilder-dist, and exit with the given code. Print a help message for pbuilder-dist, and exit with the given code.
""" """
print 'See man pbuilder-dist for more information.' print('See man pbuilder-dist for more information.')
sys.exit(exit_code) sys.exit(exit_code)
@ -498,7 +498,7 @@ def main():
if '--debug-echo' not in args: if '--debug-echo' not in args:
sys.exit(subprocess.call(app.get_command(args))) sys.exit(subprocess.call(app.get_command(args)))
else: else:
print app.get_command([arg for arg in args if arg != '--debug-echo']) print(app.get_command([arg for arg in args if arg != '--debug-echo']))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# pull-debian-debdiff - find and download a specific version of a Debian # pull-debian-debdiff - find and download a specific version of a Debian
# package and its immediate parent to generate a debdiff. # package and its immediate parent to generate a debdiff.
# #
@ -84,7 +84,7 @@ def main():
newpkg = DebianSourcePackage(package, version, mirrors=mirrors) newpkg = DebianSourcePackage(package, version, mirrors=mirrors)
try: try:
newpkg.pull() newpkg.pull()
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
newpkg.unpack() newpkg.unpack()
@ -101,10 +101,10 @@ def main():
oldpkg = DebianSourcePackage(package, oldversion, mirrors=mirrors) oldpkg = DebianSourcePackage(package, oldversion, mirrors=mirrors)
try: try:
oldpkg.pull() oldpkg.pull()
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
print 'file://' + oldpkg.debdiff(newpkg, diffstat=True) print('file://' + oldpkg.debdiff(newpkg, diffstat=True))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# pull-lp-source -- pull a source package from Launchpad # pull-lp-source -- pull a source package from Launchpad
# Basic usage: pull-lp-source <source package> [<release>] # Basic usage: pull-lp-source <source package> [<release>]
@ -26,7 +26,8 @@
import json import json
import os import os
import sys import sys
import urllib2 import urllib.error
import urllib.request
from optparse import OptionParser from optparse import OptionParser
from distro_info import UbuntuDistroInfo, DistroDataOutdated from distro_info import UbuntuDistroInfo, DistroDataOutdated
@ -49,11 +50,11 @@ def source_package_for(binary, release):
% (release, binary)) % (release, binary))
data = None data = None
try: try:
data = json.load(urllib2.urlopen(url))['r'] data = json.load(urllib.request.urlopen(url))['r']
except urllib2.URLError, e: except urllib.error.URLError as e:
Logger.error('Unable to retrieve package information from DDE: ' Logger.error('Unable to retrieve package information from DDE: '
'%s (%s)', url, str(e)) '%s (%s)', url, str(e))
except ValueError, e: except ValueError as e:
Logger.error('Unable to parse JSON response from DDE: ' Logger.error('Unable to parse JSON response from DDE: '
'%s (%s)', url, str(e)) '%s (%s)', url, str(e))
if not data: if not data:
@ -94,7 +95,7 @@ def main():
else: else:
try: try:
version = os.getenv('DIST') or ubuntu_info.devel() version = os.getenv('DIST') or ubuntu_info.devel()
except DistroDataOutdated, e: except DistroDataOutdated as e:
Logger.warn("%s\nOr specify a distribution.", e) Logger.warn("%s\nOr specify a distribution.", e)
sys.exit(1) sys.exit(1)
component = None component = None
@ -104,16 +105,16 @@ def main():
pocket = None pocket = None
try: try:
(release, pocket) = split_release_pocket(version, default=None) (release, pocket) = split_release_pocket(version, default=None)
except PocketDoesNotExistError, e: except PocketDoesNotExistError:
pass pass
if release in ubuntu_info.all: if release in ubuntu_info.all:
archive = Distribution('ubuntu').getArchive() archive = Distribution('ubuntu').getArchive()
try: try:
spph = archive.getSourcePackage(package, release, pocket) spph = archive.getSourcePackage(package, release, pocket)
except SeriesNotFoundException, e: except SeriesNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
except PackageNotFoundException, e: except PackageNotFoundException as e:
source_package = source_package_for(package, release) source_package = source_package_for(package, release)
if source_package is not None and source_package != package: if source_package is not None and source_package != package:
try: try:
@ -135,7 +136,7 @@ def main():
mirrors=[options.ubuntu_mirror]) mirrors=[options.ubuntu_mirror])
try: try:
srcpkg.pull() srcpkg.pull()
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
if not options.download_only: if not options.download_only:

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# pull-uca-source -- pull a source package from Ubuntu Cloud Archive # pull-uca-source -- pull a source package from Ubuntu Cloud Archive
# Basic usage: pull-uca-source <source package> <openstack release> [version] # Basic usage: pull-uca-source <source package> <openstack release> [version]
@ -118,12 +118,12 @@ def main():
pocket = None pocket = None
try: try:
(release, pocket) = split_release_pocket(release, default=None) (release, pocket) = split_release_pocket(release, default=None)
except PocketDoesNotExistError, e: except PocketDoesNotExistError:
pass pass
try: try:
archive = uca.getPPAByName(name="%s-staging" % release) archive = uca.getPPAByName(name="%s-staging" % release)
except NotFound, e: except NotFound:
Logger.error('Archive does not exist for Openstack release: %s', Logger.error('Archive does not exist for Openstack release: %s',
release) release)
showOpenstackReleases(uca) showOpenstackReleases(uca)
@ -143,7 +143,7 @@ def main():
try: try:
srcpkg.pull() srcpkg.pull()
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
if not options.download_only: if not options.download_only:

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
# #
@ -102,7 +102,12 @@ def check_existing(package, destinations):
Logger.normal("There are existing bug reports that look similar to your " Logger.normal("There are existing bug reports that look similar to your "
"request. Please check before continuing:") "request. Please check before continuing:")
for bug in sorted(set(bug_task.bug for bug_task in bugs)): by_id = {}
for bug_task in bugs:
bug = bug_task.bug
by_id[bug.id] = bug
for id_, bug in sorted(by_id.items()):
Logger.normal(" * LP: #%-7i: %s %s", bug.id, bug.title, bug.web_link) Logger.normal(" * LP: #%-7i: %s %s", bug.id, bug.title, bug.web_link)
confirmation_prompt() confirmation_prompt()
@ -123,7 +128,7 @@ def find_rdepends(releases, published_binaries):
except RDependsException: except RDependsException:
# Not published? TODO: Check # Not published? TODO: Check
continue continue
for relationship, rdeps in raw_rdeps.iteritems(): for relationship, rdeps in raw_rdeps.items():
for rdep in rdeps: for rdep in rdeps:
# Ignore circular deps: # Ignore circular deps:
if rdep['Package'] in published_binaries: if rdep['Package'] in published_binaries:
@ -134,14 +139,14 @@ def find_rdepends(releases, published_binaries):
intermediate[binpkg][rdep['Package']].append((release, relationship)) intermediate[binpkg][rdep['Package']].append((release, relationship))
output = [] output = []
for binpkg, rdeps in intermediate.iteritems(): for binpkg, rdeps in intermediate.items():
output += ['', binpkg, '-' * len(binpkg)] output += ['', binpkg, '-' * len(binpkg)]
for pkg, appearences in rdeps.iteritems(): for pkg, appearences in rdeps.items():
output += ['* %s' % pkg] output += ['* %s' % pkg]
for release, relationship in appearences: for release, relationship in appearences:
output += [' [ ] %s (%s)' % (release, relationship)] output += [' [ ] %s (%s)' % (release, relationship)]
found_any = sum(len(rdeps) for rdeps in intermediate.itervalues()) found_any = sum(len(rdeps) for rdeps in intermediate.values())
if found_any: if found_any:
output = [ output = [
"Reverse dependencies:", "Reverse dependencies:",
@ -168,7 +173,7 @@ def locate_package(package, distribution):
try: try:
package_spph = archive.getSourcePackage(package, distribution) package_spph = archive.getSourcePackage(package, distribution)
return package_spph return package_spph
except PackageNotFoundException, e: except PackageNotFoundException as e:
if pass_ == 'binary': if pass_ == 'binary':
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
@ -292,7 +297,7 @@ def main():
try: try:
destinations = determine_destinations(options.source, destinations = determine_destinations(options.source,
options.destination) options.destination)
except DestinationException, e: except DestinationException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (C) 2007 Canonical Ltd., Steve Kowalik # (C) 2007 Canonical Ltd., Steve Kowalik
@ -97,7 +97,7 @@ def main():
config = UDTConfig(options.no_conf) config = UDTConfig(options.no_conf)
if options.deprecated_lp_flag: if options.deprecated_lp_flag:
print "The --lp flag is now default, ignored." print("The --lp flag is now default, ignored.")
if options.email: if options.email:
options.lpapi = False options.lpapi = False
else: else:
@ -115,8 +115,8 @@ def main():
elif options.lpinstance == 'staging': elif options.lpinstance == 'staging':
bug_mail_domain = 'bugs.staging.launchpad.net' bug_mail_domain = 'bugs.staging.launchpad.net'
else: else:
print >> sys.stderr, ('Error: Unknown launchpad instance: %s' print('Error: Unknown launchpad instance: %s' % options.lpinstance,
% options.lpinstance) file=sys.stderr)
sys.exit(1) sys.exit(1)
mailserver_host = config.get_value('SMTP_SERVER', mailserver_host = config.get_value('SMTP_SERVER',
@ -130,8 +130,8 @@ def main():
firstmx = mxlist[0] firstmx = mxlist[0]
mailserver_host = firstmx[1] mailserver_host = firstmx[1]
except ImportError: except ImportError:
print >> sys.stderr, ('Please install python-dns to support ' print('Please install python3-dns to support Launchpad mail '
'Launchpad mail server lookup.') 'server lookup.', file=sys.stderr)
sys.exit(1) sys.exit(1)
mailserver_port = config.get_value('SMTP_PORT', default=25, mailserver_port = config.get_value('SMTP_PORT', default=25,
@ -167,9 +167,9 @@ def main():
get_ubuntu_delta_changelog, get_ubuntu_delta_changelog,
mail_bug, need_sponsorship) mail_bug, need_sponsorship)
if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')): if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')):
print >> sys.stderr, ( print('E: The environment variable UBUMAIL, DEBEMAIL or EMAIL '
'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs ' 'needs to be set to let this script mail the sync request.',
'to be set to let this script mail the sync request.') file=sys.stderr)
sys.exit(1) sys.exit(1)
newsource = options.newpkg newsource = options.newpkg
@ -187,14 +187,15 @@ def main():
else: else:
ubu_info = UbuntuDistroInfo() ubu_info = UbuntuDistroInfo()
release = ubu_info.devel() release = ubu_info.devel()
print >> sys.stderr, 'W: Target release missing - assuming %s' % release print('W: Target release missing - assuming %s' % release,
file=sys.stderr)
elif len(args) == 2: elif len(args) == 2:
release = args[1] release = args[1]
elif len(args) == 3: elif len(args) == 3:
release = args[1] release = args[1]
force_base_version = Version(args[2]) force_base_version = Version(args[2])
else: else:
print >> sys.stderr, 'E: Too many arguments.' print('E: Too many arguments.', file=sys.stderr)
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
@ -209,12 +210,13 @@ def main():
ubuntu_version = Version('~') ubuntu_version = Version('~')
ubuntu_component = None # Set after getting the Debian info ubuntu_component = None # Set after getting the Debian info
if not newsource: if not newsource:
print("'%s' doesn't exist in 'Ubuntu %s'.\nDo you want to sync a new package?" % print(("'%s' doesn't exist in 'Ubuntu %s'.\n"
(srcpkg, release)) "Do you want to sync a new package?")
% (srcpkg, release))
confirmation_prompt() confirmation_prompt()
newsource = True newsource = True
except udtexceptions.SeriesNotFoundException, error: except udtexceptions.SeriesNotFoundException as error:
print >> sys.stderr, "E: %s" % error print("E: %s" % error, file=sys.stderr)
sys.exit(1) sys.exit(1)
# Get the requested Debian source package # Get the requested Debian source package
@ -222,11 +224,11 @@ def main():
debian_srcpkg = get_debian_srcpkg(srcpkg, distro) debian_srcpkg = get_debian_srcpkg(srcpkg, distro)
debian_version = Version(debian_srcpkg.getVersion()) debian_version = Version(debian_srcpkg.getVersion())
debian_component = debian_srcpkg.getComponent() debian_component = debian_srcpkg.getComponent()
except udtexceptions.PackageNotFoundException, error: except udtexceptions.PackageNotFoundException as error:
print >> sys.stderr, "E: %s" % error print("E: %s" % error, file=sys.stderr)
sys.exit(1) sys.exit(1)
except udtexceptions.SeriesNotFoundException, error: except udtexceptions.SeriesNotFoundException as error:
print >> sys.stderr, "E: %s" % error print("E: %s" % error, file=sys.stderr)
sys.exit(1) sys.exit(1)
if ubuntu_component is None: if ubuntu_component is None:
@ -243,18 +245,18 @@ def main():
debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg(srcpkg, distro) debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg(srcpkg, distro)
debian_version = Version(debian_srcpkg.getVersion()) debian_version = Version(debian_srcpkg.getVersion())
debian_component = debian_srcpkg.getComponent() debian_component = debian_srcpkg.getComponent()
except udtexceptions.PackageNotFoundException, error: except udtexceptions.PackageNotFoundException as error:
print >> sys.stderr, "E: %s" % error print("E: %s" % error, file=sys.stderr)
sys.exit(1) sys.exit(1)
if ubuntu_version == debian_version: if ubuntu_version == debian_version:
print >> sys.stderr, ('E: The versions in Debian and Ubuntu are the ' print('E: The versions in Debian and Ubuntu are the same already '
'same already (%s). Aborting.' % ubuntu_version) '(%s). Aborting.' % ubuntu_version, file=sys.stderr)
sys.exit(1) sys.exit(1)
if ubuntu_version > debian_version: if ubuntu_version > debian_version:
print >> sys.stderr, ('E: The version in Ubuntu (%s) is newer than ' print(('E: The version in Ubuntu (%s) is newer than the version in '
'the version in Debian (%s). Aborting.' 'Debian (%s). Aborting.')
% (ubuntu_version, debian_version)) % (ubuntu_version, debian_version), file=sys.stderr)
sys.exit(1) sys.exit(1)
# -s flag not specified - check if we do need sponsorship # -s flag not specified - check if we do need sponsorship
@ -262,8 +264,8 @@ def main():
sponsorship = need_sponsorship(srcpkg, ubuntu_component, release) sponsorship = need_sponsorship(srcpkg, ubuntu_component, release)
if not sponsorship and not ffe: if not sponsorship and not ffe:
print >> sys.stderr, ('Consider using syncpackage(1) for syncs that ' print('Consider using syncpackage(1) for syncs that do not require '
'do not require feature freeze exceptions.') 'feature freeze exceptions.', file=sys.stderr)
# Check for existing package reports # Check for existing package reports
if not newsource: if not newsource:
@ -284,8 +286,8 @@ def main():
print('Changes have been made to the package in Ubuntu.\n' print('Changes have been made to the package in Ubuntu.\n'
'Please edit the report and give an explanation.\n' 'Please edit the report and give an explanation.\n'
'Not saving the report file will abort the request.') 'Not saving the report file will abort the request.')
report += (u'Explanation of the Ubuntu delta and why it can be ' report += ('Explanation of the Ubuntu delta and why it can be '
u'dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n' 'dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n'
% get_ubuntu_delta_changelog(ubuntu_srcpkg)) % get_ubuntu_delta_changelog(ubuntu_srcpkg))
if ffe: if ffe:
@ -310,10 +312,10 @@ def main():
changelog = debian_srcpkg.getChangelog(since_version=base_version) changelog = debian_srcpkg.getChangelog(since_version=base_version)
if not changelog: if not changelog:
if not options.missing_changelog_ok: if not options.missing_changelog_ok:
print >> sys.stderr, ("E: Did not retrieve any changelog entries. " print("E: Did not retrieve any changelog entries. "
"Do you need to specify '-C'? " "Do you need to specify '-C'? "
"Was the package recently uploaded? (check " "Was the package recently uploaded? (check "
"http://packages.debian.org/changelogs/)") "http://packages.debian.org/changelogs/)", file=sys.stderr)
sys.exit(1) sys.exit(1)
else: else:
need_interaction = True need_interaction = True
@ -325,8 +327,8 @@ def main():
title, report = editor.get_report() title, report = editor.get_report()
if 'XXX FIXME' in report: if 'XXX FIXME' in report:
print >> sys.stderr, ("E: changelog boilerplate found in report, " print("E: changelog boilerplate found in report, please manually add "
"please manually add changelog when using '-C'") "changelog when using '-C'", file=sys.stderr)
sys.exit(1) sys.exit(1)
# bug status and bug subscriber # bug status and bug subscriber
@ -357,5 +359,5 @@ if __name__ == '__main__':
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
print "\nUser abort." print("\nUser abort.")
sys.exit(2) sys.exit(2)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
# #
@ -106,12 +106,12 @@ def main():
sys.exit(1) sys.exit(1)
def filter_out_fiels(data, fields): def filter_out_fiels(data, fields):
for field in data.keys(): for field in list(data.keys()):
if field not in fields: if field not in fields:
del data[field] del data[field]
def filter_out_component(data, component): def filter_out_component(data, component):
for field, rdeps in data.items(): for field, rdeps in list(data.items()):
filtered = [rdep for rdep in rdeps filtered = [rdep for rdep in rdeps
if rdep['Component'] in component] if rdep['Component'] in component]
if not filtered: if not filtered:
@ -141,7 +141,7 @@ def main():
filter_out_component(result[package], component) filter_out_component(result[package], component)
if recursive > 0: if recursive > 0:
for rdeps in result[package].itervalues(): for rdeps in result[package].values():
for rdep in rdeps: for rdep in rdeps:
build_results( build_results(
rdep['Package'], result, fields, component, recursive - 1) rdep['Package'], result, fields, component, recursive - 1)
@ -178,7 +178,7 @@ def display_verbose(package, values):
data = values.get(package) data = values.get(package)
if data: if data:
offset = offset + 1 offset = offset + 1
for rdeps in data.itervalues(): for rdeps in data.values():
for rdep in rdeps: for rdep in rdeps:
print_package(values, print_package(values,
rdep['Package'], rdep['Package'],
@ -188,13 +188,13 @@ def display_verbose(package, values):
all_archs = set() all_archs = set()
# This isn't accurate, but we make up for it by displaying what we found # This isn't accurate, but we make up for it by displaying what we found
for data in values.itervalues(): for data in values.values():
for rdeps in data.itervalues(): for rdeps in data.values():
for rdep in rdeps: for rdep in rdeps:
if 'Architectures' in rdep: if 'Architectures' in rdep:
all_archs.update(rdep['Architectures']) all_archs.update(rdep['Architectures'])
for field, rdeps in values[package].iteritems(): for field, rdeps in values[package].items():
print_field(field) print_field(field)
rdeps.sort(key=lambda x: x['Package']) rdeps.sort(key=lambda x: x['Package'])
for rdep in rdeps: for rdep in rdeps:
@ -202,7 +202,7 @@ def display_verbose(package, values):
rdep['Package'], rdep['Package'],
rdep.get('Architectures', all_archs), rdep.get('Architectures', all_archs),
rdep.get('Dependency')) rdep.get('Dependency'))
print print()
if all_archs: if all_archs:
print("Packages without architectures listed are " print("Packages without architectures listed are "
@ -212,12 +212,12 @@ def display_verbose(package, values):
def display_consise(values): def display_consise(values):
result = set() result = set()
for data in values.itervalues(): for data in values.values():
for rdeps in data.itervalues(): for rdeps in data.values():
for rdep in rdeps: for rdep in rdeps:
result.add(rdep['Package']) result.add(rdep['Package'])
print(u'\n'.join(sorted(list(result)))) print('\n'.join(sorted(list(result))))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
# #
@ -20,7 +20,7 @@ import json
import optparse import optparse
import os import os
import time import time
import urllib import urllib.request
from ubuntutools.lp.lpapicache import (Distribution, Launchpad, from ubuntutools.lp.lpapicache import (Distribution, Launchpad,
PackageNotFoundException) PackageNotFoundException)
@ -40,12 +40,12 @@ def load_index(url):
or time.time() - os.path.getmtime(fn) > 60 * 60 * 2): or time.time() - os.path.getmtime(fn) > 60 * 60 * 2):
if not os.path.isdir(cachedir): if not os.path.isdir(cachedir):
os.makedirs(cachedir) os.makedirs(cachedir)
urllib.urlretrieve(url, fn) urllib.request.urlretrieve(url, fn)
try: try:
with gzip.open(fn, 'r') as f: with gzip.open(fn, 'r') as f:
return json.load(f) return json.load(f)
except Exception, e: except Exception as e:
Logger.error("Unable to parse seed data: %s. " Logger.error("Unable to parse seed data: %s. "
"Deleting cached data, please try again.", "Deleting cached data, please try again.",
str(e)) str(e))
@ -61,7 +61,7 @@ def resolve_binaries(sources):
for source in sources: for source in sources:
try: try:
spph = archive.getSourcePackage(source) spph = archive.getSourcePackage(source)
except PackageNotFoundException, e: except PackageNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
continue continue
binaries[source] = sorted(set(bpph.getPackageName() binaries[source] = sorted(set(bpph.getPackageName()
@ -75,11 +75,11 @@ def present_on(appearences):
present = collections.defaultdict(set) present = collections.defaultdict(set)
for flavor, type_ in appearences: for flavor, type_ in appearences:
present[flavor].add(type_) present[flavor].add(type_)
for flavor, types in present.iteritems(): for flavor, types in present.items():
if len(types) > 1: if len(types) > 1:
types.discard('supported') types.discard('supported')
output = [' %s: %s' % (flavor, ', '.join(sorted(types))) output = [' %s: %s' % (flavor, ', '.join(sorted(types)))
for flavor, types in present.iteritems()] for flavor, types in present.items()]
output.sort() output.sort()
return '\n'.join(output) return '\n'.join(output)
@ -88,28 +88,28 @@ def output_binaries(index, binaries):
'''Print binaries found in index''' '''Print binaries found in index'''
for binary in binaries: for binary in binaries:
if binary in index: if binary in index:
print "%s is seeded in:" % binary print("%s is seeded in:" % binary)
print present_on(index[binary]) print(present_on(index[binary]))
else: else:
print "%s is not seeded (and may not exist)." % binary print("%s is not seeded (and may not exist)." % binary)
def output_by_source(index, by_source): def output_by_source(index, by_source):
'''Print binaries found in index. Grouped by source''' '''Print binaries found in index. Grouped by source'''
for source, binaries in by_source.iteritems(): for source, binaries in by_source.items():
seen = False seen = False
if not binaries: if not binaries:
print ("Status unknown: No binary packages built by the latest " print("Status unknown: No binary packages built by the latest "
"%s.\nTry again using -b and the expected binary packages." "%s.\nTry again using -b and the expected binary packages."
% source) % source)
continue continue
for binary in binaries: for binary in binaries:
if binary in index: if binary in index:
seen = True seen = True
print "%s (from %s) is seeded in:" % (binary, source) print("%s (from %s) is seeded in:" % (binary, source))
print present_on(index[binary]) print(present_on(index[binary]))
if not seen: if not seen:
print "%s's binaries are not seeded." % source print("%s's binaries are not seeded." % source)
def main(): def main():

View File

@ -4,62 +4,54 @@ from setuptools import setup
import glob import glob
import os import os
import re import re
import sys
import codecs
# look/set what version we have # look/set what version we have
changelog = "debian/changelog" changelog = "debian/changelog"
if os.path.exists(changelog): if os.path.exists(changelog):
head = codecs.open(changelog, 'r', 'utf-8', 'replace').readline() head = open(changelog, 'r', encoding='utf-8').readline()
match = re.compile(r".*\((.*)\).*").match(head) match = re.compile(r".*\((.*)\).*").match(head)
if match: if match:
version = match.group(1) version = match.group(1)
if sys.version_info[0] >= 3: scripts = [
scripts = [ 'backportpackage',
'pull-debian-source', 'bitesize',
] 'check-mir',
data_files = [] 'check-symbols',
else: 'dch-repeat',
scripts = [ 'grab-merge',
'404main', 'grep-merges',
'backportpackage', 'hugdaylist',
'bitesize', 'import-bug-from-debian',
'check-mir', 'merge-changelog',
'check-symbols', 'mk-sbuild',
'dch-repeat', 'pbuilder-dist',
'grab-merge', 'pbuilder-dist-simple',
'grep-merges', 'pull-debian-debdiff',
'hugdaylist', 'pull-debian-source',
'import-bug-from-debian', 'pull-lp-source',
'merge-changelog', 'pull-revu-source',
'mk-sbuild', 'pull-uca-source',
'pbuilder-dist', 'requestbackport',
'pbuilder-dist-simple', 'requestsync',
'pull-debian-debdiff', 'reverse-build-depends',
'pull-lp-source', 'reverse-depends',
'pull-revu-source', 'seeded-in-ubuntu',
'pull-uca-source', 'setup-packaging-environment',
'requestbackport', 'sponsor-patch',
'requestsync', 'submittodebian',
'reverse-build-depends', 'syncpackage',
'reverse-depends', 'ubuntu-build',
'seeded-in-ubuntu', 'ubuntu-iso',
'setup-packaging-environment', 'ubuntu-upload-permission',
'sponsor-patch', 'update-maintainer',
'submittodebian', ]
'syncpackage', data_files = [
'ubuntu-build', ('share/bash-completion/completions', glob.glob("bash_completion/*")),
'ubuntu-iso', ('share/man/man1', glob.glob("doc/*.1")),
'ubuntu-upload-permission', ('share/man/man5', glob.glob("doc/*.5")),
'update-maintainer', ('share/ubuntu-dev-tools', ['enforced-editing-wrapper']),
] ]
data_files = [
('share/bash-completion/completions', glob.glob("bash_completion/*")),
('share/man/man1', glob.glob("doc/*.1")),
('share/man/man5', glob.glob("doc/*.5")),
('share/ubuntu-dev-tools', ['enforced-editing-wrapper']),
]
if __name__ == '__main__': if __name__ == '__main__':
setup( setup(

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2010-2011, Benjamin Drung <bdrung@ubuntu.com> # Copyright (C) 2010-2011, Benjamin Drung <bdrung@ubuntu.com>
# #
@ -123,7 +123,7 @@ def main():
options.keyid, options.lpinstance, options.update, options.keyid, options.lpinstance, options.update,
options.upload, workdir) options.upload, workdir)
except KeyboardInterrupt: except KeyboardInterrupt:
print "\nUser abort." print("\nUser abort.")
sys.exit(2) sys.exit(2)
finally: finally:
if options.workdir is None: if options.workdir is None:

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# submittodebian - tool to submit patches to Debian's BTS # submittodebian - tool to submit patches to Debian's BTS
@ -27,22 +27,16 @@ import os
import re import re
import shutil import shutil
import sys import sys
from subprocess import call, check_call, Popen, PIPE
from tempfile import mkdtemp from tempfile import mkdtemp
from debian.changelog import Changelog
from distro_info import UbuntuDistroInfo, DistroDataOutdated from distro_info import UbuntuDistroInfo, DistroDataOutdated
from ubuntutools.config import ubu_email from ubuntutools.config import ubu_email
from ubuntutools.question import YesNoQuestion, EditFile from ubuntutools.question import YesNoQuestion, EditFile
from ubuntutools.subprocess import call, check_call, Popen, PIPE
from ubuntutools.update_maintainer import update_maintainer, restore_maintainer from ubuntutools.update_maintainer import update_maintainer, restore_maintainer
try:
from debian.changelog import Changelog
except ImportError:
print(u"This utility requires modules from the «python-debian» package, "
u"which isn't currently installed.")
sys.exit(1)
def get_most_recent_debian_version(changelog): def get_most_recent_debian_version(changelog):
for block in changelog: for block in changelog:
@ -94,7 +88,7 @@ def gen_debdiff(tmpdir, changelog):
devnull = open('/dev/null', 'w') devnull = open('/dev/null', 'w')
diff_cmd = ['bzr', 'diff', '-r', 'tag:' + str(oldver)] diff_cmd = ['bzr', 'diff', '-r', 'tag:' + str(oldver)]
if call(diff_cmd, stdout=devnull, stderr=devnull) == 1: if call(diff_cmd, stdout=devnull, stderr=devnull) == 1:
print "Extracting bzr diff between %s and %s" % (oldver, newver) print("Extracting bzr diff between %s and %s" % (oldver, newver))
else: else:
if oldver.epoch is not None: if oldver.epoch is not None:
oldver = str(oldver)[str(oldver).index(":") + 1:] oldver = str(oldver)[str(oldver).index(":") + 1:]
@ -107,7 +101,7 @@ def gen_debdiff(tmpdir, changelog):
check_file(olddsc) check_file(olddsc)
check_file(newdsc) check_file(newdsc)
print "Generating debdiff between %s and %s" % (oldver, newver) print("Generating debdiff between %s and %s" % (oldver, newver))
diff_cmd = ['debdiff', olddsc, newdsc] diff_cmd = ['debdiff', olddsc, newdsc]
diff = Popen(diff_cmd, stdout=PIPE) diff = Popen(diff_cmd, stdout=PIPE)
@ -128,15 +122,15 @@ def check_file(fname, critical=True):
else: else:
if not critical: if not critical:
return False return False
print u"Couldn't find «%s».\n" % fname print("Couldn't find «%s».\n" % fname)
sys.exit(1) sys.exit(1)
def submit_bugreport(body, debdiff, deb_version, changelog): def submit_bugreport(body, debdiff, deb_version, changelog):
try: try:
devel = UbuntuDistroInfo().devel() devel = UbuntuDistroInfo().devel()
except DistroDataOutdated, e: except DistroDataOutdated as e:
print str(e) print(str(e))
devel = '' devel = ''
if os.path.dirname(sys.argv[0]).startswith('/usr/bin'): if os.path.dirname(sys.argv[0]).startswith('/usr/bin'):
@ -203,10 +197,10 @@ no-cc
#smtptls #smtptls
""" % email """ % email
with file(fn, 'w') as f: with open(fn, 'w') as f:
f.write(reportbugrc) f.write(reportbugrc)
print """\ print("""\
You have not configured reportbug. Assuming this is the first time you have You have not configured reportbug. Assuming this is the first time you have
used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC
the bug to you at <%s> the bug to you at <%s>
@ -217,7 +211,7 @@ the bug to you at <%s>
If this is not correct, please exit now and edit ~/.reportbugrc or run If this is not correct, please exit now and edit ~/.reportbugrc or run
reportbug --configure for its configuration wizard. reportbug --configure for its configuration wizard.
""" % (email, reportbugrc.strip()) """ % (email, reportbugrc.strip()))
if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no": if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no":
sys.exit(1) sys.exit(1)
@ -230,14 +224,15 @@ def main():
parser.parse_args() parser.parse_args()
if not os.path.exists('/usr/bin/reportbug'): if not os.path.exists('/usr/bin/reportbug'):
print(u"This utility requires the «reportbug» package, which isn't " print("This utility requires the «reportbug» package, which isn't "
u"currently installed.") "currently installed.")
sys.exit(1) sys.exit(1)
check_reportbug_config() check_reportbug_config()
changelog_file = (check_file('debian/changelog', critical=False) or changelog_file = (check_file('debian/changelog', critical=False) or
check_file('../debian/changelog')) check_file('../debian/changelog'))
changelog = Changelog(file(changelog_file).read()) with open(changelog_file) as f:
changelog = Changelog(f.read())
deb_version = get_most_recent_debian_version(changelog) deb_version = get_most_recent_debian_version(changelog)
bug_body = get_bug_body(changelog) bug_body = get_bug_body(changelog)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2008-2010 Martin Pitt <martin.pitt@canonical.com>, # Copyright (C) 2008-2010 Martin Pitt <martin.pitt@canonical.com>,
@ -20,14 +20,14 @@
# #
# ################################################################## # ##################################################################
import codecs
import fnmatch import fnmatch
import optparse import optparse
import os import os
import shutil import shutil
import subprocess
import sys import sys
import textwrap import textwrap
import urllib import urllib.request
from lazr.restfulclient.errors import HTTPError from lazr.restfulclient.errors import HTTPError
@ -44,13 +44,12 @@ from ubuntutools.requestsync.mail import (
get_debian_srcpkg as requestsync_mail_get_debian_srcpkg) get_debian_srcpkg as requestsync_mail_get_debian_srcpkg)
from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg
from ubuntutools.version import Version from ubuntutools.version import Version
from ubuntutools import subprocess
def remove_signature(dscname): def remove_signature(dscname):
'''Removes the signature from a .dsc file if the .dsc file is signed.''' '''Removes the signature from a .dsc file if the .dsc file is signed.'''
dsc_file = open(dscname) dsc_file = open(dscname, encoding='utf-8')
if dsc_file.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----": if dsc_file.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----":
unsigned_file = [] unsigned_file = []
# search until begin of body found # search until begin of body found
@ -65,7 +64,7 @@ def remove_signature(dscname):
unsigned_file.append(line) unsigned_file.append(line)
dsc_file.close() dsc_file.close()
dsc_file = open(dscname, "w") dsc_file = open(dscname, "w", encoding='utf-8')
dsc_file.writelines(unsigned_file) dsc_file.writelines(unsigned_file)
dsc_file.close() dsc_file.close()
@ -78,7 +77,7 @@ def add_fixed_bugs(changes, bugs):
# Remove duplicates # Remove duplicates
bugs = set(str(bug) for bug in bugs) bugs = set(str(bug) for bug in bugs)
for i in xrange(len(changes)): for i in range(len(changes)):
if changes[i].startswith("Launchpad-Bugs-Fixed:"): if changes[i].startswith("Launchpad-Bugs-Fixed:"):
bugs.update(changes[i][22:].strip().split(" ")) bugs.update(changes[i][22:].strip().split(" "))
changes[i] = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs)) changes[i] = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs))
@ -137,7 +136,7 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
try: try:
src_pkg.pull() src_pkg.pull()
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
src_pkg.unpack() src_pkg.unpack()
@ -158,7 +157,7 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
# Download Ubuntu files (override Debian source tarballs) # Download Ubuntu files (override Debian source tarballs)
try: try:
ubu_pkg.pull() ubu_pkg.pull()
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
@ -169,7 +168,7 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
# read Debian distribution from debian/changelog if not specified # read Debian distribution from debian/changelog if not specified
if debian_dist is None: if debian_dist is None:
line = open("debian/changelog").readline() line = open("debian/changelog", encoding='utf-8').readline()
debian_dist = line.split(" ")[2].strip(";") debian_dist = line.split(" ")[2].strip(";")
if not fakesync: if not fakesync:
@ -187,8 +186,7 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
if not Logger.verbose: if not Logger.verbose:
cmd += ["-q"] cmd += ["-q"]
Logger.command(cmd + ['>', '../' + changes_filename]) Logger.command(cmd + ['>', '../' + changes_filename])
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) changes = subprocess.check_output(cmd, encoding='utf-8')
changes = process.communicate()[0]
# Add additional bug numbers # Add additional bug numbers
if len(bugs) > 0: if len(bugs) > 0:
@ -200,7 +198,7 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
shutil.rmtree(directory, True) shutil.rmtree(directory, True)
# write changes file # write changes file
changes_file = open(changes_filename, "w") changes_file = open(changes_filename, "w", encoding='utf-8')
changes_file.writelines(changes) changes_file.writelines(changes)
changes_file.close() changes_file.close()
@ -274,7 +272,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release,
try: try:
debian_srcpkg = get_debian_srcpkg(package, dist) debian_srcpkg = get_debian_srcpkg(package, dist)
except (udtexceptions.PackageNotFoundException, except (udtexceptions.PackageNotFoundException,
udtexceptions.SeriesNotFoundException), e: udtexceptions.SeriesNotFoundException) as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
if version is None: if version is None:
@ -286,7 +284,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release,
ubuntu_version = Version(ubuntu_srcpkg.getVersion()) ubuntu_version = Version(ubuntu_srcpkg.getVersion())
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_version = Version('~') ubuntu_version = Version('~')
except udtexceptions.SeriesNotFoundException, e: except udtexceptions.SeriesNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
if ubuntu_version >= version: if ubuntu_version >= version:
@ -388,7 +386,7 @@ def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False):
to_pocket=ubuntu_pocket, to_pocket=ubuntu_pocket,
include_binaries=False, include_binaries=False,
sponsored=sponsoree) sponsored=sponsoree)
except HTTPError, error: except HTTPError as error:
Logger.error("HTTP Error %s: %s", error.response.status, Logger.error("HTTP Error %s: %s", error.response.status,
error.response.reason) error.response.reason)
Logger.error(error.content) Logger.error(error.content)
@ -416,7 +414,7 @@ def is_blacklisted(query):
series = Launchpad.distributions['ubuntu'].current_series series = Launchpad.distributions['ubuntu'].current_series
lp_comments = series.getDifferenceComments(source_package_name=query) lp_comments = series.getDifferenceComments(source_package_name=query)
blacklisted = False blacklisted = False
comments = [u'%s\n -- %s %s' comments = ['%s\n -- %s %s'
% (c.body_text, c.comment_author.name, % (c.body_text, c.comment_author.name,
c.comment_date.strftime('%a, %d %b %Y %H:%M:%S +0000')) c.comment_date.strftime('%a, %d %b %Y %H:%M:%S +0000'))
for c in lp_comments] for c in lp_comments]
@ -430,9 +428,10 @@ def is_blacklisted(query):
# Old blacklist: # Old blacklist:
url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt' url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt'
with codecs.EncodedFile(urllib.urlopen(url), 'UTF-8') as f: with urllib.request.urlopen(url) as f:
applicable_lines = [] applicable_lines = []
for line in f: for line in f:
line = line.decode('utf-8')
if not line.strip(): if not line.strip():
applicable_lines = [] applicable_lines = []
continue continue
@ -475,7 +474,7 @@ def close_bugs(bugs, package, version, changes, sponsoree):
bug.newMessage(content=message) bug.newMessage(content=message)
break break
else: else:
Logger.error(u"Cannot find any tasks on LP: #%i to close.", bug.id) Logger.error("Cannot find any tasks on LP: #%i to close.", bug.id)
def parse(): def parse():
@ -686,9 +685,9 @@ def main():
"reasoning and subscribe ~ubuntu-archive."] "reasoning and subscribe ~ubuntu-archive."]
if blacklist_fail: if blacklist_fail:
Logger.error(u"Source package %s is blacklisted.", src_pkg.source) Logger.error("Source package %s is blacklisted.", src_pkg.source)
elif blacklisted == 'ALWAYS': elif blacklisted == 'ALWAYS':
Logger.normal(u"Source package %s is blacklisted.", src_pkg.source) Logger.normal("Source package %s is blacklisted.", src_pkg.source)
if messages: if messages:
for message in messages: for message in messages:
for line in textwrap.wrap(message): for line in textwrap.wrap(message):
@ -698,7 +697,7 @@ def main():
Logger.normal("Blacklist Comments:") Logger.normal("Blacklist Comments:")
for comment in comments: for comment in comments:
for line in textwrap.wrap(comment): for line in textwrap.wrap(comment):
Logger.normal(u" " + line) Logger.normal(" " + line)
if blacklist_fail: if blacklist_fail:
sys.exit(1) sys.exit(1)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# ubuntu-build - command line interface for Launchpad buildd operations. # ubuntu-build - command line interface for Launchpad buildd operations.
# #
@ -108,15 +108,15 @@ def main():
# Check our operation. # Check our operation.
if op not in ("rescore", "retry", "status"): if op not in ("rescore", "retry", "status"):
print >> sys.stderr, "Invalid operation: %s." % op print("Invalid operation: %s." % op, file=sys.stderr)
sys.exit(1) sys.exit(1)
# If the user has specified an architecture to build, we only wish to # If the user has specified an architecture to build, we only wish to
# rebuild it and nothing else. # rebuild it and nothing else.
if options.architecture: if options.architecture:
if options.architecture[0] not in valid_archs: if options.architecture[0] not in valid_archs:
print >> sys.stderr, ("Invalid architecture specified: %s." print("Invalid architecture specified: %s."
% options.architecture[0]) % options.architecture[0], file=sys.stderr)
sys.exit(1) sys.exit(1)
else: else:
one_arch = True one_arch = True
@ -126,8 +126,8 @@ def main():
# split release and pocket # split release and pocket
try: try:
(release, pocket) = split_release_pocket(release) (release, pocket) = split_release_pocket(release)
except PocketDoesNotExistError, error: except PocketDoesNotExistError as error:
print 'E: %s' % error print('E: %s' % error)
sys.exit(1) sys.exit(1)
# Get the ubuntu archive # Get the ubuntu archive
@ -140,8 +140,8 @@ def main():
try: try:
sources = ubuntu_archive.getSourcePackage(package, release, pocket) sources = ubuntu_archive.getSourcePackage(package, release, pocket)
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution('ubuntu').getSeries(release)
except (SeriesNotFoundException, PackageNotFoundException), error: except (SeriesNotFoundException, PackageNotFoundException) as error:
print error print(error)
sys.exit(1) sys.exit(1)
# Get list of builds for that package. # Get list of builds for that package.
builds = sources.getBuilds() builds = sources.getBuilds()
@ -163,16 +163,16 @@ def main():
pocket=pocket) pocket=pocket)
if op in ('rescore', 'retry') and not necessary_privs: if op in ('rescore', 'retry') and not necessary_privs:
print >> sys.stderr, ("You cannot perform the %s operation on a %s " print(("You cannot perform the %s operation on a %s package as "
"package as you do not have the permissions " "you do not have the permissions to do this action.")
"to do this action." % (op, component)) % (op, component), file=sys.stderr)
sys.exit(1) sys.exit(1)
# Output details. # Output details.
print("The source version for '%s' in %s (%s) is at %s." % print("The source version for '%s' in %s (%s) is at %s."
(package, release.capitalize(), component, version)) % (package, release.capitalize(), component, version))
print "Current build status for this package:" print("Current build status for this package:")
# Output list of arches for package and their status. # Output list of arches for package and their status.
done = False done = False
@ -182,28 +182,29 @@ def main():
continue continue
done = True done = True
print "%s: %s." % (build.arch_tag, build.buildstate) print("%s: %s." % (build.arch_tag, build.buildstate))
if op == 'rescore': if op == 'rescore':
if build.can_be_rescored: if build.can_be_rescored:
# FIXME: make priority an option # FIXME: make priority an option
priority = 5000 priority = 5000
print 'Rescoring build %s to %d...' % (build.arch_tag, priority) print('Rescoring build %s to %d...'
% (build.arch_tag, priority))
build.rescore(score=priority) build.rescore(score=priority)
else: else:
print 'Cannot rescore build on %s.' % build.arch_tag print('Cannot rescore build on %s.' % build.arch_tag)
if op == 'retry': if op == 'retry':
if build.can_be_retried: if build.can_be_retried:
print 'Retrying build on %s...' % build.arch_tag print('Retrying build on %s...' % build.arch_tag)
build.retry() build.retry()
else: else:
print 'Cannot retry build on %s.' % build.arch_tag print('Cannot retry build on %s.' % build.arch_tag)
# We are done # We are done
if done: if done:
sys.exit(0) sys.exit(0)
print("No builds for '%s' found in the %s release - it may have been " print(("No builds for '%s' found in the %s release - it may have been "
"built in a former release." % (package, release.capitalize())) "built in a former release.") % (package, release.capitalize()))
sys.exit(0) sys.exit(0)
# Batch mode # Batch mode
@ -223,15 +224,15 @@ def main():
+ '-proposed') + '-proposed')
try: try:
(release, pocket) = split_release_pocket(release) (release, pocket) = split_release_pocket(release)
except PocketDoesNotExistError, error: except PocketDoesNotExistError as error:
print 'E: %s' % error print('E: %s' % error)
sys.exit(1) sys.exit(1)
ubuntu_archive = Distribution('ubuntu').getArchive() ubuntu_archive = Distribution('ubuntu').getArchive()
try: try:
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution('ubuntu').getSeries(release)
except SeriesNotFoundException, error: except SeriesNotFoundException as error:
print error print(error)
sys.exit(1) sys.exit(1)
me = PersonTeam.me me = PersonTeam.me
@ -240,14 +241,14 @@ def main():
and me.isLpTeamMember('launchpad-buildd-admins')) and me.isLpTeamMember('launchpad-buildd-admins'))
or False) or False)
if options.priority and not can_rescore: if options.priority and not can_rescore:
print >> sys.stderr, ("You don't have the permissions to rescore " print("You don't have the permissions to rescore builds. "
"builds. Ignoring your rescore request.") "Ignoring your rescore request.", file=sys.stderr)
for pkg in args: for pkg in args:
try: try:
pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket) pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket)
except PackageNotFoundException, error: except PackageNotFoundException as error:
print error print(error)
continue continue
# Check permissions (part 2): check upload permissions for the source # Check permissions (part 2): check upload permissions for the source
@ -257,20 +258,20 @@ def main():
pkg.getPackageName(), pkg.getPackageName(),
pkg.getComponent()) pkg.getComponent())
if options.retry and not can_retry: if options.retry and not can_retry:
print >> sys.stderr, ("You don't have the permissions to retry the " print(("You don't have the permissions to retry the build of "
"build of '%s'. Ignoring your request." "'%s'. Ignoring your request.")
% pkg.getPackageName()) % pkg.getPackageName(), file=sys.stderr)
print "The source version for '%s' in '%s' (%s) is: %s" % ( print("The source version for '%s' in '%s' (%s) is: %s"
pkg.getPackageName(), release, pocket, pkg.getVersion()) % (pkg.getPackageName(), release, pocket, pkg.getVersion()))
print pkg.getBuildStates(archs) print(pkg.getBuildStates(archs))
if can_retry: if can_retry:
print pkg.retryBuilds(archs) print(pkg.retryBuilds(archs))
if options.priority and can_rescore: if options.priority and can_rescore:
print pkg.rescoreBuilds(archs, options.priority) print(pkg.rescoreBuilds(archs, options.priority))
print '' print()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# ubuntuiso - tool to examine Ubuntu CD (ISO) installation media # ubuntuiso - tool to examine Ubuntu CD (ISO) installation media
# Copyright (C) 2008 Canonical Ltd. # Copyright (C) 2008 Canonical Ltd.
@ -21,15 +21,14 @@
# ################################################################## # ##################################################################
import optparse import optparse
import subprocess
import sys import sys
from ubuntutools import subprocess
def extract(iso, path): def extract(iso, path):
command = ['isoinfo', '-R', '-i', iso, '-x', path] command = ['isoinfo', '-R', '-i', iso, '-x', path]
pipe = subprocess.Popen(command, stdout=subprocess.PIPE, pipe = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE, encoding='utf-8')
stdout, stderr = pipe.communicate() stdout, stderr = pipe.communicate()
if pipe.returncode != 0: if pipe.returncode != 0:
@ -55,11 +54,12 @@ def main():
version = extract(iso, '/.disk/info') version = extract(iso, '/.disk/info')
if len(version) == 0: if len(version) == 0:
print >> sys.stderr, '%s does not appear to be an Ubuntu ISO' % iso print('%s does not appear to be an Ubuntu ISO' % iso,
file=sys.stderr)
err = True err = True
continue continue
print prefix + version print(prefix + version)
if err: if err:
sys.exit(1) sys.exit(1)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
# #
@ -62,13 +62,13 @@ def main():
try: try:
release, pocket = split_release_pocket(options.release) release, pocket = split_release_pocket(options.release)
series = ubuntu.getSeries(release) series = ubuntu.getSeries(release)
except SeriesNotFoundException, e: except SeriesNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(2) sys.exit(2)
try: try:
spph = archive.getSourcePackage(package) spph = archive.getSourcePackage(package)
except PackageNotFoundException, e: except PackageNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(2) sys.exit(2)
component = spph.getComponent() component = spph.getComponent()
@ -77,44 +77,46 @@ def main():
component_uploader = archive.getUploadersForComponent( component_uploader = archive.getUploadersForComponent(
component_name=component)[0] component_name=component)[0]
print "All upload permissions for %s:" % package print("All upload permissions for %s:" % package)
print print()
print "Component (%s)" % component print("Component (%s)" % component)
print "============" + ("=" * len(component)) print("============" + ("=" * len(component)))
print_uploaders([component_uploader], options.list_team_members) print_uploaders([component_uploader], options.list_team_members)
packagesets = sorted(Packageset.setsIncludingSource( packagesets = sorted(Packageset.setsIncludingSource(
distroseries=series, distroseries=series,
sourcepackagename=package)) sourcepackagename=package))
if packagesets: if packagesets:
print print()
print "Packagesets" print("Packagesets")
print "===========" print("===========")
for packageset in packagesets: for packageset in packagesets:
print print()
print "%s:" % packageset.name print("%s:" % packageset.name)
print_uploaders(archive.getUploadersForPackageset( print_uploaders(archive.getUploadersForPackageset(
packageset=packageset), options.list_team_members) packageset=packageset), options.list_team_members)
ppu_uploaders = archive.getUploadersForPackage( ppu_uploaders = archive.getUploadersForPackage(
source_package_name=package) source_package_name=package)
if ppu_uploaders: if ppu_uploaders:
print print()
print "Per-Package-Uploaders" print("Per-Package-Uploaders")
print "=====================" print("=====================")
print print()
print_uploaders(ppu_uploaders, options.list_team_members) print_uploaders(ppu_uploaders, options.list_team_members)
print print()
if PersonTeam.me.canUploadPackage(archive, series, package, component, if PersonTeam.me.canUploadPackage(archive, series, package, component,
pocket): pocket):
print "You can upload %s to %s." % (package, options.release) print("You can upload %s to %s." % (package, options.release))
else: else:
print("You can not upload %s to %s, yourself." % (package, options.release)) print("You can not upload %s to %s, yourself."
% (package, options.release))
if (series.status in ('Current Stable Release', 'Supported', 'Obsolete') if (series.status in ('Current Stable Release', 'Supported', 'Obsolete')
and pocket == 'Release'): and pocket == 'Release'):
print("%s is in the '%s' state. You may want to query the %s-proposed pocket." % print(("%s is in the '%s' state. You may want to query the "
(release, series.status, release)) "%s-proposed pocket.")
% (release, series.status, release))
else: else:
print("But you can still contribute to it via the sponsorship " print("But you can still contribute to it via the sponsorship "
"process: https://wiki.ubuntu.com/SponsorshipProcess") "process: https://wiki.ubuntu.com/SponsorshipProcess")
@ -131,9 +133,9 @@ def print_uploaders(uploaders, expand_teams=False, prefix=''):
recursion. recursion.
""" """
for uploader in sorted(uploaders, key=lambda p: p.display_name): for uploader in sorted(uploaders, key=lambda p: p.display_name):
print("%s* %s (%s)%s" % print(("%s* %s (%s)%s" %
(prefix, uploader.display_name, uploader.name, (prefix, uploader.display_name, uploader.name,
' [team]' if uploader.is_team else '')) ' [team]' if uploader.is_team else '')))
if expand_teams and uploader.is_team: if expand_teams and uploader.is_team:
print_uploaders(uploader.participants, True, prefix=prefix + ' ') print_uploaders(uploader.participants, True, prefix=prefix + ' ')

View File

@ -27,19 +27,15 @@ Approach:
3. Verify checksums. 3. Verify checksums.
""" """
from __future__ import with_statement, print_function from urllib.error import URLError, HTTPError
from urllib.parse import urlparse
from urllib.request import ProxyHandler, build_opener, urlopen
import codecs import codecs
import hashlib import hashlib
import json
import os.path import os.path
try:
from urllib.request import ProxyHandler, build_opener, urlopen
from urllib.parse import urlparse
from urllib.error import URLError, HTTPError
except ImportError:
from urllib2 import ProxyHandler, build_opener, urlopen, URLError, HTTPError
from urlparse import urlparse
import re import re
import subprocess
import sys import sys
from debian.changelog import Changelog from debian.changelog import Changelog
@ -51,11 +47,6 @@ from ubuntutools.lp.lpapicache import (Launchpad, Distribution,
SourcePackagePublishingHistory) SourcePackagePublishingHistory)
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.version import Version from ubuntutools.version import Version
from ubuntutools import subprocess
if sys.version_info[0] >= 3:
basestring = str
unicode = str
class DownloadError(Exception): class DownloadError(Exception):
@ -493,15 +484,6 @@ class DebianSourcePackage(SourcePackage):
def snapshot_list(self): def snapshot_list(self):
"Return a filename -> hash dictionary from snapshot.debian.org" "Return a filename -> hash dictionary from snapshot.debian.org"
if self._snapshot_list is None: if self._snapshot_list is None:
try:
import json
except ImportError:
import simplejson as json
except ImportError:
Logger.error("Please install python-simplejson.")
raise DownloadError("Unable to dowload from "
"snapshot.debian.org without "
"python-simplejson")
try: try:
data = self.url_opener.open( data = self.url_opener.open(
@ -598,15 +580,15 @@ class FakeSPPH(object):
if since_version is None: if since_version is None:
return self._changelog return self._changelog
if isinstance(since_version, basestring): if isinstance(since_version, str):
since_version = Version(since_version) since_version = Version(since_version)
new_entries = [] new_entries = []
for block in Changelog(self._changelog): for block in Changelog(self._changelog):
if block.version <= since_version: if block.version <= since_version:
break break
new_entries.append(unicode(block)) new_entries.append(str(block))
return u''.join(new_entries) return ''.join(new_entries)
def rmadison(url, package, suite=None, arch=None): def rmadison(url, package, suite=None, arch=None):
@ -617,8 +599,8 @@ def rmadison(url, package, suite=None, arch=None):
if arch: if arch:
cmd += ['-a', arch] cmd += ['-a', arch]
cmd.append(package) cmd.append(package)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, process = subprocess.Popen(
stderr=subprocess.PIPE, close_fds=True) cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
output, error_output = process.communicate() output, error_output = process.communicate()
if process.wait() != 0: if process.wait() != 0:
if error_output: if error_output:
@ -633,7 +615,7 @@ def rmadison(url, package, suite=None, arch=None):
# pylint bug: http://www.logilab.org/ticket/46273 # pylint bug: http://www.logilab.org/ticket/46273
# pylint: disable=E1103 # pylint: disable=E1103
for line in output.decode().strip().splitlines(): for line in output.strip().splitlines():
# pylint: enable=E1103 # pylint: enable=E1103
pkg, ver, dist, archs = [x.strip() for x in line.split('|')] pkg, ver, dist, archs = [x.strip() for x in line.split('|')]
comp = 'main' comp = 'main'

View File

@ -19,9 +19,9 @@
# #
import os import os
import subprocess
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools import subprocess
def _build_preparation(result_directory): def _build_preparation(result_directory):
@ -34,8 +34,8 @@ class Builder(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"] cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) self.architecture = subprocess.check_output(
self.architecture = process.communicate()[0].strip() cmd, encoding='utf-8').strip()
def _build_failure(self, returncode, dsc_file): def _build_failure(self, returncode, dsc_file):
if returncode != 0: if returncode != 0:
@ -124,7 +124,8 @@ class Sbuild(Builder):
def update(self, dist): def update(self, dist):
cmd = ["schroot", "--list"] cmd = ["schroot", "--list"]
Logger.command(cmd) Logger.command(cmd)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, encoding='utf-8')
chroots, _ = process.communicate()[0].strip().split() chroots, _ = process.communicate()[0].strip().split()
if process.returncode != 0: if process.returncode != 0:
return process.returncode return process.returncode

View File

@ -18,12 +18,7 @@
# the GNU General Public License license. # the GNU General Public License license.
# #
# Modules. from urllib.parse import urlsplit, urlencode, urlunsplit
try:
from urllib.parse import urlsplit, urlencode, urlunsplit
except ImportError:
from urllib import urlencode
from urlparse import urlsplit, urlunsplit
def query_to_dict(query_string): def query_to_dict(query_string):

View File

@ -21,8 +21,6 @@
# #
# Based on code written by Jonathan Davies <jpds@ubuntu.com> # Based on code written by Jonathan Davies <jpds@ubuntu.com>
from __future__ import print_function
# Uncomment for tracing LP API calls # Uncomment for tracing LP API calls
# import httplib2 # import httplib2
# httplib2.debuglevel = 1 # httplib2.debuglevel = 1
@ -45,27 +43,6 @@ from ubuntutools.lp.udtexceptions import (AlreadyLoggedInError,
PocketDoesNotExistError, PocketDoesNotExistError,
SeriesNotFoundException) SeriesNotFoundException)
if sys.version_info[0] >= 3:
basestring = str
unicode = str
# Shameless steal from python-six
def add_metaclass(metaclass):
"""Class decorator for creating a class with a metaclass."""
def wrapper(cls):
orig_vars = cls.__dict__.copy()
slots = orig_vars.get('__slots__')
if slots is not None:
if isinstance(slots, str):
slots = [slots]
for slots_var in slots:
orig_vars.pop(slots_var)
orig_vars.pop('__dict__', None)
orig_vars.pop('__weakref__', None)
return metaclass(cls.__name__, cls.__bases__, orig_vars)
return wrapper
__all__ = [ __all__ = [
'Archive', 'Archive',
@ -141,15 +118,14 @@ class MetaWrapper(type):
cls._cache = dict() cls._cache = dict()
@add_metaclass(MetaWrapper) class BaseWrapper(object, metaclass=MetaWrapper):
class BaseWrapper(object):
''' '''
A base class from which other wrapper classes are derived. A base class from which other wrapper classes are derived.
''' '''
resource_type = None # it's a base class after all resource_type = None # it's a base class after all
def __new__(cls, data): def __new__(cls, data):
if isinstance(data, basestring) and data.startswith(str(Launchpad._root_uri)): if isinstance(data, str) and data.startswith(str(Launchpad._root_uri)):
# looks like a LP API URL # looks like a LP API URL
# check if it's already cached # check if it's already cached
cached = cls._cache.get(data) cached = cls._cache.get(data)
@ -226,7 +202,7 @@ class Distribution(BaseWrapper):
''' '''
Fetch the distribution object identified by 'dist' from LP. Fetch the distribution object identified by 'dist' from LP.
''' '''
if not isinstance(dist, basestring): if not isinstance(dist, str):
raise TypeError("Don't know what do with '%r'" % dist) raise TypeError("Don't know what do with '%r'" % dist)
cached = cls._cache.get(dist) cached = cls._cache.get(dist)
if not cached: if not cached:
@ -386,7 +362,7 @@ class Archive(BaseWrapper):
''' '''
if pocket is None: if pocket is None:
pockets = frozenset(('Proposed', 'Updates', 'Security', 'Release')) pockets = frozenset(('Proposed', 'Updates', 'Security', 'Release'))
elif isinstance(pocket, basestring): elif isinstance(pocket, str):
pockets = frozenset((pocket,)) pockets = frozenset((pocket,))
else: else:
pockets = frozenset(pocket) pockets = frozenset(pocket)
@ -594,15 +570,15 @@ class SourcePackagePublishingHistory(BaseWrapper):
if since_version is None: if since_version is None:
return self._changelog return self._changelog
if isinstance(since_version, basestring): if isinstance(since_version, str):
since_version = Version(since_version) since_version = Version(since_version)
new_entries = [] new_entries = []
for block in Changelog(self._changelog): for block in Changelog(self._changelog):
if block.version <= since_version: if block.version <= since_version:
break break
new_entries.append(unicode(block)) new_entries.append(str(block))
return u''.join(new_entries) return ''.join(new_entries)
def getBinaries(self): def getBinaries(self):
''' '''
@ -720,8 +696,7 @@ class MetaPersonTeam(MetaWrapper):
return cls._me return cls._me
@add_metaclass(MetaPersonTeam) class PersonTeam(BaseWrapper, metaclass=MetaPersonTeam):
class PersonTeam(BaseWrapper):
''' '''
Wrapper class around a LP person or team object. Wrapper class around a LP person or team object.
''' '''
@ -744,7 +719,7 @@ class PersonTeam(BaseWrapper):
''' '''
Fetch the person or team object identified by 'url' from LP. Fetch the person or team object identified by 'url' from LP.
''' '''
if not isinstance(person_or_team, basestring): if not isinstance(person_or_team, str):
raise TypeError("Don't know what do with '%r'" % person_or_team) raise TypeError("Don't know what do with '%r'" % person_or_team)
cached = cls._cache.get(person_or_team) cached = cls._cache.get(person_or_team)
if not cached: if not cached:
@ -772,9 +747,9 @@ class PersonTeam(BaseWrapper):
raise TypeError("'%r' is not an Archive object." % archive) raise TypeError("'%r' is not an Archive object." % archive)
if not isinstance(distroseries, DistroSeries): if not isinstance(distroseries, DistroSeries):
raise TypeError("'%r' is not a DistroSeries object." % distroseries) raise TypeError("'%r' is not a DistroSeries object." % distroseries)
if package is not None and not isinstance(package, basestring): if package is not None and not isinstance(package, str):
raise TypeError('A source package name expected.') raise TypeError('A source package name expected.')
if component is not None and not isinstance(component, basestring): if component is not None and not isinstance(component, str):
raise TypeError('A component name expected.') raise TypeError('A component name expected.')
if package is None and component is None: if package is None and component is None:
raise ValueError('Either a source package name or a component has ' raise ValueError('Either a source package name or a component has '

View File

@ -22,9 +22,8 @@
# #
# ################################################################## # ##################################################################
from __future__ import print_function
# Modules. # Modules.
from subprocess import Popen, PIPE
import locale import locale
import os import os
import sys import sys
@ -32,7 +31,6 @@ import sys
import distro_info import distro_info
from ubuntutools.lp.udtexceptions import PocketDoesNotExistError from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
from ubuntutools.subprocess import Popen, PIPE
_system_distribution_chain = [] _system_distribution_chain = []
@ -50,7 +48,7 @@ def system_distribution_chain():
if len(_system_distribution_chain) == 0: if len(_system_distribution_chain) == 0:
try: try:
p = Popen(('dpkg-vendor', '--query', 'Vendor'), p = Popen(('dpkg-vendor', '--query', 'Vendor'),
stdout=PIPE) stdout=PIPE, encoding='utf-8')
_system_distribution_chain.append(p.communicate()[0].strip()) _system_distribution_chain.append(p.communicate()[0].strip())
except OSError: except OSError:
print('Error: Could not determine what distribution you are running.') print('Error: Could not determine what distribution you are running.')
@ -61,7 +59,7 @@ def system_distribution_chain():
p = Popen(('dpkg-vendor', p = Popen(('dpkg-vendor',
'--vendor', _system_distribution_chain[-1], '--vendor', _system_distribution_chain[-1],
'--query', 'Parent'), '--query', 'Parent'),
stdout=PIPE) stdout=PIPE, encoding='utf-8')
parent = p.communicate()[0].strip() parent = p.communicate()[0].strip()
# Don't check return code, because if a vendor has no # Don't check return code, because if a vendor has no
# parent, dpkg-vendor returns 1 # parent, dpkg-vendor returns 1

View File

@ -16,18 +16,12 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import tempfile import tempfile
import os import os
import re import re
import subprocess
import sys import sys
import ubuntutools.subprocess
if sys.version_info[0] < 3:
input = raw_input # noqa, pylint: disable=undefined-variable
class Question(object): class Question(object):
def __init__(self, options, show_help=True): def __init__(self, options, show_help=True):
@ -133,7 +127,7 @@ class EditFile(object):
def edit(self, optional=False): def edit(self, optional=False):
if optional: if optional:
print("\n\nCurrently the %s looks like:" % self.description) print("\n\nCurrently the %s looks like:" % self.description)
with open(self.filename, 'r') as f: with open(self.filename, 'r', encoding='utf-8') as f:
print(f.read()) print(f.read())
if YesNoQuestion().ask("Edit", "no") == "no": if YesNoQuestion().ask("Edit", "no") == "no":
return return
@ -141,12 +135,11 @@ class EditFile(object):
done = False done = False
while not done: while not done:
old_mtime = os.stat(self.filename).st_mtime old_mtime = os.stat(self.filename).st_mtime
ubuntutools.subprocess.check_call(['sensible-editor', subprocess.check_call(['sensible-editor', self.filename])
self.filename])
modified = old_mtime != os.stat(self.filename).st_mtime modified = old_mtime != os.stat(self.filename).st_mtime
placeholders_present = False placeholders_present = False
if self.placeholders: if self.placeholders:
with open(self.filename, 'r') as f: with open(self.filename, 'r', encoding='utf-8') as f:
for line in f: for line in f:
for placeholder in self.placeholders: for placeholder in self.placeholders:
if placeholder.search(line.strip()): if placeholder.search(line.strip()):
@ -188,8 +181,8 @@ class EditBugReport(EditFile):
placeholders) placeholders)
def check_edit(self): def check_edit(self):
with open(self.filename, 'r') as f: with open(self.filename, 'r', encoding='utf-8') as f:
report = f.read().decode('utf-8') report = f.read()
if self.split_re.match(report) is None: if self.split_re.match(report) is None:
print("The %s doesn't start with 'Summary:' and 'Description:' " print("The %s doesn't start with 'Summary:' and 'Description:' "
@ -199,8 +192,8 @@ class EditBugReport(EditFile):
return True return True
def get_report(self): def get_report(self):
with open(self.filename, 'r') as f: with open(self.filename, 'r', encoding='utf-8') as f:
report = f.read().decode('utf-8') report = f.read()
match = self.split_re.match(report) match = self.split_re.match(report)
title = match.group(1).replace(u'\n', u' ') title = match.group(1).replace(u'\n', u' ')

View File

@ -20,8 +20,6 @@
# Please see the /usr/share/common-licenses/GPL-2 file for the full text # Please see the /usr/share/common-licenses/GPL-2 file for the full text
# of the GNU General Public License license. # of the GNU General Public License license.
from __future__ import print_function
import re import re
from debian.deb822 import Changes from debian.deb822 import Changes

View File

@ -20,13 +20,12 @@
# Please see the /usr/share/common-licenses/GPL-2 file for the full text # Please see the /usr/share/common-licenses/GPL-2 file for the full text
# of the GNU General Public License license. # of the GNU General Public License license.
from __future__ import print_function
import os import os
import re import re
import sys import sys
import smtplib import smtplib
import socket import socket
import subprocess
import tempfile import tempfile
from debian.changelog import Changelog from debian.changelog import Changelog
@ -37,11 +36,6 @@ from ubuntutools.lp.udtexceptions import PackageNotFoundException
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.question import confirmation_prompt, YesNoQuestion from ubuntutools.question import confirmation_prompt, YesNoQuestion
from ubuntutools.version import Version from ubuntutools.version import Version
from ubuntutools import subprocess
if sys.version_info[0] >= 3:
basestring = str
unicode = str
__all__ = [ __all__ = [
@ -111,17 +105,17 @@ def get_ubuntu_delta_changelog(srcpkg):
''' '''
changelog = Changelog(srcpkg.getChangelog()) changelog = Changelog(srcpkg.getChangelog())
if changelog is None: if changelog is None:
return u'' return ''
delta = [] delta = []
debian_info = DebianDistroInfo() debian_info = DebianDistroInfo()
for block in changelog: for block in changelog:
distribution = block.distributions.split()[0].split('-')[0] distribution = block.distributions.split()[0].split('-')[0]
if debian_info.valid(distribution): if debian_info.valid(distribution):
break break
delta += [unicode(change) for change in block.changes() delta += [str(change) for change in block.changes()
if change.strip()] if change.strip()]
return u'\n'.join(delta) return '\n'.join(delta)
def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain,
@ -162,15 +156,16 @@ def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain,
gpg_command.extend(('-u', keyid)) gpg_command.extend(('-u', keyid))
# sign the mail body # sign the mail body
gpg = subprocess.Popen(gpg_command, stdin=subprocess.PIPE, gpg = subprocess.Popen(
stdout=subprocess.PIPE) gpg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
signed_report = gpg.communicate(mailbody.encode('utf-8'))[0].decode('utf-8') encoding='utf-8')
signed_report = gpg.communicate(mailbody)[0]
if gpg.returncode != 0: if gpg.returncode != 0:
Logger.error("%s failed.", gpg_command[0]) Logger.error("%s failed.", gpg_command[0])
sys.exit(1) sys.exit(1)
# generate email # generate email
mail = u'''\ mail = '''\
From: %s From: %s
To: %s To: %s
Subject: %s Subject: %s

View File

@ -17,11 +17,8 @@
import os import os
import re import re
try: from urllib.parse import unquote
from urllib.parse import unquote from urllib.request import urlretrieve
from urllib.request import urlretrieve
except ImportError:
from urllib import unquote, urlretrieve
import distro_info import distro_info
import httplib2 import httplib2

View File

@ -17,8 +17,8 @@
import os import os
import re import re
import subprocess
from ubuntutools import subprocess
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.sponsor_patch.question import ask_for_manual_fixing from ubuntutools.sponsor_patch.question import ask_for_manual_fixing
from functools import reduce from functools import reduce
@ -71,8 +71,7 @@ class Patch(object):
patch_f.close() patch_f.close()
cmd = ["diffstat", "-l", "-p0", self._full_path] cmd = ["diffstat", "-l", "-p0", self._full_path]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) changed_files = subprocess.check_output(cmd, encoding='utf-8')
changed_files = process.communicate()[0]
self._changed_files = [f for f in changed_files.split("\n") if f != ""] self._changed_files = [f for f in changed_files.split("\n") if f != ""]
def get_strip_level(self): def get_strip_level(self):

View File

@ -15,8 +15,6 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys import sys
from ubuntutools.question import Question, YesNoQuestion from ubuntutools.question import Question, YesNoQuestion

View File

@ -15,16 +15,14 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import os import os
import re import re
import subprocess
import sys import sys
import debian.changelog import debian.changelog
import debian.deb822 import debian.deb822
from ubuntutools import subprocess
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.question import Question, YesNoQuestion from ubuntutools.question import Question, YesNoQuestion
@ -327,8 +325,7 @@ class SourcePackage(object):
if not Logger.verbose: if not Logger.verbose:
cmd.insert(1, "-q") cmd.insert(1, "-q")
Logger.command(cmd + [">", self._debdiff_filename]) Logger.command(cmd + [">", self._debdiff_filename])
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) debdiff = subprocess.check_output(cmd, encoding='utf-8')
debdiff = process.communicate()[0]
# write debdiff file # write debdiff file
debdiff_file = open(self._debdiff_filename, "w") debdiff_file = open(self._debdiff_filename, "w")
@ -421,8 +418,7 @@ class SourcePackage(object):
self._package + "_" + self._package + "_" +
strip_epoch(self._version) + ".lintian") strip_epoch(self._version) + ".lintian")
Logger.command(cmd + [">", lintian_filename]) Logger.command(cmd + [">", lintian_filename])
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) report = subprocess.check_output(cmd, encoding='utf-8')
report = process.communicate()[0]
# write lintian report file # write lintian report file
lintian_file = open(lintian_filename, "w") lintian_file = open(lintian_filename, "w")

View File

@ -15,18 +15,16 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import os import os
import pwd import pwd
import shutil import shutil
import subprocess
import sys import sys
from distro_info import UbuntuDistroInfo from distro_info import UbuntuDistroInfo
from launchpadlib.launchpad import Launchpad from launchpadlib.launchpad import Launchpad
from ubuntutools import subprocess
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.update_maintainer import (update_maintainer, from ubuntutools.update_maintainer import (update_maintainer,
MaintainerUpdateException) MaintainerUpdateException)
@ -37,9 +35,6 @@ from ubuntutools.sponsor_patch.patch import Patch
from ubuntutools.sponsor_patch.question import ask_for_manual_fixing from ubuntutools.sponsor_patch.question import ask_for_manual_fixing
from ubuntutools.sponsor_patch.source_package import SourcePackage from ubuntutools.sponsor_patch.source_package import SourcePackage
if sys.version_info[0] < 3:
range = xrange # noqa, pylint: disable=redefined-builtin,undefined-variable
def is_command_available(command, check_sbin=False): def is_command_available(command, check_sbin=False):
"Is command in $PATH?" "Is command in $PATH?"

View File

@ -1,116 +0,0 @@
"""Drop-in replacement for subprocess with better defaults
This is an API-compatible replacement for the built-in subprocess
module whose defaults better line up with our tastes.
In particular, it:
- Adds support for the restore_signals flag if subprocess itself
doesn't support it
- Defaults close_fds to True
"""
from __future__ import absolute_import
import inspect
import signal
import subprocess
import sys
from subprocess import PIPE, STDOUT, CalledProcessError
__all__ = ['Popen', 'call', 'check_call', 'check_output', 'CalledProcessError',
'PIPE', 'STDOUT']
class Popen(subprocess.Popen):
def __init__(self, *args, **kwargs):
kwargs.setdefault('close_fds', True)
if sys.version_info[0] >= 3:
getargs = inspect.getfullargspec
else:
getargs = inspect.getargspec
if 'restore_signals' not in getargs(subprocess.Popen.__init__)[0]:
given_preexec_fn = kwargs.pop('preexec_fn', None)
restore_signals = kwargs.pop('restore_signals', True)
def preexec_fn():
if restore_signals:
for sig in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
if hasattr(signal, sig):
signal.signal(getattr(signal, sig),
signal.SIG_DFL)
if given_preexec_fn:
given_preexec_fn()
kwargs['preexec_fn'] = preexec_fn
subprocess.Popen.__init__(self, *args, **kwargs)
# call, check_call, and check_output are copied directly from the
# subprocess module shipped with Python 2.7.1-5ubuntu2
def call(*popenargs, **kwargs):
"""Run command with arguments. Wait for command to complete, then
return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
"""
return Popen(*popenargs, **kwargs).wait()
def check_call(*popenargs, **kwargs):
"""Run command with arguments. Wait for command to complete. If
the exit code was zero then return, otherwise raise
CalledProcessError. The CalledProcessError object will have the
return code in the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
check_call(["ls", "-l"])
"""
retcode = call(*popenargs, **kwargs)
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise CalledProcessError(retcode, cmd)
return 0
def check_output(*popenargs, **kwargs):
r"""Run command with arguments and return its output as a byte string.
If the exit code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
attribute and output in the output attribute.
The arguments are the same as for the Popen constructor. Example:
>>> check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
The stdout argument is not allowed as it is used internally.
To capture standard error in the result, use stderr=STDOUT.
>>> check_output(["/bin/sh", "-c",
... "ls -l non_existent_file ; exit 0"],
... stderr=STDOUT)
'ls: non_existent_file: No such file or directory\n'
"""
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = Popen(stdout=PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise CalledProcessError(retcode, cmd, output=output)
return output

View File

@ -21,10 +21,7 @@ import sys
import setup import setup
if sys.version_info < (2, 7): import unittest
import unittest2 as unittest
else:
import unittest
def discover(): def discover():
@ -49,8 +46,7 @@ def get_source_files():
if is_script: if is_script:
with open(code_file, "rb") as script_file: with open(code_file, "rb") as script_file:
shebang = script_file.readline().decode("utf-8") shebang = script_file.readline().decode("utf-8")
if ((sys.version_info[0] == 3 and "python3" in shebang) if "python3" in shebang:
or ("python" in shebang and "python3" not in shebang)):
files.append(code_file) files.append(code_file)
else: else:
files.append(code_file) files.append(code_file)

View File

@ -15,21 +15,16 @@
# PERFORMANCE OF THIS SOFTWARE. # PERFORMANCE OF THIS SOFTWARE.
import mock
import os.path import os.path
import shutil import shutil
import sys
import tempfile import tempfile
from io import BytesIO from io import BytesIO
try: from urllib.error import HTTPError, URLError
from urllib.request import OpenerDirector, urlopen from urllib.request import OpenerDirector, urlopen
from urllib.error import HTTPError, URLError
except ImportError:
from urllib2 import OpenerDirector, urlopen
from urllib2 import HTTPError, URLError
import httplib2
import mock
import debian.deb822 import debian.deb822
import httplib2
import ubuntutools.archive import ubuntutools.archive
from ubuntutools.test import unittest from ubuntutools.test import unittest
@ -64,18 +59,11 @@ class DscVerificationTestCase(unittest.TestCase):
fn = 'test-data/example_1.0.orig.tar.gz' fn = 'test-data/example_1.0.orig.tar.gz'
with open(fn, 'rb') as f: with open(fn, 'rb') as f:
data = f.read() data = f.read()
if sys.version_info[0] >= 3: last_byte = chr(data[-1] ^ 8).encode()
last_byte = chr(data[-1] ^ 8).encode()
else:
last_byte = chr(ord(data[-1]) ^ 8)
data = data[:-1] + last_byte data = data[:-1] + last_byte
m = mock.MagicMock(name='open', spec=open) m = mock.MagicMock(name='open', spec=open)
m.return_value = BytesIO(data) m.return_value = BytesIO(data)
if sys.version_info[0] >= 3: with mock.patch('builtins.open', m):
target = 'builtins.open'
else:
target = '__builtin__.open'
with mock.patch(target, m):
self.assertFalse(self.dsc.verify_file(fn)) self.assertFalse(self.dsc.verify_file(fn))
def test_sha1(self): def test_sha1(self):

View File

@ -15,15 +15,11 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE. # PERFORMANCE OF THIS SOFTWARE.
import locale
import mock
import os import os
import sys import sys
import locale from io import StringIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import mock
from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
@ -49,15 +45,9 @@ class ConfigTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
super(ConfigTestCase, self).setUp() super(ConfigTestCase, self).setUp()
if sys.version_info[0] < 3:
self.assertRegex = self.assertRegexpMatches
m = mock.mock_open() m = mock.mock_open()
m.side_effect = self._fake_open m.side_effect = self._fake_open
if sys.version_info[0] >= 3: patcher = mock.patch('builtins.open', m)
target = 'builtins.open'
else:
target = '__builtin__.open'
patcher = mock.patch(target, m)
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
patcher.start() patcher.start()

View File

@ -33,17 +33,18 @@ class Flake8TestCase(unittest.TestCase):
cmd = [sys.executable, "-m", "flake8", "--max-line-length=99"] + get_source_files() cmd = [sys.executable, "-m", "flake8", "--max-line-length=99"] + get_source_files()
if unittest_verbosity() >= 2: if unittest_verbosity() >= 2:
sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd)))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, process = subprocess.Popen(
stderr=subprocess.PIPE, close_fds=True) cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf-8')
out, err = process.communicate() out, err = process.communicate()
if process.returncode != 0: # pragma: no cover if process.returncode != 0: # pragma: no cover
msgs = [] msgs = []
if err: if err:
msgs.append("flake8 exited with code {} and has unexpected output on stderr:\n{}" msgs.append("flake8 exited with code {} and has unexpected output on stderr:\n{}"
.format(process.returncode, err.decode().rstrip())) .format(process.returncode, err.rstrip()))
if out: if out:
msgs.append("flake8 found issues:\n{}".format(out.decode().rstrip())) msgs.append("flake8 found issues:\n{}".format(out.rstrip()))
if not msgs: if not msgs:
msgs.append("flake8 exited with code {} and has no output on stdout or stderr." msgs.append("flake8 exited with code {} and has no output on stdout or stderr."
.format(process.returncode)) .format(process.returncode))

View File

@ -18,10 +18,10 @@ import fcntl
import os import os
import select import select
import signal import signal
import subprocess
import time import time
import setup import setup
from ubuntutools import subprocess
from ubuntutools.test import unittest from ubuntutools.test import unittest
TIMEOUT = 10 TIMEOUT = 10
@ -46,7 +46,7 @@ class HelpTestCase(unittest.TestCase):
def tester(self): def tester(self):
null = open('/dev/null', 'r') null = open('/dev/null', 'r')
process = subprocess.Popen(['./' + script, '--help'], process = subprocess.Popen(['./' + script, '--help'],
close_fds=True, stdin=null, encoding='utf-8', stdin=null,
universal_newlines=True, universal_newlines=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
@ -73,6 +73,8 @@ class HelpTestCase(unittest.TestCase):
if process.poll() is None: if process.poll() is None:
os.kill(process.pid, signal.SIGKILL) os.kill(process.pid, signal.SIGKILL)
null.close() null.close()
process.stdout.close()
process.stderr.close()
self.assertEqual(process.poll(), 0, self.assertEqual(process.poll(), 0,
"%s failed to return usage within %i seconds.\n" "%s failed to return usage within %i seconds.\n"

View File

@ -14,10 +14,7 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE. # PERFORMANCE OF THIS SOFTWARE.
try: from io import StringIO
from StringIO import StringIO
except ImportError:
from io import StringIO
import sys import sys
from ubuntutools.logger import Logger from ubuntutools.logger import Logger

View File

@ -17,10 +17,10 @@
import os import os
import re import re
import subprocess
import sys import sys
from ubuntutools.test import get_source_files, unittest, unittest_verbosity from ubuntutools.test import get_source_files, unittest, unittest_verbosity
from ubuntutools import subprocess
CONFIG = os.path.join(os.path.dirname(__file__), "pylint.conf") CONFIG = os.path.join(os.path.dirname(__file__), "pylint.conf")
@ -40,8 +40,9 @@ class PylintTestCase(unittest.TestCase):
"-E", "--"] + get_source_files() "-E", "--"] + get_source_files()
if unittest_verbosity() >= 2: if unittest_verbosity() >= 2:
sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd))) sys.stderr.write("Running following command:\n{}\n".format(" ".join(cmd)))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, process = subprocess.Popen(
close_fds=True) cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf-8')
out, err = process.communicate() out, err = process.communicate()
if process.returncode != 0: # pragma: no cover if process.returncode != 0: # pragma: no cover
@ -50,11 +51,11 @@ class PylintTestCase(unittest.TestCase):
# ------------------------------------ # ------------------------------------
# Your code has been rated at 10.00/10 # Your code has been rated at 10.00/10
# #
out = re.sub("^(-+|Your code has been rated at .*)$", "", out.decode(), out = re.sub("^(-+|Your code has been rated at .*)$", "", out,
flags=re.MULTILINE).rstrip() flags=re.MULTILINE).rstrip()
# Strip logging of used config file (introduced in pylint 1.8) # Strip logging of used config file (introduced in pylint 1.8)
err = re.sub("^Using config file .*\n", "", err.decode()).rstrip() err = re.sub("^Using config file .*\n", "", err).rstrip()
msgs = [] msgs = []
if err: if err:

View File

@ -16,15 +16,10 @@
"""Test suite for ubuntutools.update_maintainer""" """Test suite for ubuntutools.update_maintainer"""
try: import mock
from StringIO import StringIO
except ImportError:
from io import StringIO
import os import os
import sys import sys
from io import StringIO
import mock
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.test import unittest from ubuntutools.test import unittest
@ -231,15 +226,9 @@ class UpdateMaintainerTestCase(unittest.TestCase):
# pylint: disable=C0103 # pylint: disable=C0103
def setUp(self): def setUp(self):
if sys.version_info[0] < 3:
self.assertRegex = self.assertRegexpMatches
m = mock.mock_open() m = mock.mock_open()
m.side_effect = self._fake_open m.side_effect = self._fake_open
if sys.version_info[0] >= 3: patcher = mock.patch('builtins.open', m)
target = 'builtins.open'
else:
target = '__builtin__.open'
patcher = mock.patch(target, m)
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
patcher.start() patcher.start()
m = mock.MagicMock(side_effect=self._fake_isfile) m = mock.MagicMock(side_effect=self._fake_isfile)

View File

@ -14,8 +14,6 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
"""This module is for updating the Maintainer field of an Ubuntu package.""" """This module is for updating the Maintainer field of an Ubuntu package."""
import os import os

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2010, Benjamin Drung <bdrung@ubuntu.com> # Copyright (C) 2010, Benjamin Drung <bdrung@ubuntu.com>
# #
@ -39,8 +39,8 @@ def main():
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) != 0: if len(args) != 0:
print >> sys.stderr, ("%s: Error: Unsupported additional parameters " print("%s: Error: Unsupported additional parameters specified: %s"
"specified: %s") % (script_name, ", ".join(args)) % (script_name, ", ".join(args)), file=sys.stderr)
sys.exit(1) sys.exit(1)
if not options.restore: if not options.restore: