summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2006-01-06 00:14:36 +0000
committerBob Ippolito <bob@redivi.com>2006-01-06 00:14:36 +0000
commitd5e74720eb2bde10b37f95c4c9cc02552df69805 (patch)
tree5836ee79f87949b834b660abb74cd5d7b9340d56
parent13d2101a29781fc79fdbefbaf23ea94c24f7ed50 (diff)
downloadxattr-d5e74720eb2bde10b37f95c4c9cc02552df69805.tar.gz
add the tool
-rwxr-xr-xLib/xattr/tool.py82
-rw-r--r--setup.cfg3
-rw-r--r--setup.py5
3 files changed, 90 insertions, 0 deletions
diff --git a/Lib/xattr/tool.py b/Lib/xattr/tool.py
new file mode 100755
index 0000000..aad278d
--- /dev/null
+++ b/Lib/xattr/tool.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+
+import sys
+import os
+import getopt
+import xattr
+
+##
+# Handle command line
+##
+
+# Defaults
+attr_name = None
+attr_value = None
+long_format = False
+
+def usage(e=None):
+ if e:
+ print e
+ print ""
+
+ print "usage: %s [-l] file [attr_name [attr_value]]" % (sys.argv[0],)
+ print " -l: print long format (attr_name: attr_value) when listing xattrs"
+ print " With no optional arguments, lists the xattrs on file"
+ print " With attr_name only, lists the contents of attr_name on file"
+ print " With attr_value, set the contents of attr_name on file"
+
+ if e:
+ sys.exit(1)
+ else:
+ sys.exit(0)
+
+def main():
+ # Read options
+ try:
+ (optargs, args) = getopt.getopt(sys.argv[1:], "hl", ["help"])
+ except getopt.GetoptError, e:
+ usage(e)
+
+ for opt, arg in optargs:
+ if opt in ("-h", "--help"):
+ usage()
+ elif opt == "-l":
+ long_format = True
+
+ if args:
+ filename = args.pop(0)
+ else:
+ usage("No file argument")
+
+ if args:
+ attr_name = args.pop(0)
+ if args:
+ attr_value = args.pop(0)
+
+ ##
+ # Do The Right Thing
+ ##
+
+ attrs = xattr.xattr(filename)
+
+ if attr_name:
+ if attr_value:
+ attrs[attr_name] = attr_value
+ else:
+ if attr_name in attrs:
+ if long_format:
+ print "%s: %s" % (attr_name, attrs[attr_name])
+ else:
+ print attrs[attr_name]
+ else:
+ print "No such attribute."
+ sys.exit(1)
+ else:
+ for attr_name in attrs:
+ if long_format:
+ print "%s: %s" % (attr_name, attrs[attr_name])
+ else:
+ print attr_name
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..01bb954
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = dev
+tag_svn_revision = true
diff --git a/setup.py b/setup.py
index 57c16d3..9f8fce2 100644
--- a/setup.py
+++ b/setup.py
@@ -44,5 +44,10 @@ setup(
ext_modules=[
Extension("xattr._xattr", ["Modules/xattr/_xattr.c"]),
],
+ entry_points={
+ 'console_scripts': [
+ "xattr = xattr.tool:main",
+ ],
+ },
zip_safe=False,
)