本文整理汇总了Python中xattr.remove函数的典型用法代码示例。如果您正苦于以下问题:Python remove函数的具体用法?Python remove怎么用?Python remove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _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
开发者ID:Wiesel97,项目名称:bup,代码行数:28,代码来源:metadata.py
示例2: xattr_sync
def xattr_sync(file_name, meta):
""" Synchronize the xattrs on a file with a hash of our choosing """
to_delete, to_set = xattr_sync_impl(file_name, meta)
for k in to_delete:
xattr.remove(file_name, k)
for k,v in to_set.items():
xattr.set(file_name, k, v, namespace=xattr.NS_USER)
开发者ID:BillTheBest,项目名称:ceph,代码行数:7,代码来源:test-obsync.py
示例3: preserve_xattrs
def preserve_xattrs(path, nofollow=False, namespace=None):
"""Context manager to save/restore extended attributes on |path|
If you want to rewrite a file (possibly replacing it with a new one), but
want to preserve the extended attributes, this will do the trick.
# First read all the extended attributes.
with save_xattrs('/some/file'):
... rewrite the file ...
# Now the extended attributes are restored as needed.
"""
kwargs = {'nofollow': nofollow,}
if namespace:
# Compiled xattr python module does not like it when namespace=None.
kwargs['namespace'] = namespace
old_attrs = dict(xattr.get_all(path, **kwargs))
try:
yield
finally:
new_attrs = dict(xattr.get_all(path, **kwargs))
for name, value in new_attrs.items():
if name not in old_attrs:
# Clear out new ones.
xattr.remove(path, name, **kwargs)
elif new_attrs[name] != old_attrs[name]:
# Update changed ones.
xattr.set(path, name, value, **kwargs)
for name, value in old_attrs.items():
if name not in new_attrs:
# Re-add missing ones.
xattr.set(path, name, value, **kwargs)
开发者ID:aeroniero33,项目名称:portage,代码行数:33,代码来源:_xattr.py
示例4: test_loading_attr_ensures_all_xattrs_are_set
def test_loading_attr_ensures_all_xattrs_are_set(self):
dumbattr.set(self.file1, "file_1", "1")
xattr.remove(self.file1, "file_1", namespace=xattr.NS_USER)
self.assertEqual(self.all_xattrs(self.file1), {})
self.assertEqual(dumbattr.load(self.file1).copy(), {'file_1':'1'})
self.assertEqual(self.all_xattrs(self.file1), {b'file_1':b'1'})
开发者ID:timbertson,项目名称:dumbattr,代码行数:8,代码来源:dumbattr_test.py
示例5: _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)
开发者ID:quantheory,项目名称:pyxattr,代码行数:58,代码来源:test_xattr.py
示例6: clean_metadata
def clean_metadata(path):
key = 0
while True:
try:
xattr.remove(path, '%s%s' % (METADATA_KEY, (key or '')))
except IOError as err:
if err.errno == errno.ENODATA:
break
key += 1
开发者ID:gf1730,项目名称:glusterfs,代码行数:9,代码来源:utils.py
示例7: testSymlinkOps
def testSymlinkOps(self):
"""test symlink operations"""
_, sname = self._getsymlink()
self.assertRaises(EnvironmentError, xattr.list, sname)
self._checkListSetGet(sname, symlink=True)
self._checkListSetGet(sname, symlink=True, use_ns=True)
target, sname = self._getsymlink(dangling=False)
xattr.set(target, self.USER_ATTR, self.USER_VAL)
self.assertEqual(xattr.list(target), [self.USER_ATTR])
self.assertEqual(xattr.list(sname, nofollow=True), [])
self.assertRaises(EnvironmentError, xattr.remove, sname, self.USER_ATTR, nofollow=True)
xattr.remove(sname, self.USER_ATTR, nofollow=False)
开发者ID:floppym,项目名称:pyxattr,代码行数:12,代码来源:test_xattr.py
示例8: check_user_xattr
def check_user_xattr(path):
if not os.path.exists(path):
return False
try:
xattr.set(path, 'user.test.key1', 'value1')
except IOError as err:
logging.exception("check_user_xattr: set failed on %s err: %s", path, str(err))
raise
try:
xattr.remove(path, 'user.test.key1')
except Exception, err:
logging.exception("xattr.remove failed on %s err: %s", path, str(err))
开发者ID:glycerine,项目名称:glusterfs,代码行数:12,代码来源:utils.py
示例9: check_user_xattr
def check_user_xattr(path):
if not os.path.exists(path):
return False
try:
xattr.set(path, 'user.test.key1', 'value1')
except IOError as err:
logging.exception("check_user_xattr: set failed on %s err: %s", path, str(err))
raise
try:
xattr.remove(path, 'user.test.key1')
except IOError as err:
logging.exception("check_user_xattr: remove failed on %s err: %s", path, str(err))
#Remove xattr may fail in case of concurrent remove.
return True
开发者ID:sun3shines,项目名称:ufo,代码行数:14,代码来源:utils.py
示例10: 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)
开发者ID:floppym,项目名称:pyxattr,代码行数:15,代码来源:test_xattr.py
示例11: process
def process(path):
# get tags
try: attrvalue = xattr.get(path, ATTRNAME)
except IOError: tags = set();
else: tags = set(attrvalue.split("\x1f"))
oldtags = tags
# perform operations
if options.filter and not set(options.filter) <= tags: return
if options.clear: tags = []
if options.add: tags = tags | set(options.add)
if options.delete: tags = tags - set(options.delete)
if not tags == oldtags:
if tags:
xattr.set(path, ATTRNAME, "\x1f".join(tags))
else:
try: xattr.remove(path, ATTRNAME)
except IOError: pass
if options.list: print path, "::", ", ".join(tags)
开发者ID:quartsize,项目名称:sedulity,代码行数:18,代码来源:sedulity.py
示例12: _set
def _set(self, filename, key, value):
path = os.path.join(self.dirpath, filename)
logger.info("Setting %s=%s (%s)", key, value, path)
if os.path.islink(path):
if value is None:
h = self._saved_attrs[filename]
del h[key]
if not h:
del self._saved_attrs[filename]
else:
if not filename in self._saved_attrs:
self._saved_attrs[filename] = {}
self._saved_attrs[filename][key] = value
else:
logger.debug("Setting xattr %s=%s (%s)", key, value, path)
if value is None:
xattr.remove(path, key, namespace=xattr.NS_USER)
else:
xattr.set(path, key, value, namespace=xattr.NS_USER)
self._update_saved_attrs(filename)
开发者ID:timbertson,项目名称:dumbattr,代码行数:20,代码来源:dumbattr.py
示例13: _apply_linux_xattr_rec
def _apply_linux_xattr_rec(self, path, restore_numeric_ids=False):
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:
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
开发者ID:meeee,项目名称:bup,代码行数:22,代码来源:metadata.py
示例14: test_handling_of_incorrect_existing_linux_xattrs
def test_handling_of_incorrect_existing_linux_xattrs():
if os.geteuid() != 0 or detect_fakeroot():
return
setup_testfs()
subprocess.check_call('rm -rf testfs/*', shell=True)
path = 'testfs/foo'
open(path, 'w').close()
xattr.set(path, 'foo', 'bar', namespace=xattr.NS_USER)
m = metadata.from_path(path, archive_path=path, save_symlinks=True)
xattr.set(path, 'baz', 'bax', namespace=xattr.NS_USER)
m.apply_to_path(path, restore_numeric_ids=False)
WVPASSEQ(xattr.list(path), ['user.foo'])
WVPASSEQ(xattr.get(path, 'user.foo'), 'bar')
xattr.set(path, 'foo', 'baz', namespace=xattr.NS_USER)
m.apply_to_path(path, restore_numeric_ids=False)
WVPASSEQ(xattr.list(path), ['user.foo'])
WVPASSEQ(xattr.get(path, 'user.foo'), 'bar')
xattr.remove(path, 'foo', namespace=xattr.NS_USER)
m.apply_to_path(path, restore_numeric_ids=False)
WVPASSEQ(xattr.list(path), ['user.foo'])
WVPASSEQ(xattr.get(path, 'user.foo'), 'bar')
os.chdir(top_dir)
cleanup_testfs()
开发者ID:meeee,项目名称:bup,代码行数:23,代码来源:tmetadata.py
示例15: ApplyError
raise ApplyError("xattr.set: %s" % e)
else:
raise
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
def __init__(self):
self.mode = None
# optional members
self.path = None
self.size = None
self.symlink_target = None
self.hardlink_target = None
self.linux_attr = None
self.linux_xattr = None
开发者ID:kwharrigan,项目名称:bup,代码行数:31,代码来源:metadata.py
示例16: __remove
def __remove(self,path,key):
xattr.remove(path,key,namespace=self.ns)
开发者ID:Neuvoo,项目名称:legacy-portage,代码行数:2,代码来源:ebuild_xattr.py
示例17: clear_cache
def clear_cache(self):
for name in xattr.list(self.name):
if name.decode().startswith('user.pyanidb.'):
xattr.remove(self.name, name)
开发者ID:xyzz,项目名称:pyanidb,代码行数:4,代码来源:hash.py
示例18: __delitem__
def __delitem__(self, key):
"""
Removes a filesystem attribute
"""
xattr.remove(self._path, key, namespace=xattr.NS_USER)
开发者ID:juddc,项目名称:MediaFS,代码行数:5,代码来源:xattrs.py
注:本文中的xattr.remove函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论