Verified Commit 44ec09c5 authored by Ansgar's avatar Ansgar

use `print` instead of `sys.stderr.write` or `sys.stdout.write`

parent 6c241cb0
...@@ -340,7 +340,7 @@ def check_timestamps(): ...@@ -340,7 +340,7 @@ def check_timestamps():
if os.access(filename, os.R_OK): if os.access(filename, os.R_OK):
f = utils.open_file(filename) f = utils.open_file(filename)
current_file = filename current_file = filename
sys.stderr.write("Processing %s.\n" % (filename)) print("Processing %s." % (filename), file=sys.stderr)
apt_inst.debExtract(f, Ent, "control.tar.gz") apt_inst.debExtract(f, Ent, "control.tar.gz")
f.seek(0) f.seek(0)
apt_inst.debExtract(f, Ent, "data.tar.gz") apt_inst.debExtract(f, Ent, "data.tar.gz")
......
...@@ -225,9 +225,9 @@ def export_files(session, archive, clpool, progress=False): ...@@ -225,9 +225,9 @@ def export_files(session, archive, clpool, progress=False):
stats['unpack'] += 1 stats['unpack'] += 1
if progress: if progress:
if stats['unpack'] % 100 == 0: if stats['unpack'] % 100 == 0:
sys.stderr.write('%d packages unpacked\n' % stats['unpack']) print('%d packages unpacked' % stats['unpack'], file=sys.stderr)
elif stats['unpack'] % 10 == 0: elif stats['unpack'] % 10 == 0:
sys.stderr.write('.') print('.', end='', file=sys.stderr)
for file in files: for file in files:
for f in glob(os.path.join(tempdir, 'debian', '*%s' % file)): for f in glob(os.path.join(tempdir, 'debian', '*%s' % file)):
for s in unpack[p][1]: for s in unpack[p][1]:
......
...@@ -170,7 +170,7 @@ SELECT ...@@ -170,7 +170,7 @@ SELECT
if Options["Print"]: if Options["Print"]:
for package in sorted(maintainers): for package in sorted(maintainers):
sys.stdout.write(format(package, maintainers[package])) print(format(package, maintainers[package]), end='')
else: else:
maintainer_file = open('Maintainers', 'w') maintainer_file = open('Maintainers', 'w')
uploader_file = open('Uploaders', 'w') uploader_file = open('Uploaders', 'w')
......
...@@ -123,7 +123,7 @@ def main(): ...@@ -123,7 +123,7 @@ def main():
print("Skipping %s as it is marked as untouchable" % suite.suite_name) print("Skipping %s as it is marked as untouchable" % suite.suite_name)
continue continue
sys.stderr.write("Processing %s...\n" % (suite.suite_name)) print("Processing %s..." % (suite.suite_name), file=sys.stderr)
override_suite = suite.overridecodename or suite.codename override_suite = suite.overridecodename or suite.codename
for component in session.query(Component).all(): for component in session.query(Component).all():
......
...@@ -777,7 +777,7 @@ def end(): ...@@ -777,7 +777,7 @@ def end():
sets = "set" sets = "set"
if accept_count > 1: if accept_count > 1:
sets = "sets" sets = "sets"
sys.stderr.write("Accepted %d package %s, %s.\n" % (accept_count, sets, utils.size_type(int(accept_bytes)))) print("Accepted %d package %s, %s." % (accept_count, sets, utils.size_type(int(accept_bytes))), file=sys.stderr)
Logger.log(["total", accept_count, accept_bytes]) Logger.log(["total", accept_count, accept_bytes])
if not Options["No-Action"] and not Options["Trainee"]: if not Options["No-Action"] and not Options["Trainee"]:
...@@ -832,7 +832,7 @@ def main(): ...@@ -832,7 +832,7 @@ def main():
readline.parse_and_bind("tab: complete") readline.parse_and_bind("tab: complete")
if len(uploads) > 1: if len(uploads) > 1:
sys.stderr.write("Sorting changes...\n") print("Sorting changes...", file=sys.stderr)
uploads = sort_uploads(new_queue, uploads, session, Options["No-Binaries"]) uploads = sort_uploads(new_queue, uploads, session, Options["No-Binaries"])
if Options["Comments"]: if Options["Comments"]:
......
...@@ -131,18 +131,14 @@ def open_file(filename, mode='r'): ...@@ -131,18 +131,14 @@ def open_file(filename, mode='r'):
def our_raw_input(prompt=""): def our_raw_input(prompt=""):
if prompt: if prompt:
while 1: print(prompt, end='')
try: # TODO: py3: use `print(..., flush=True)`
sys.stdout.write(prompt)
break
except IOError:
pass
sys.stdout.flush() sys.stdout.flush()
try: try:
ret = raw_input() ret = raw_input()
return ret return ret
except EOFError: except EOFError:
sys.stderr.write("\nUser interrupt (^D).\n") print("\nUser interrupt (^D).", file=sys.stderr)
raise SystemExit raise SystemExit
################################################################################ ################################################################################
...@@ -607,12 +603,12 @@ def TemplateSubst(subst_map, filename): ...@@ -607,12 +603,12 @@ def TemplateSubst(subst_map, filename):
def fubar(msg, exit_code=1): def fubar(msg, exit_code=1):
sys.stderr.write("E: %s\n" % (msg)) print("E:", msg, file=sys.stderr)
sys.exit(exit_code) sys.exit(exit_code)
def warn(msg): def warn(msg):
sys.stderr.write("W: %s\n" % (msg)) print("W:", msg, file=sys.stderr)
################################################################################ ################################################################################
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# Author: Filippo Giunchedi <filippo@debian.org> # Author: Filippo Giunchedi <filippo@debian.org>
# Version: 0.5 # Version: 0.5
from __future__ import print_function
import cgi import cgi
import os import os
import os.path import os.path
...@@ -110,7 +112,7 @@ def parse_leave_reason(fname): ...@@ -110,7 +112,7 @@ def parse_leave_reason(fname):
try: try:
f = open(fname) f = open(fname)
except IOError as e: except IOError as e:
sys.stderr.write("Can't open %s: %s\n" % (fname, e)) print("Can't open %s: %s" % (fname, e), file=sys.stderr)
return {} return {}
res = {} res = {}
...@@ -195,12 +197,12 @@ if __name__ == "__main__": ...@@ -195,12 +197,12 @@ if __name__ == "__main__":
(settings, args) = parser.parse_args() (settings, args) = parser.parse_args()
if not os.path.exists(settings.outdir): if not os.path.exists(settings.outdir):
sys.stderr.write("Outdir '%s' does not exists\n" % settings.outdir) print("Outdir '%s' does not exists" % settings.outdir, file=sys.stderr)
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
if not os.path.exists(settings.datadir): if not os.path.exists(settings.datadir):
sys.stderr.write("Datadir '%s' does not exists\n" % settings.datadir) print("Datadir '%s' does not exists" % settings.datadir, file=sys.stderr)
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
...@@ -225,7 +227,7 @@ if __name__ == "__main__": ...@@ -225,7 +227,7 @@ if __name__ == "__main__":
status.feed_in.write_xml(file(feed_in_file, "w+"), "utf-8") status.feed_in.write_xml(file(feed_in_file, "w+"), "utf-8")
status.feed_out.write_xml(file(feed_out_file, "w+"), "utf-8") status.feed_out.write_xml(file(feed_out_file, "w+"), "utf-8")
except IOError as why: except IOError as why:
sys.stderr.write("Unable to write feeds: %s\n" % why) print("Unable to write feeds:", why, file=sys.stderr)
sys.exit(1) sys.exit(1)
status.queue = current_queue status.queue = current_queue
...@@ -233,7 +235,7 @@ if __name__ == "__main__": ...@@ -233,7 +235,7 @@ if __name__ == "__main__":
try: try:
cPickle.dump(status, open(status_db, "w+")) cPickle.dump(status, open(status_db, "w+"))
except IOError as why: except IOError as why:
sys.stderr.write("Unable to save status: %s\n" % why) print("Unable to save status:", why, file=sys.stderr)
sys.exit(1) sys.exit(1)
# vim:et:ts=4 # vim:et:ts=4
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment