当前位置: 首页>>代码示例>>Python>>正文


Python xattr.xattr方法代码示例

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


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

示例1: _ensure_xattr_support

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def _ensure_xattr_support(self):
        testfile = os.path.join(self.tempdir, "test")
        self._touch(testfile)
        xattr_supported = False
        if xattr is not None:
            try:
                x = xattr.xattr(testfile)
                x[b"user.test"] = b"test"
            except (OSError, IOError) as e:
                if e.errno != 95:
                    raise
            else:
                xattr_supported = True

        if not xattr_supported:
            raise RuntimeError("TMPDIR must support xattr for %s" %
                               self.__class__.__name__) 
开发者ID:jd,项目名称:pifpaf,代码行数:19,代码来源:__init__.py

示例2: copyxattr

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def copyxattr(src, dst):
    """Copy the extended attributes from src to dst using xattr."""
    # See http://pypi.python.org/pypi/xattr for a (possibly outdated)
    # version of xattr. A (possibly newer) version is included with
    # Python on the Mac.
    sx = xattr.xattr(src)
    dx = xattr.xattr(dst)
    # Make sure not to follow symbolic links as we always work on the
    # links themselves, not the (possibly) non-existent target.
    attrs = sx.list(xattr.constants.XATTR_NOFOLLOW)
    try:
        for name in attrs:
            value = sx.get(name, xattr.constants.XATTR_NOFOLLOW)
            dx.set(name, value, xattr.constants.XATTR_NOFOLLOW)
    except IOError:
        # Fails for certain directories which we will ignore.
        # All others, show a warning.
        if not dst.endswith(("/etc", "/tmp", "/var")):
            print "WARNING: cannot xattr %s" % dst 
开发者ID:nlfiedler,项目名称:timedog,代码行数:21,代码来源:timecopy.py

示例3: __init__

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def __init__(self, defaultuser, pathFactory):
        """
        Initialize a L{PropertyStore}.

        @param pathFactory: a 0-arg callable that returns the L{CachingFilePath}
            to set extended attributes on.
        """
        super(PropertyStore, self).__init__(defaultuser)

        self._pathFactory = pathFactory
        # self.attrs = xattr(path.path)
        self.removed = set()
        self.modified = {} 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:15,代码来源:xattr.py

示例4: attrs

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def attrs(self):
        return xattr(self.path.path) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:4,代码来源:xattr.py

示例5: test_init

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def test_init(self):
        store = self.propertyStore
        self.failUnless(isinstance(store.attrs, xattr))
        self.assertEquals(store.removed, set())
        self.assertEquals(store.modified, {}) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:7,代码来源:test_xattr.py

示例6: upgradeCalendarHome

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def upgradeCalendarHome(homePath, directory, cuaCache):

    errorOccurred = False

    log.debug("Upgrading calendar home: {path}", path=homePath)

    try:
        for cal in os.listdir(homePath):
            calPath = os.path.join(homePath, cal)
            if not os.path.isdir(calPath):
                # Skip non-directories; these might have been uploaded by a
                # random DAV client, they can't be calendar collections.
                continue
            if cal == 'notifications':
                # Delete the old, now obsolete, notifications directory.
                rmdir(calPath)
                continue
            log.debug("Upgrading calendar: {path}", path=calPath)
            if not (yield upgradeCalendarCollection(calPath, directory, cuaCache)):
                errorOccurred = True

            # Change the calendar-free-busy-set xattrs of the inbox to the
            # __uids__/<guid> form
            if cal == "inbox":
                try:
                    for attr, value in xattr.xattr(calPath).iteritems():
                        if attr == xattrname("{urn:ietf:params:xml:ns:caldav}calendar-free-busy-set"):
                            value = yield updateFreeBusySet(value, directory)
                            if value is not None:
                                # Need to write the xattr back to disk
                                xattr.setxattr(calPath, attr, value)
                except IOError, ioe:
                    if ioe.errno == errno.EOPNOTSUPP:
                        # On non-native xattr systems we cannot do this,
                        # but those systems will typically not be migrating
                        # from pre-v1
                        pass
                except:
                    raise 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:41,代码来源:upgrade.py

示例7: __init__

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def __init__(self, resource):
        self.resource = resource
        self.attrs = xattr.xattr(self.resource.fp.path) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:5,代码来源:xattrprops.py

示例8: setUp

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def setUp(self):
        """
        Create a resource and a xattr property store for it.
        """
        self.resourcePath = FilePath(self.mktemp())
        self.resourcePath.setContent("")
        self.attrs = xattr(self.resourcePath.path)
        self.resource = DAVFile(self.resourcePath.path)
        self.propertyStore = xattrPropertyStore(self.resource) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:11,代码来源:test_xattrprops.py

示例9: main

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def main():
    """Parse command line arguments and do the work."""
    # Parse the command line arguments.
    shortopts = "hnvx"
    longopts = ["help", "dry-run", "nochown", "verbose", "xattr"]
    try:
        opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
    except getopt.GetoptError, err:
        print str(err)
        print "Invoke with -h for help."
        sys.exit(2) 
开发者ID:nlfiedler,项目名称:timedog,代码行数:13,代码来源:timecopy.py

示例10: __init__

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def __init__(self,path):

       global supports_alternate_data_streams
       global supports_extended_attributes

       self.path = path
       self.x = {}
       self.dirty = False

       if xattr_disabled:
           supports_alternate_data_streams=False
           supports_extended_attributes=False
           return

       if supports_alternate_data_streams:
           self.ads = ADS(path)
           s = list(self.ads)
           if STREAM_NAME in s:
              self.x = json.loads( self.ads.get_stream_content(STREAM_NAME).decode('utf-8')  )

       if supports_extended_attributes:
          d = xattr.xattr(path)
          for i in d:
              if not i.startswith('user.sr_'):
                 continue
              k= i.replace('user.sr_','') 
              v= d[i].decode('utf-8')
              self.x[k] = v 
开发者ID:MetPX,项目名称:sarracenia,代码行数:30,代码来源:sr_xattr.py

示例11: persist

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def persist(self):

       global supports_alternate_data_streams
       global supports_extended_attributes

       if not self.dirty:
          return

       try: 
           if supports_alternate_data_streams:

              #replace STREAM_NAME with json.dumps(self.x)
              s = list(self.ads)
              if STREAM_NAME in s: 
                   self.ads.delete_stream(STREAM_NAME)

              self.ads.add_stream_from_string(STREAM_NAME,bytes(json.dumps(self.x,indent=4),'utf-8'))

           if supports_extended_attributes:
              #set the attributes in the list. encoding utf8...
              for i in self.x:
                  xattr.setxattr( self.path, 'user.sr_' + i, bytes( self.x[i], 'utf-8' ) )
       except:
          # not really sure what to do in the exception case...
          # permission would be a normal thing and just silently fail...
          # could also be on windows, but not on an NTFS file system.
          # silent failure means it falls back to using other means.
          pass

       self.dirty = False 
开发者ID:MetPX,项目名称:sarracenia,代码行数:32,代码来源:sr_xattr.py

示例12: fileStoreFromPath

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def fileStoreFromPath(cls, path):
        """
        @param path: a path pointing at the document root, where the file-based
            data-store is located.
        @type path: L{CachingFilePath}
        """

        # Legacy: old file store only ever used these two top-level paths
        for homeType in ("calendars", "addressbooks"):
            if path.child(homeType).exists():
                if platform.isMacOSX():
                    appropriateStoreClass = XattrPropertyStore
                else:
                    attrs = xattr.xattr(path.path)
                    try:
                        attrs.get('user.should-not-be-set')
                    except IOError, ioe:
                        if ioe.errno == errno.ENODATA:
                            # xattrs are supported and enabled on the filesystem
                            # where the calendar data lives.  this takes some
                            # doing (you have to edit fstab), so this means
                            # we're trying to migrate some 2.x data from a
                            # previous linux installation.
                            appropriateStoreClass = XattrPropertyStore
                        elif ioe.errno == errno.EOPNOTSUPP:
                            # The operation wasn't supported.  This is what will
                            # usually happen on a naively configured filesystem,
                            # so this means we're most likely trying to migrate
                            # some data from an untarred archive created on an
                            # OS X installation using xattrs.
                            appropriateStoreClass = AppleDoubleStore
                        else:
                            # No need to check for ENOENT and the like; we just
                            # checked above to make sure the parent exists.
                            # Other errors are not anticipated here, so fail
                            # fast.
                            raise

                    appropriateStoreClass = AppleDoubleStore

                from txdav.common.datastore.file import CommonDataStore as FileStore
                return FileStore(
                    path, None, None, True, True,
                    propertyStoreClass=appropriateStoreClass) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:46,代码来源:migrate.py

示例13: get

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def get(self, qname, uid=None):
        """
        Retrieve the value of a property stored as an extended attribute on the
        wrapped path.

        @param qname: The property to retrieve as a two-tuple of namespace URI
            and local name.

        @param uid: The per-user identifier for per user properties.

        @raise HTTPError: If there is no value associated with the given
            property.

        @return: A L{WebDAVDocument} representing the value associated with the
            given property.
        """

        try:
            data = self.attrs.get(self._encode(qname, uid))
        except KeyError:
            raise HTTPError(StatusResponse(
                responsecode.NOT_FOUND,
                "No such property: %s" % (encodeXMLName(*qname),)
            ))
        except IOError, e:
            if e.errno in _ATTR_MISSING or e.errno == errno.ENOENT:
                raise HTTPError(StatusResponse(
                    responsecode.NOT_FOUND,
                    "No such property: %s" % (encodeXMLName(*qname),)
                ))
            else:
                raise HTTPError(StatusResponse(
                    statusForFailure(Failure()),
                    "Unable to read property: %s" % (encodeXMLName(*qname),)
                ))

        #
        # Unserialize XML data from an xattr.  The storage format has changed
        # over time:
        #
        #  1- Started with XML
        #  2- Started compressing the XML due to limits on xattr size
        #  3- Switched to pickle which is faster, still compressing
        #  4- Back to compressed XML for interoperability, size
        #
        # We only write the current format, but we also read the old
        # ones for compatibility.
        # 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:50,代码来源:xattrprops.py

示例14: usage

# 需要导入模块: import xattr [as 别名]
# 或者: from xattr import xattr [as 别名]
def usage():
    """Display a usage summary."""
    print """Usage: timecopy.py [-hnvx] [--nochown] <source> <target>

Copies a Mac OS X Time Machine volume (set of backups) from one location
to another, such as from one disk to another, or from one disk image to
another. This can be useful when block copying the disk is not feasible
(i.e. the destination disk is smaller than the original).

The <source> location must be the root directory of the source Time
Machine volume, that which contains the 'Backups.backupdb' directory
(e.g. /Volumes/Backup, not /Volumes/Backup/Backups.backupdb/gojira).
You must have sufficient privileges to access this directory, and the
Time Machine volume must already be mounted (read-only mode is okay).

The <target> location should be the root of an empty volume to which the
Time Machine backups will be copied. You must have sufficient privileges
to write to this location. Chances are you will need to be using `sudo`
to gain the necessary privileges, unless -n or --dry-run is given.

-h|--help
\tPrints this usage information.

-n|--dry-run
\tDo not make any changes on disk.

--nochown
\tDo not use chown to change the owner/group of the destination
\tfiles. Generally only root can do that, and on network volumes
\tthe Mac will make everything owned by the 'unknown' user anyway.

-v|--verbose
\tPrints information about what the script is doing at each step.

-x|--xattr
\tCopies the extended attributes from the source volume to the target
\tvolume, assuming that the target is an exact copy of the source.
\tThis is useful if you have a copy of a Time Machine volume that is
\tmissing the necessary extended attributes. Normally this script
\twill already have copied the extended attributes as part of the
\tcopying process, so this option is only needed when you have created
\tthe copy using some other means.""" 
开发者ID:nlfiedler,项目名称:timedog,代码行数:44,代码来源:timecopy.py


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