本文整理匯總了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__)
示例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
示例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 = {}
示例4: attrs
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import xattr [as 別名]
def attrs(self):
return xattr(self.path.path)
示例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, {})
示例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
示例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)
示例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)
示例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)
示例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
示例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
示例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)
示例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.
#
示例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."""