Commit 8abd39a6 authored by Felix Dietrich's avatar Felix Dietrich Committed by Julian Andres Klode

Use print function from __future__ in examples

Closes: #807104
parent a7ba82de
......@@ -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()
......@@ -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()
#!/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])
......
#!/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])
......
#!/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()
......
......@@ -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():
......
......@@ -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()
......@@ -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
......
......@@ -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()
......@@ -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
......
......@@ -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:
......
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