4
from optparse import OptionParser
10
if (string[0] == '0' and
13
tmp_string = string.strip('%s%s' %
16
return tmp_string.decode('base64')
18
if (string[0] == '0' and
21
tmp_string = string.split('%s%s' %
24
return tmp_string[1].decode('hex')
28
if __name__ == '__main__':
29
usage = "usage: %prog [-n name] [-v value] [-x name]"
30
parser = OptionParser(usage=usage)
31
parser.add_option("-n", action="store", dest="name", type="string",
32
help="Specifies the name of the extended attribute to set.")
33
parser.add_option("-v", action="store", dest="value", type="string",
34
help="Specifies the new value of the extended attribute."
35
" There are three methods available for encoding the value."
36
" If the given string is enclosed in double quotes, the"
37
" inner string is treated as text. In that case,"
38
" backslashes and double quotes have special meanings"
39
" and need to be escaped by a preceding backslash. Any"
40
" control characters can be encoded as a backslash"
41
" followed by three digits as its ASCII code in octal."
42
" If the given string begins with 0x or 0X, it expresses"
43
" a hexadecimal number. If the given string begins with"
44
" 0s or 0S, base64 encoding is expected.")
45
parser.add_option("-x", action="store", dest="xname", type="string",
46
help="Remove the named extended attribute entirely.")
48
(option, args) = parser.parse_args()
50
print ("Usage: setfattr {-n name} [-v value] file...")
51
print (" setfattr {-x name} file...")
52
print ("Try `setfattr --help' for more information.")
55
if option.name and option.xname:
56
print ("-n and -x are mutually exclusive...")
60
if option.value is None:
61
print ("-n option requires -v value...")
63
args[0] = os.path.abspath(args[0])
65
if option.name and option.value:
67
xattr.setxattr(args[0], option.name, convert(option.value))
68
except Exception as err:
74
xattr.removexattr(args[0], option.xname)
75
except Exception as err: