diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-07-18 14:43:00 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-07-18 14:43:00 -0700 |
commit | decfae5305f707fc14875ead056b4a4f8622b9cd (patch) | |
tree | bc96a0afeb1aba67e598b8274d3f0878b9aa7643 | |
parent | 59e9ede4b3e85a7d7995a7861f0605c7bb03bd97 (diff) | |
download | xattr-decfae5305f707fc14875ead056b4a4f8622b9cd.tar.gz |
cleanups
-rw-r--r-- | _build/_make_constants.py | 20 | ||||
-rwxr-xr-x | xattr/tool.py | 33 |
2 files changed, 19 insertions, 34 deletions
diff --git a/_build/_make_constants.py b/_build/_make_constants.py deleted file mode 100644 index c73e8c1..0000000 --- a/_build/_make_constants.py +++ /dev/null @@ -1,20 +0,0 @@ -infile = '/usr/include/sys/xattr.h' -out = file('Lib/xattr/constants.py', 'w') -for line in file(infile): - line = line.rstrip() - if line.startswith('/*') and line.endswith('*/'): - print >>out, '' - print >>out, '# ' + line[2:-2].strip() - elif line.startswith('#define'): - if lastblank: - print >>out, '' - chunks = line.split(None, 3) - if len(chunks) == 3: - print >>out, '%s = %s' % (chunks[1], chunks[2]) - elif len(chunks) == 4: - comment = chunks[3].replace('/*', '').replace('*/', '').strip() - print >>out, '%s = %s # %s' % (chunks[1], chunks[2], comment) - if not line: - lastblank = True - else: - lastblank = False diff --git a/xattr/tool.py b/xattr/tool.py index 3b1121e..41ea7e1 100755 --- a/xattr/tool.py +++ b/xattr/tool.py @@ -28,9 +28,11 @@ import sys import os import getopt -import xattr import zlib +import xattr + + def usage(e=None): if e: print e @@ -57,34 +59,38 @@ def usage(e=None): else: sys.exit(0) + class NullsInString(Exception): """Nulls in string.""" -_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)]) + +_FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)]) + def _dump(src, length=16): - result=[] + result = [] for i in xrange(0, len(src), length): s = src[i:i+length] - hexa = ' '.join(["%02X"%ord(x) for x in s]) + hexa = ' '.join(["%02X" % ord(x) for x in s]) printable = s.translate(_FILTER) result.append("%04X %-*s %s\n" % (i, length*3, hexa, printable)) return ''.join(result) + def main(): try: (optargs, args) = getopt.getopt(sys.argv[1:], "hlpwdz", ["help"]) except getopt.GetoptError, e: usage(e) - attr_name = None + attr_name = None long_format = False - read = False - write = False - delete = False - compress = lambda x: x - decompress = compress - status = 0 + read = False + write = False + delete = False + compress = lambda x: x + decompress = compress + status = 0 for opt, arg in optargs: if opt in ("-h", "--help"): @@ -104,7 +110,7 @@ def main(): if read or write: usage("-d not allowed with -p or -w") elif opt == "-z": - compress = zlib.compress + compress = zlib.compress decompress = zlib.decompress if write or delete: @@ -132,7 +138,6 @@ def main(): sys.stderr.write("No such file: %s\n" % (filename,)) else: sys.stderr.write(str(e) + "\n") - status = 1 try: attrs = xattr.xattr(filename) @@ -185,7 +190,7 @@ def main(): if long_format: try: if attr_value.find('\0') >= 0: - raise NullsInString; + raise NullsInString print "".join((file_prefix, "%s: " % (attr_name,), attr_value)) except (UnicodeDecodeError, NullsInString): print "".join((file_prefix, "%s:" % (attr_name,))) |