summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2007-04-15 01:09:03 +0000
committerBob Ippolito <bob@redivi.com>2007-04-15 01:09:03 +0000
commitc45b708511e5d89dd8bde8f6d47d3ca325d83cd7 (patch)
treed32e4b418314293141b4d84f61e40137bcbd2ce5
parentd05855cc2344d4028f815b2b4eef38f8be1c7c41 (diff)
downloadxattr-c45b708511e5d89dd8bde8f6d47d3ca325d83cd7.tar.gz
detabv0.5
-rwxr-xr-xLib/xattr/tool.py140
1 files changed, 70 insertions, 70 deletions
diff --git a/Lib/xattr/tool.py b/Lib/xattr/tool.py
index f1ca728..b7eee1d 100755
--- a/Lib/xattr/tool.py
+++ b/Lib/xattr/tool.py
@@ -74,89 +74,89 @@ def main():
elif opt == "-l":
long_format = True
elif opt == "-p":
- read = True
+ read = True
elif opt == "-w":
- write = True
+ write = True
elif opt == "-d":
- delete = True
+ delete = True
if write or delete:
- if long_format:
- usage("-l not allowed with -w or -p")
+ if long_format:
+ usage("-l not allowed with -w or -p")
if read or write or delete:
- if not args:
- usage("No attr_name")
- attr_name = args.pop(0)
+ if not args:
+ usage("No attr_name")
+ attr_name = args.pop(0)
if write:
- if not args:
- usage("No attr_value")
- attr_value = args.pop(0)
+ if not args:
+ usage("No attr_value")
+ attr_value = args.pop(0)
if len(args) > 1:
- multiple_files = True
+ multiple_files = True
else:
- multiple_files = False
+ multiple_files = False
for filename in args:
- def onError(e):
- if not os.path.exists(filename):
- sys.stderr.write("No such file: %s\n" % (filename,))
- else:
- sys.stderr.write(str(e) + "\n")
- status = 1
-
- try:
- attrs = xattr.xattr(filename)
- except (IOError, OSError), e:
- onError(e)
- continue
-
- if write:
- try:
- attrs[attr_name] = attr_value
- except (IOError, OSError), e:
- onError(e)
- continue
-
- elif delete:
- try:
- del attrs[attr_name]
- except (IOError, OSError), e:
- onError(e)
- continue
- except KeyError:
- onError("No such xattr: %s" % (attr_name,))
- continue
-
- else:
- try:
- if read:
- attr_names = (attr_name,)
- else:
- attr_names = attrs.keys()
- except (IOError, OSError), e:
- onError(e)
- continue
-
- if multiple_files:
- file_prefix = "%s: " % (filename,)
- else:
- file_prefix = ""
-
- for attr_name in attr_names:
- try:
- if long_format:
- print "".join((file_prefix, "%s: " % (attr_name,), attrs[attr_name]))
- else:
- if read:
- print "".join((file_prefix, attrs[attr_name]))
- else:
- print "".join((file_prefix, attr_name))
- except KeyError:
- onError("%sNo such xattr: %s" % (file_prefix, attr_name))
- continue
+ def onError(e):
+ if not os.path.exists(filename):
+ sys.stderr.write("No such file: %s\n" % (filename,))
+ else:
+ sys.stderr.write(str(e) + "\n")
+ status = 1
+
+ try:
+ attrs = xattr.xattr(filename)
+ except (IOError, OSError), e:
+ onError(e)
+ continue
+
+ if write:
+ try:
+ attrs[attr_name] = attr_value
+ except (IOError, OSError), e:
+ onError(e)
+ continue
+
+ elif delete:
+ try:
+ del attrs[attr_name]
+ except (IOError, OSError), e:
+ onError(e)
+ continue
+ except KeyError:
+ onError("No such xattr: %s" % (attr_name,))
+ continue
+
+ else:
+ try:
+ if read:
+ attr_names = (attr_name,)
+ else:
+ attr_names = attrs.keys()
+ except (IOError, OSError), e:
+ onError(e)
+ continue
+
+ if multiple_files:
+ file_prefix = "%s: " % (filename,)
+ else:
+ file_prefix = ""
+
+ for attr_name in attr_names:
+ try:
+ if long_format:
+ print "".join((file_prefix, "%s: " % (attr_name,), attrs[attr_name]))
+ else:
+ if read:
+ print "".join((file_prefix, attrs[attr_name]))
+ else:
+ print "".join((file_prefix, attr_name))
+ except KeyError:
+ onError("%sNo such xattr: %s" % (file_prefix, attr_name))
+ continue
sys.exit(status)