Skip to content

Commit

Permalink
Merge pull request #21 from alex/fix-prints
Browse files Browse the repository at this point in the history
Made print statements python3 compatible in xattr.tool -- REfs #20
  • Loading branch information
etrepum committed Jan 12, 2014
2 parents 5abf7c4 + 6321e21 commit 1e1652b
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions xattr/tool.py
Expand Up @@ -25,6 +25,8 @@
# IN THE SOFTWARE.
##

from __future__ import print_function

import sys
import os
import getopt
Expand All @@ -35,24 +37,24 @@

def usage(e=None):
if e:
print e
print ""
print(e)
print("")

name = os.path.basename(sys.argv[0])
print "usage: %s [-lz] file [file ...]" % (name,)
print " %s -p [-lz] attr_name file [file ...]" % (name,)
print " %s -w [-z] attr_name attr_value file [file ...]" % (name,)
print " %s -d attr_name file [file ...]" % (name,)
print ""
print "The first form lists the names of all xattrs on the given file(s)."
print "The second form (-p) prints the value of the xattr attr_name."
print "The third form (-w) sets the value of the xattr attr_name to attr_value."
print "The fourth form (-d) deletes the xattr attr_name."
print ""
print "options:"
print " -h: print this help"
print " -l: print long format (attr_name: attr_value)"
print " -z: compress or decompress (if compressed) attribute value in zip format"
print("usage: %s [-lz] file [file ...]" % (name,))
print(" %s -p [-lz] attr_name file [file ...]" % (name,))
print(" %s -w [-z] attr_name attr_value file [file ...]" % (name,))
print(" %s -d attr_name file [file ...]" % (name,))
print("")
print("The first form lists the names of all xattrs on the given file(s).")
print("The second form (-p) prints the value of the xattr attr_name.")
print("The third form (-w) sets the value of the xattr attr_name to attr_value.")
print("The fourth form (-d) deletes the xattr attr_name.")
print("")
print("options:")
print(" -h: print this help")
print(" -l: print long format (attr_name: attr_value)")
print(" -z: compress or decompress (if compressed) attribute value in zip format")

if e:
sys.exit(64)
Expand Down Expand Up @@ -80,7 +82,7 @@ def _dump(src, length=16):
def main():
try:
(optargs, args) = getopt.getopt(sys.argv[1:], "hlpwdz", ["help"])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
usage(e)

attr_name = None
Expand Down Expand Up @@ -141,21 +143,21 @@ def onError(e):

try:
attrs = xattr.xattr(filename)
except (IOError, OSError), e:
except (IOError, OSError) as e:
onError(e)
continue

if write:
try:
attrs[attr_name] = compress(attr_value)
except (IOError, OSError), e:
except (IOError, OSError) as e:
onError(e)
continue

elif delete:
try:
del attrs[attr_name]
except (IOError, OSError), e:
except (IOError, OSError) as e:
onError(e)
continue
except KeyError:
Expand All @@ -168,7 +170,7 @@ def onError(e):
attr_names = (attr_name,)
else:
attr_names = attrs.keys()
except (IOError, OSError), e:
except (IOError, OSError) as e:
onError(e)
continue

Expand All @@ -191,15 +193,15 @@ def onError(e):
try:
if attr_value.find('\0') >= 0:
raise NullsInString
print "".join((file_prefix, "%s: " % (attr_name,), attr_value))
print("".join((file_prefix, "%s: " % (attr_name,), attr_value)))
except (UnicodeDecodeError, NullsInString):
print "".join((file_prefix, "%s:" % (attr_name,)))
print _dump(attr_value)
print("".join((file_prefix, "%s:" % (attr_name,))))
print(_dump(attr_value))
else:
if read:
print "".join((file_prefix, attr_value))
print("".join((file_prefix, attr_value)))
else:
print "".join((file_prefix, attr_name))
print("".join((file_prefix, attr_name)))

sys.exit(status)

Expand Down

0 comments on commit 1e1652b

Please sign in to comment.