[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#807104: python-apt-doc: Use of print statements not compatible with python3



Package: python-apt-doc
Version: 1.1.0~beta1
Severity: normal
Tags: patch

The examples make use of the print statements such that it is
incompatible with python3, e.g.:

    print "Essential packages:"
    print >> sys.stderr, "need filename argument"

The attached patch modifies these lines to read:

    print("Essential packages:")
    sys.stderr.write("need filename argument\n")

--

>From 331782006251adb25118cd1343c74a1765280b4f Mon Sep 17 00:00:00 2001
From: Felix Dietrich <felix.dietrich@sperrhaken.name>
Date: Thu, 3 Dec 2015 13:34:07 +0100
Subject: [PATCH] Convert print statements so they work in python3

---
 doc/source/examples/cache-packages.py    |  8 ++++----
 doc/source/examples/cache-pkgfile.py     | 16 ++++++++--------
 doc/source/examples/dpkg-contents.py     |  4 ++--
 doc/source/examples/dpkg-extract.py      |  4 ++--
 doc/source/examples/dpkg-info.py         |  4 ++--
 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, 33 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 9497cf8..ec730c4
--- a/doc/source/examples/dpkg-contents.py
+++ b/doc/source/examples/dpkg-contents.py
@@ -38,13 +38,13 @@ def callback(what, name, link, mode, uid, gid, size, mtime, major, minor):
     s_name = name.startswith(".") and name or ("./" + name)
     if link:
         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"
+        sys.stderr.write("need filename argument\n")
         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 8d14402..42e38dc
--- a/doc/source/examples/dpkg-extract.py
+++ b/doc/source/examples/dpkg-extract.py
@@ -9,10 +9,10 @@ import apt_inst
 def main():
     """Main function."""
     if len(sys.argv) < 3:
-        print >> sys.stderr, "Usage:", __file__, "package.deb outdir"
+        sys.stderr.write("Usage: %s package.deb outdir\n" % (__file__))
         sys.exit(1)
     if not os.path.exists(sys.argv[2]):
-        print >> sys.stderr, "The directory %s does not exist" % sys.argv[2]
+        sys.stderr.write("The directory %s does not exist\n" % (sys.argv[2]))
         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..85391be
--- a/doc/source/examples/dpkg-info.py
+++ b/doc/source/examples/dpkg-info.py
@@ -8,11 +8,11 @@ from apt_inst import DebFile
 def main():
     """Main function."""
     if len(sys.argv) < 3:
-        print >> sys.stderr, 'Usage: tool file.deb control-file'
+        sys.stderr.write('Usage: tool file.deb control-file\n')
         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 5256931..9b570cd 100644
--- a/doc/source/library/apt_pkg.rst
+++ b/doc/source/library/apt_pkg.rst
@@ -1282,7 +1282,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
 
@@ -1350,7 +1350,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
 
@@ -1435,7 +1435,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
@@ -1957,7 +1957,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: