Bug#807104: python-apt-doc: Use of print statements not compatible with python3
Julian Andres Klode <jak@debian.org> writes:
> I'd rather prefer to use print(..., file=sys.stderr) instead of
> sys.stderr.write().
> Importing print_function from __future__ should make it
> work in both Python 2 and 3.
I attached another patch that uses the print function.
> This might need more changes though: I'm not sure if the
> pep8 test accepts this (tests/testmanual_pep8.py).
Oh, you are right. I hadn't run the test before: pep8 complained about
a line that got to long.
>> >From 331782006251adb25118cd1343c74a1765280b4f Mon Sep 17 00:00:00 2001
>
> There is an extra > in front of the first attachement line, causing
> git am to fail applying it.
Not sure were that came from; I hope it works this time.
--
Felix Dietrich
>From 2af29dfc532987e0161eb18cd43feff6d028d648 Mon Sep 17 00:00:00 2001
From: Felix Dietrich <felix.dietrich@sperrhaken.name>
Date: Sun, 6 Dec 2015 13:56:47 +0100
Subject: [PATCH] Use print function from __future__ in examples
---
doc/source/examples/cache-packages.py | 8 ++++----
doc/source/examples/cache-pkgfile.py | 16 ++++++++--------
doc/source/examples/dpkg-contents.py | 6 ++++--
doc/source/examples/dpkg-extract.py | 8 ++++++--
doc/source/examples/dpkg-info.py | 7 +++++--
doc/source/examples/missing-deps.py | 10 +++++-----
doc/source/examples/update-print-uris.py | 2 +-
doc/source/library/apt.cache.rst | 2 +-
doc/source/library/apt.package.rst | 6 +++---
doc/source/library/apt_pkg.rst | 8 ++++----
doc/source/tutorials/apt-get.rst | 2 +-
11 files changed, 42 insertions(+), 33 deletions(-)
mode change 100644 => 100755 doc/source/examples/cache-packages.py
mode change 100644 => 100755 doc/source/examples/cache-pkgfile.py
mode change 100644 => 100755 doc/source/examples/dpkg-contents.py
mode change 100644 => 100755 doc/source/examples/dpkg-extract.py
mode change 100644 => 100755 doc/source/examples/dpkg-info.py
mode change 100644 => 100755 doc/source/examples/missing-deps.py
mode change 100644 => 100755 doc/source/examples/update-print-uris.py
diff --git a/doc/source/examples/cache-packages.py b/doc/source/examples/cache-packages.py
old mode 100644
new mode 100755
index 7253430..0a4c34e
--- a/doc/source/examples/cache-packages.py
+++ b/doc/source/examples/cache-packages.py
@@ -9,14 +9,14 @@ def main():
apt_pkg.init_config()
apt_pkg.init_system()
cache = apt_pkg.Cache()
- print "Essential packages:"
+ print("Essential packages:")
for pkg in cache.packages:
if pkg.essential:
- print " ", pkg.name
- print "Important packages:"
+ print(" ", pkg.name)
+ print("Important packages:")
for pkg in cache.packages:
if pkg.important:
- print " ", pkg.name
+ print(" ", pkg.name)
if __name__ == "__main__":
main()
diff --git a/doc/source/examples/cache-pkgfile.py b/doc/source/examples/cache-pkgfile.py
old mode 100644
new mode 100755
index 10216c1..bbf9b61
--- a/doc/source/examples/cache-pkgfile.py
+++ b/doc/source/examples/cache-pkgfile.py
@@ -7,23 +7,23 @@ def main():
apt_pkg.init()
cache = apt_pkg.Cache()
for pkgfile in cache.file_list:
- print 'Package-File:', pkgfile.filename
- print 'Index-Type:', pkgfile.index_type # 'Debian Package Index'
+ print('Package-File:', pkgfile.filename)
+ print('Index-Type:', pkgfile.index_type) # 'Debian Package Index'
if pkgfile.not_source:
- print 'Source: None'
+ print('Source: None')
else:
if pkgfile.site:
# There is a source, and a site, print the site
- print 'Source:', pkgfile.site
+ print('Source:', pkgfile.site)
else:
# It seems to be a local repository
- print 'Source: Local package file'
+ print('Source: Local package file')
if pkgfile.not_automatic:
# The system won't be updated automatically (eg. experimental)
- print 'Automatic: No'
+ print('Automatic: No')
else:
- print 'Automatic: Yes'
- print
+ print('Automatic: Yes')
+ print()
if __name__ == '__main__':
main()
diff --git a/doc/source/examples/dpkg-contents.py b/doc/source/examples/dpkg-contents.py
old mode 100644
new mode 100755
index 47a50e0..1308172
--- a/doc/source/examples/dpkg-contents.py
+++ b/doc/source/examples/dpkg-contents.py
@@ -1,6 +1,8 @@
#!/usr/bin/python
"""Emulate dpkg --contents"""
+from __future__ import print_function
+
import grp
import pwd
import stat
@@ -46,13 +48,13 @@ def callback(member, data):
else ("./" + member.name))
if member.islnk():
s_name += " link to %s" % link
- print s_mode, s_owner, s_size, s_time, s_name
+ print(s_mode, s_owner, s_size, s_time, s_name)
def main():
"""Main function"""
if len(sys.argv) < 2:
- print >> sys.stderr, "need filename argumnet"
+ print("need filename argumnet", file=sys.stderr)
sys.exit(1)
fobj = open(sys.argv[1])
diff --git a/doc/source/examples/dpkg-extract.py b/doc/source/examples/dpkg-extract.py
old mode 100644
new mode 100755
index fe27634..47ef6a5
--- a/doc/source/examples/dpkg-extract.py
+++ b/doc/source/examples/dpkg-extract.py
@@ -1,5 +1,8 @@
#!/usr/bin/python
"""Emulate dpkg --extract package.deb outdir"""
+
+from __future__ import print_function
+
import os
import sys
@@ -9,10 +12,11 @@ import apt_inst
def main():
"""Main function."""
if len(sys.argv) < 3:
- print >> sys.stderr, "Usage:", __file__, "package.deb outdir"
+ print("Usage: %s package.deb outdir\n" % (__file__), file=sys.stderr)
sys.exit(1)
if not os.path.exists(sys.argv[2]):
- print >> sys.stderr, "The directory %s does not exist" % sys.argv[2]
+ print("The directory %s does not exist\n" % (sys.argv[2]),
+ file=sys.stderr)
sys.exit(1)
fobj = open(sys.argv[1])
diff --git a/doc/source/examples/dpkg-info.py b/doc/source/examples/dpkg-info.py
old mode 100644
new mode 100755
index af22059..9331605
--- a/doc/source/examples/dpkg-info.py
+++ b/doc/source/examples/dpkg-info.py
@@ -1,5 +1,8 @@
#!/usr/bin/python
"""Emulate dpkg --info package.deb control-file"""
+
+from __future__ import print_function
+
import sys
from apt_inst import DebFile
@@ -8,11 +11,11 @@ from apt_inst import DebFile
def main():
"""Main function."""
if len(sys.argv) < 3:
- print >> sys.stderr, 'Usage: tool file.deb control-file'
+ print('Usage: tool file.deb control-file\n', file=sys.stderr)
sys.exit(0)
fobj = open(sys.argv[1])
try:
- print DebFile(fobj).control.extractdata(sys.argv[2])
+ print(DebFile(fobj).control.extractdata(sys.argv[2]))
finally:
fobj.close()
diff --git a/doc/source/examples/missing-deps.py b/doc/source/examples/missing-deps.py
old mode 100644
new mode 100755
index b9ccdc1..3718e2d
--- a/doc/source/examples/missing-deps.py
+++ b/doc/source/examples/missing-deps.py
@@ -22,12 +22,12 @@ def check_version(pkgver):
missing.append(or_group)
if missing:
- print "Package:", pkgver.parent_pkg.name
- print "Version:", pkgver.ver_str
- print "Missing:",
- print ", ".join(" | ".join(fmt_dep(dep) for dep in or_group)
+ print("Package:", pkgver.parent_pkg.name)
+ print("Version:", pkgver.ver_str)
+ print("Missing:")
+ print(", ".join(" | ".join(fmt_dep(dep) for dep in or_group))
for or_group in missing)
- print
+ print()
def main():
diff --git a/doc/source/examples/update-print-uris.py b/doc/source/examples/update-print-uris.py
old mode 100644
new mode 100755
index dbe1dfd..5a7c235
--- a/doc/source/examples/update-print-uris.py
+++ b/doc/source/examples/update-print-uris.py
@@ -17,7 +17,7 @@ def main():
# Now print the URI of every item.
for item in acquire.items:
- print item.desc_uri
+ print(item.desc_uri)
if __name__ == '__main__':
main()
diff --git a/doc/source/library/apt.cache.rst b/doc/source/library/apt.cache.rst
index d0e4459..f85deb2 100644
--- a/doc/source/library/apt.cache.rst
+++ b/doc/source/library/apt.cache.rst
@@ -67,7 +67,7 @@ packages whose state has been changed, eg. packages marked for installation::
>>> cache = apt.Cache()
>>> changed = apt.FilteredCache(cache)
>>> changed.set_filter(MarkedChangesFilter())
- >>> print len(changed) == len(cache.get_changes()) # Both need to have same length
+ >>> print(len(changed) == len(cache.get_changes())) # Both need to have same length
True
The ProblemResolver class
diff --git a/doc/source/library/apt.package.rst b/doc/source/library/apt.package.rst
index 1a69c1e..ec7ed36 100644
--- a/doc/source/library/apt.package.rst
+++ b/doc/source/library/apt.package.rst
@@ -109,14 +109,14 @@ Examples
cache = apt.Cache()
pkg = cache['python-apt'] # Access the Package object for python-apt
- print 'python-apt is trusted:', pkg.candidate.origins[0].trusted
+ print('python-apt is trusted:', pkg.candidate.origins[0].trusted)
# Mark python-apt for install
pkg.mark_install()
- print 'python-apt is marked for install:', pkg.marked_install
+ print('python-apt is marked for install:', pkg.marked_install)
- print 'python-apt is (summary):', pkg.candidate.summary
+ print('python-apt is (summary):', pkg.candidate.summary)
# Now, really install it
cache.commit()
diff --git a/doc/source/library/apt_pkg.rst b/doc/source/library/apt_pkg.rst
index 3176ac5..313ca7a 100644
--- a/doc/source/library/apt_pkg.rst
+++ b/doc/source/library/apt_pkg.rst
@@ -1276,7 +1276,7 @@ Index Files
for pkgfile in cache.file_list:
if pkgfile.not_source:
- print 'The file %s has no source.' % pkgfile.filename
+ print('The file %s has no source.' % pkgfile.filename)
.. attribute:: origin
@@ -1344,7 +1344,7 @@ Records (Release files, Packages, Sources)
cand = depcache.get_candidate_ver(cache['python-apt'])
records.lookup(cand.file_list[0])
# Now you can access the record
- print records.source_pkg # == python-apt
+ print(records.source_pkg) # == python-apt
.. attribute:: filename
@@ -1429,7 +1429,7 @@ Records (Release files, Packages, Sources)
Example::
section = apt_pkg.TagSection(records.record)
- print section['SHA256'] # Use records.sha256_hash instead
+ print(section['SHA256']) # Use records.sha256_hash instead
.. class:: SourceRecords
@@ -1951,7 +1951,7 @@ section as a string.
with apt_pkg.TagFile('/var/lib/dpkg/status') as tagfile:
for section in tagfile:
- print section['Package']
+ print(section['Package'])
.. versionchanged:: 0.7.100
Added support for using gzip files, via :class:`gzip.GzipFile` or any
diff --git a/doc/source/tutorials/apt-get.rst b/doc/source/tutorials/apt-get.rst
index f8dd089..26ebc3d 100644
--- a/doc/source/tutorials/apt-get.rst
+++ b/doc/source/tutorials/apt-get.rst
@@ -38,7 +38,7 @@ URIs. Luckily, there is :attr:`apt_pkg.Acquire.items` which allows us to
iterate over the items::
for item in acquire.items:
- print item.desc_uri
+ print(item.desc_uri)
In the end a program could look like this:
--
2.6.2
Reply to: