• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xattr.list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xattr.list函数的典型用法代码示例。如果您正苦于以下问题:Python list函数的具体用法?Python list怎么用?Python list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了list函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _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


示例2: 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


示例3: 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


示例4: 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()
开发者ID:floppym,项目名称:pyxattr,代码行数:15,代码来源:test_xattr.py


示例5: _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


示例6: populate_pgfid_and_inodegfid

def populate_pgfid_and_inodegfid(brick, changelog_data):
    """
    For all the DATA/METADATA modifications GFID,
    If symlink, directly convert to Path using Readlink.
    If not symlink, try to get PGFIDs via xattr query and populate it
    to pgfid table, collect inodes in inodegfid table
    """
    for row in changelog_data.gfidpath_get({"path1": "", "type": "MODIFY"}):
        gfid = row[3].strip()
        p = os.path.join(brick, ".glusterfs", gfid[0:2], gfid[2:4], gfid)
        if os.path.islink(p):
            # It is a Directory if GFID backend path is symlink
            try:
                path = symlink_gfid_to_path(brick, gfid)
                path = output_path_prepare(path, args)
                changelog_data.gfidpath_update({"path1": path},
                                               {"gfid": gfid})
            except (IOError, OSError) as e:
                logger.warn("Error converting to path: %s" % e)
                continue
        else:
            try:
                # INODE and GFID to inodegfid table
                changelog_data.inodegfid_add(os.stat(p).st_ino, gfid)
                file_xattrs = xattr.list(p)
                for x in file_xattrs:
                    if x.startswith("trusted.pgfid."):
                        # PGFID in pgfid table
                        changelog_data.pgfid_add(x.split(".")[-1])
            except (IOError, OSError):
                # All OS Errors ignored, since failures will be logged
                # in End. All GFIDs present in gfidpath table
                continue
开发者ID:gluster,项目名称:glusterfs,代码行数:33,代码来源:changelog.py


示例7: 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)])
开发者ID:floppym,项目名称:pyxattr,代码行数:16,代码来源:test_xattr.py


示例8: _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)))
开发者ID:Spencerx,项目名称:portage,代码行数:26,代码来源:movefile.py


示例9: read_cache

	def read_cache(self):
		if not xattr:
			return
		cache = dict([(n[13:], xattr.get(self.name, n)) for n in xattr.list(self.name) if n.decode().startswith('user.pyanidb.')])
		if 'mtime' not in cache or str(int(self.mtime)) != cache.pop('mtime'):
			return
		for n, v in cache.items():
			setattr(self, n, v)
		self.cached = True
开发者ID:xyzz,项目名称:pyanidb,代码行数:9,代码来源:hash.py


示例10: get_sha1

	def get_sha1(self):
		name = self.get_real_name()
		if "user.sha1" in xattr.list(name):
			val = xattr.get(name, "user.sha1")[:-1]
		else:
			with open(name) as f:
				val = sha1(f.read()).hexdigest()
			xattr.setxattr(name, "user.sha1", "%s\x00" % val)
		return val
开发者ID:terrop,项目名称:atrfs,代码行数:9,代码来源:FLVTree.py


示例11: _copyxattr

		def _copyxattr(src, dest):
			for attr in xattr.list(src):
				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 attributes" % dest)
开发者ID:zy-sunshine,项目名称:easymgc,代码行数:9,代码来源:movefile.py


示例12: 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


示例13: _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
     if not self.linux_xattr:
         return
     try:
         existing_xattrs = set(xattr.list(path, nofollow=True))
     except IOError, e:
         if e.errno == errno.EACCES:
             raise ApplyError("xattr.set: %s" % e)
         else:
             raise
开发者ID:kwharrigan,项目名称:bup,代码行数:14,代码来源:metadata.py


示例14: 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)
开发者ID:gluster,项目名称:glustertool,代码行数:48,代码来源:volmark.py


示例15: dump_xattrs

def dump_xattrs(pathnames, file_out):
	"""Dump the xattr data for |pathnames| to |file_out|"""
	# NOTE: Always quote backslashes, in order to ensure that they are
	# not interpreted as quotes when they are processed by unquote.
	quote_chars = b'\n\r\\\\'

	for pathname in pathnames:
		attrs = xattr.list(pathname)
		if not attrs:
			continue

		file_out.write(b'# file: %s\n' % quote(pathname, quote_chars))
		for attr in attrs:
			attr = unicode_encode(attr)
			value = xattr.get(pathname, attr)
			file_out.write(b'%s="%s"\n' % (
				quote(attr, b'=' + quote_chars),
				quote(value, b'\0"' + quote_chars)))
开发者ID:entoo,项目名称:portage-src,代码行数:18,代码来源:xattr-helper.py


示例16: _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


示例17: testNoXattr

 def testNoXattr(self):
     """test no attributes"""
     fh, fname = self._getfile()
     self.assertEqual(xattr.list(fname), [])
     self.assertEqual(xattr.list(fname, namespace=NS_USER), [])
     self.assertEqual(xattr.get_all(fname), [])
     self.assertEqual(xattr.get_all(fname, namespace=NS_USER), [])
     dname = self._getdir()
     self.assertEqual(xattr.list(dname), [])
     self.assertEqual(xattr.list(dname, namespace=NS_USER), [])
     self.assertEqual(xattr.get_all(dname), [])
     self.assertEqual(xattr.get_all(dname, namespace=NS_USER), [])
     _, sname = self._getsymlink()
     self.assertEqual(xattr.list(sname, nofollow=True), [])
     self.assertEqual(xattr.list(sname, nofollow=True, namespace=NS_USER), [])
     self.assertEqual(xattr.get_all(sname, nofollow=True), [])
     self.assertEqual(xattr.get_all(sname, nofollow=True, namespace=NS_USER), [])
开发者ID:floppym,项目名称:pyxattr,代码行数:17,代码来源:test_xattr.py


示例18: keys

 def keys(self):
     """
     Returns a list of all filesystem attributes
     """
     return [ key.decode() for key in xattr.list(self._path, namespace=xattr.NS_USER) ]
开发者ID:juddc,项目名称:MediaFS,代码行数:5,代码来源:xattrs.py


示例19: gfid_to_path_using_pgfid

def gfid_to_path_using_pgfid(brick, gfids_file, output_file, outfile_failures):
    """
    Parent GFID is saved as xattr, collect Parent GFIDs from all
    the files from gfids_file. Convert parent GFID to path and Crawl
    each directories to get the list of files/dirs having same inode number.
    Do find with maxdepth as 1 and print the output in <INODE_NUM> <PATH>
    format, use this output to look into in memory dictionary of inode
    numbers got from the list of GFIDs
    """
    with open(output_file, "a+") as fout:
        pgfids = set()
        inode_dict = {}
        with open(gfids_file) as f:
            for gfid in f:
                gfid = gfid.strip()
                p = os.path.join(brick,
                                 ".glusterfs",
                                 gfid[0:2],
                                 gfid[2:4],
                                 gfid)
                if os.path.islink(p):
                    path = symlink_gfid_to_path(brick, gfid)
                    output_write(fout, path, args.output_prefix)
                else:
                    try:
                        inode_dict[str(os.stat(p).st_ino)] = 1
                        file_xattrs = xattr.list(p)
                        num_parent_gfid = 0
                        for x in file_xattrs:
                            if x.startswith("trusted.pgfid."):
                                num_parent_gfid += 1
                                pgfids.add(x.split(".")[-1])

                        if num_parent_gfid == 0:
                            with open(outfile_failures, "a") as f:
                                f.write("%s\n" % gfid)
                                f.flush()
                                os.fsync(f.fileno())

                    except (IOError, OSError) as e:
                        if e.errno == ENOENT:
                            continue
                        else:
                            fail("%s Failed to convert to path from "
                                 "GFID %s: %s" % (brick, gfid, e),
                                 logger=logger)

        if not inode_dict:
            return

        def inode_filter(path):
            try:
                st = os.lstat(path)
            except (OSError, IOError) as e:
                if e.errno == ENOENT:
                    st = None
                else:
                    raise

            if st and inode_dict.get(str(st.st_ino), None):
                return True

            return False

        # Length of brick path, to remove from output path
        brick_path_len = len(brick)

        def output_callback(path):
            path = path.strip()
            path = path[brick_path_len+1:]
            output_write(fout, path, args.output_prefix)

        ignore_dirs = [os.path.join(brick, dirname)
                       for dirname in
                       conf.get_opt("brick_ignore_dirs").split(",")]

        for pgfid in pgfids:
            path = symlink_gfid_to_path(brick, pgfid)
            find(os.path.join(brick, path),
                 callback_func=output_callback,
                 filter_func=inode_filter,
                 ignore_dirs=ignore_dirs,
                 subdirs_crawl=False)

        fout.flush()
        os.fsync(fout.fileno())
开发者ID:SourabhShenoy,项目名称:glusterfs,代码行数:86,代码来源:changelog.py


示例20: 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



注:本文中的xattr.list函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python xattr.listxattr函数代码示例发布时间:2022-05-26
下一篇:
Python xattr.getxattr函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap