本文整理汇总了Python中xattr.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_purge_lock
def test_purge_lock(self):
resp = self.test_file.write(data='test',
hdrs={'X-Hpss-Purgelock-Status': 'true',
'X-Hpss-Class-Of-Service-Id': '1'},
return_resp=True)
print resp.status
print resp.getheaders()
print resp.read()
test_file_name = os.path.join(self.hpss_dir,
self.account.name,
self.container.name,
'testfile')
print test_file_name
print os.stat(test_file_name)
print xattr.listxattr(test_file_name)
self.assertEqual(xattr.get(test_file_name,
'system.hpss.purgelock'),
'1')
self.test_file.post(hdrs={'X-Hpss-Purgelock-Status': 'false'})
self.assertEqual(xattr.get(test_file_name,
'system.hpss.purgelock'), '0')
示例2: _checkListSetGet
def _checkListSetGet(self, item, symlink=False, use_ns=False):
"""check list, set, get operations against an item"""
self.assertEqual(self._ignore(xattr.list(item, symlink)),
[])
self.assertRaises(EnvironmentError, xattr.set, item,
self.USER_ATTR, self.USER_VAL, flags=XATTR_REPLACE)
self.assertRaises(EnvironmentError, xattr.set, item,
self.USER_NN, self.USER_VAL, flags=XATTR_REPLACE,
namespace=NS_USER)
try:
if use_ns:
xattr.set(item, self.USER_NN, self.USER_VAL,
namespace=NS_USER,
nofollow=symlink)
else:
xattr.set(item, self.USER_ATTR, self.USER_VAL,
nofollow=symlink)
except IOError:
err = sys.exc_info()[1]
if err.errno == errno.EPERM and symlink:
# symlinks may fail, in which case we abort the rest
# of the test for this case
return
raise
self.assertRaises(EnvironmentError, xattr.set, item,
self.USER_ATTR, self.USER_VAL, flags=XATTR_CREATE)
self.assertRaises(EnvironmentError, xattr.set, item,
self.USER_NN, self.USER_VAL,
flags=XATTR_CREATE, namespace=NS_USER)
self.assertEqual(self._ignore(xattr.list(item, nofollow=symlink)),
[self.USER_ATTR])
self.assertEqual(self._ignore(xattr.list(item, nofollow=symlink,
namespace=EMPTY_NS)),
[self.USER_ATTR])
self.assertEqual(xattr.list(item, namespace=NS_USER, nofollow=symlink),
[self.USER_NN])
self.assertEqual(xattr.get(item, self.USER_ATTR, nofollow=symlink),
self.USER_VAL)
self.assertEqual(xattr.get(item, self.USER_NN, nofollow=symlink,
namespace=NS_USER), self.USER_VAL)
self.assertEqual(self._ignore_tuples(xattr.get_all(item,
nofollow=symlink)),
[(self.USER_ATTR, self.USER_VAL)])
self.assertEqual(xattr.get_all(item, nofollow=symlink,
namespace=NS_USER),
[(self.USER_NN, self.USER_VAL)])
if use_ns:
xattr.remove(item, self.USER_NN, namespace=NS_USER)
else:
xattr.remove(item, self.USER_ATTR)
self.assertEqual(self._ignore(xattr.list(item, symlink)), [])
self.assertEqual(self._ignore_tuples(xattr.get_all(item,
nofollow=symlink)),
[])
self.assertRaises(EnvironmentError, xattr.remove,
item, self.USER_ATTR, nofollow=symlink)
self.assertRaises(EnvironmentError, xattr.remove, item,
self.USER_NN, namespace=NS_USER, nofollow=symlink)
示例3: get_gfid
def get_gfid(path):
try:
return uuid.UUID(bytes=xattr.get(path, "trusted.gfid",
nofollow=True))
except (IOError, OSError) as e:
if e.errno == ENODATA:
return uuid.UUID(bytes=xattr.get(path, "glusterfs.gfid",
nofollow=True))
else:
raise
示例4: mode_gfid
def mode_gfid(args):
try:
try:
print uuid.UUID(bytes=xattr.get(args.path, "trusted.gfid", nofollow=True))
except (IOError, OSError) as e:
if e.errno == ENODATA:
print uuid.UUID(bytes=xattr.get(args.path, "glusterfs.gfid", nofollow=True))
else:
raise
except (OSError, IOError) as e:
print "[Error %s] %s" % (e.errno, os.strerror(e.errno))
sys.exit(-1)
示例5: testBinaryPayload
def testBinaryPayload(self):
"""test binary values"""
fh, fname = self._getfile()
os.close(fh)
BINVAL = "abc" + "\0" + "def"
if PY3K:
BINVAL = BINVAL.encode()
xattr.set(fname, self.USER_ATTR, BINVAL)
self.assertEqual(xattr.list(fname), [self.USER_ATTR])
self.assertEqual(xattr.list(fname, namespace=NS_USER), [self.USER_NN])
self.assertEqual(xattr.get(fname, self.USER_ATTR), BINVAL)
self.assertEqual(xattr.get(fname, self.USER_NN, namespace=NS_USER), BINVAL)
self.assertEqual(xattr.get_all(fname), [(self.USER_ATTR, BINVAL)])
self.assertEqual(xattr.get_all(fname, namespace=NS_USER), [(self.USER_NN, BINVAL)])
xattr.remove(fname, self.USER_ATTR)
示例6: testMixedAccess
def testMixedAccess(self):
"""test mixed access to file"""
fh, fname = self._getfile()
fo = os.fdopen(fh)
self.assertEqual(xattr.list(fname), [])
xattr.set(fname, self.USER_ATTR, self.USER_VAL)
self.assertEqual(xattr.list(fh), [self.USER_ATTR])
self.assertEqual(xattr.list(fh, namespace=NS_USER), [self.USER_NN])
self.assertEqual(xattr.get(fo, self.USER_ATTR), self.USER_VAL)
self.assertEqual(xattr.get(fo, self.USER_NN, namespace=NS_USER), self.USER_VAL)
self.assertEqual(xattr.get_all(fo), [(self.USER_ATTR, self.USER_VAL)])
self.assertEqual(xattr.get_all(fo, namespace=NS_USER), [(self.USER_NN, self.USER_VAL)])
self.assertEqual(xattr.get_all(fname), [(self.USER_ATTR, self.USER_VAL)])
self.assertEqual(xattr.get_all(fname, namespace=NS_USER), [(self.USER_NN, self.USER_VAL)])
fo.close()
示例7: run
def run(args):
# Volmark from Master side
fmt_string = "!" + "B" * 19 + "II"
try:
vm = struct.unpack(fmt_string, xattr.get(
args.path,
"trusted.glusterfs.volume-mark",
nofollow=True))
print "UUID : %s" % uuid.UUID(
"".join(['%02x' % x for x in vm[2:18]]))
print "VERSION : %s.%s" % vm[0:2]
print "RETVAL : %s" % vm[18]
print "VOLUME MARK : %s.%s (%s)" % (
vm[19], vm[20], human_time("%s.%s" % (vm[19], vm[20])))
except (OSError, IOError) as e:
if e.errno == ENODATA:
pass
else:
print "[Error %s] %s" % (e.errno, os.strerror(e.errno))
sys.exit(-1)
# Volmark from slave side
all_xattrs = xattr.list(args.path)
fmt_string = "!" + "B" * 19 + "II" + "I"
volmark_xattrs = []
for x in all_xattrs:
if x.startswith("trusted.glusterfs.volume-mark."):
volmark_xattrs.append(x)
for vx in volmark_xattrs:
try:
vm = struct.unpack(fmt_string, xattr.get(
args.path,
vx))
print "UUID : %s" % uuid.UUID(
"".join(['%02x' % x for x in vm[2:18]]))
print "VERSION : %s.%s" % vm[0:2]
print "RETVAL : %s" % vm[18]
print "VOLUME MARK : %s.%s (%s)" % (
vm[19], vm[20], human_time("%s.%s" % (vm[19], vm[20])))
print "TIMEOUT : %s (%s)" % (vm[-1], human_time(vm[-1]))
except (OSError, IOError) as e:
if e.errno == ENODATA:
pass
else:
print "[Error %s] %s" % (e.errno, os.strerror(e.errno))
sys.exit(-1)
示例8: _apply_linux_xattr_rec
def _apply_linux_xattr_rec(self, path, restore_numeric_ids=False):
if not xattr:
if self.linux_xattr:
add_error("%s: can't restore xattr; xattr support missing.\n"
% path)
return
existing_xattrs = set(xattr.list(path, nofollow=True))
if self.linux_xattr:
for k, v in self.linux_xattr:
if k not in existing_xattrs \
or v != xattr.get(path, k, nofollow=True):
try:
xattr.set(path, k, v, nofollow=True)
except IOError, e:
if e.errno == errno.EPERM \
or e.errno == errno.EOPNOTSUPP:
raise ApplyError('xattr.set: %s' % e)
else:
raise
existing_xattrs -= frozenset([k])
for k in existing_xattrs:
try:
xattr.remove(path, k, nofollow=True)
except IOError, e:
if e.errno == errno.EPERM:
raise ApplyError('xattr.remove: %s' % e)
else:
raise
示例9: gfid_to_path
def gfid_to_path(gfid):
"""
Try readlink, if it is directory it succeeds.
Get ctime of the GFID file, Decrement by 5 sec
Search for Changelog filename, Since Changelog file generated
every 15 sec, Search and get immediate next Changelog after the file
Creation. Get the Path by searching in Changelog file.
Get the resultant file's GFID and Compare with the input, If these
GFIDs are different then Some thing is changed(May be Rename)
"""
gfid = gfid.strip()
gpath = os.path.join(".glusterfs", gfid[0:2], gfid[2:4], gfid)
try:
output_success(full_dir_path(gfid))
return
except OSError:
# Not an SymLink
pass
try:
ctime = int(os.stat(gpath).st_ctime)
ctime -= DEC_CTIME_START
except (OSError, IOError):
output_not_found(gfid)
return
path = None
found_changelog = False
changelog_parse_try = 0
for i in range(CHANGELOG_SEARCH_MAX_TRY):
cl = os.path.join(".glusterfs/changelogs", "CHANGELOG.%s" % ctime)
try:
with open(cl, "rb") as f:
changelog_parse_try += 1
found_changelog = True
path = find_path_from_changelog(f, gfid)
if not path and changelog_parse_try < MAX_NUM_CHANGELOGS_TRY:
ctime += 1
continue
break
except (IOError, OSError) as e:
if e.errno == errno.ENOENT:
ctime += 1
else:
break
if not found_changelog:
output_not_found(gfid)
return
if not path:
output_not_found(gfid)
return
gfid1 = str(uuid.UUID(bytes=xattr.get(path, "trusted.gfid")))
if gfid != gfid1:
output_not_found(gfid)
return
output_success(path)
示例10: mode_stime
def mode_stime(args):
try:
stime_key = "trusted.glusterfs.%s.%s.stime" % (args.master_uuid, args.slave_uuid)
print struct.unpack("!II", xattr.get(args.path, stime_key, nofollow=True))
except (OSError, IOError) as e:
print "[Error %s] %s" % (e.errno, os.strerror(e.errno))
sys.exit(-1)
示例11: testManyOps
def testManyOps(self):
"""test many ops"""
fh, fname = self._getfile()
xattr.set(fh, self.USER_ATTR, self.USER_VAL)
VL = [self.USER_ATTR]
VN = [self.USER_NN]
for i in range(self.MANYOPS_COUNT):
self.assertEqual(xattr.list(fh), VL)
self.assertEqual(xattr.list(fh, namespace=EMPTY_NS), VL)
self.assertEqual(xattr.list(fh, namespace=NS_USER), VN)
for i in range(self.MANYOPS_COUNT):
self.assertEqual(xattr.get(fh, self.USER_ATTR), self.USER_VAL)
self.assertEqual(xattr.get(fh, self.USER_NN, namespace=NS_USER), self.USER_VAL)
for i in range(self.MANYOPS_COUNT):
self.assertEqual(xattr.get_all(fh), [(self.USER_ATTR, self.USER_VAL)])
self.assertEqual(xattr.get_all(fh, namespace=NS_USER), [(self.USER_NN, self.USER_VAL)])
示例12: _copyxattr
def _copyxattr(src, dest, exclude=None):
try:
attrs = xattr.list(src)
except IOError as e:
if e.errno != OperationNotSupported.errno:
raise
attrs = ()
if attrs:
if exclude is not None and isinstance(attrs[0], bytes):
exclude = exclude.encode(_encodings['fs'])
exclude = _get_xattr_excluder(exclude)
for attr in attrs:
if exclude(attr):
continue
try:
xattr.set(dest, attr, xattr.get(src, attr))
raise_exception = False
except IOError:
raise_exception = True
if raise_exception:
raise OperationNotSupported(_("Filesystem containing file '%s' "
"does not support extended attribute '%s'") %
(_unicode_decode(dest), _unicode_decode(attr)))
示例13: run
def run(args):
xtime_key = "trusted.glusterfs.%s.xtime" % args.vol_uuid
try:
print struct.unpack("!II", xattr.get(args.path, xtime_key,
nofollow=True))
except (OSError, IOError) as e:
print "[Error %s] %s" % (e.errno, os.strerror(e.errno))
sys.exit(-1)
示例14: __get
def __get(self,path,key,default=None):
try:
return xattr.get(path,key,namespace=self.ns)
except IOError as e:
if not default is None and ENODATA == e.errno:
return default
else:
raise NoValueException()
示例15: test_change_cos
def test_change_cos(self):
self.test_file.write(data='asdfasdf',
hdrs={'X-Hpss-Class-Of-Service-Id': '2'})
test_file_name = os.path.join(self.hpss_dir,
self.account.name,
self.container.name,
'testfile')
print test_file_name
time.sleep(10) # It takes a long time for HPSS to get around to it.
self.assertEqual(xattr.get(test_file_name, 'system.hpss.cos'), '2')
self.test_file.post(hdrs={'X-Hpss-Class-Of-Service-Id': '1'})
time.sleep(10)
self.assertEqual(xattr.get(test_file_name, 'system.hpss.cos'), '1')