[CalendarServer-changes] [1914] CalendarServer/trunk/bin/xattr
source_changes at macosforge.org
source_changes at macosforge.org
Wed Sep 26 13:36:18 PDT 2007
Revision: 1914
http://trac.macosforge.org/projects/calendarserver/changeset/1914
Author: wsanchez at apple.com
Date: 2007-09-26 13:36:18 -0700 (Wed, 26 Sep 2007)
Log Message:
-----------
Add -z option.
Modified Paths:
--------------
CalendarServer/trunk/bin/xattr
Modified: CalendarServer/trunk/bin/xattr
===================================================================
--- CalendarServer/trunk/bin/xattr 2007-09-26 20:15:46 UTC (rev 1913)
+++ CalendarServer/trunk/bin/xattr 2007-09-26 20:36:18 UTC (rev 1914)
@@ -29,6 +29,7 @@
import os
import getopt
import xattr
+import zlib
def usage(e=None):
if e:
@@ -36,9 +37,9 @@
print ""
name = os.path.basename(sys.argv[0])
- print "usage: %s [-l] file [file ...]" % (name,)
- print " %s -p [-l] attr_name file [file ...]" % (name,)
- print " %s -w attr_name attr_value file [file ...]" % (name,)
+ 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)."
@@ -49,6 +50,7 @@
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)
@@ -71,7 +73,7 @@
def main():
try:
- (optargs, args) = getopt.getopt(sys.argv[1:], "hlpwd", ["help"])
+ (optargs, args) = getopt.getopt(sys.argv[1:], "hlpwdz", ["help"])
except getopt.GetoptError, e:
usage(e)
@@ -80,6 +82,8 @@
read = False
write = False
delete = False
+ compress = lambda x: x
+ decompress = compress
status = 0
for opt, arg in optargs:
@@ -89,10 +93,19 @@
long_format = True
elif opt == "-p":
read = True
+ if write or delete:
+ usage("-p not allowed with -w or -d")
elif opt == "-w":
write = True
+ if read or delete:
+ usage("-w not allowed with -p or -d")
elif opt == "-d":
delete = True
+ if read or write:
+ usage("-d not allowed with -p or -w")
+ elif opt == "-z":
+ compress = zlib.compress
+ decompress = zlib.decompress
if write or delete:
if long_format:
@@ -129,7 +142,7 @@
if write:
try:
- attrs[attr_name] = attr_value
+ attrs[attr_name] = compress(attr_value)
except (IOError, OSError), e:
onError(e)
continue
@@ -161,23 +174,28 @@
for attr_name in attr_names:
try:
- if long_format:
- try:
- if attrs[attr_name].find('\0') >= 0:
- raise NullsInString;
- print "".join((file_prefix, "%s: " % (attr_name,), attrs[attr_name]))
- except (UnicodeDecodeError, NullsInString):
- print "".join((file_prefix, "%s:" % (attr_name,)))
- print _dump(attrs[attr_name])
- else:
- if read:
- print "".join((file_prefix, attrs[attr_name]))
- else:
- print "".join((file_prefix, attr_name))
+ try:
+ attr_value = decompress(attrs[attr_name])
+ except zlib.error:
+ attr_value = attrs[attr_name]
except KeyError:
onError("%sNo such xattr: %s" % (file_prefix, attr_name))
continue
+ if long_format:
+ try:
+ if attr_value.find('\0') >= 0:
+ raise NullsInString;
+ print "".join((file_prefix, "%s: " % (attr_name,), attr_value))
+ except (UnicodeDecodeError, NullsInString):
+ print "".join((file_prefix, "%s:" % (attr_name,)))
+ print _dump(attr_value)
+ else:
+ if read:
+ print "".join((file_prefix, attr_value))
+ else:
+ print "".join((file_prefix, attr_name))
+
sys.exit(status)
if __name__ == "__main__":
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070926/674ca3ac/attachment.html
More information about the calendarserver-changes
mailing list