本文整理匯總了Python中xattr.setxattr方法的典型用法代碼示例。如果您正苦於以下問題:Python xattr.setxattr方法的具體用法?Python xattr.setxattr怎麽用?Python xattr.setxattr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xattr
的用法示例。
在下文中一共展示了xattr.setxattr方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [as 別名]
def main(self):
source_file = self.env['source_file']
destination_file = self.env["destination_file"]
# Check if we're trying to copy something inside a dmg.
(dmg_path, dmg, dmg_source_path) = self.parsePathForDMG(source_file)
try:
if dmg:
# Mount dmg and copy path inside.
mount_point = self.mount(dmg_path)
source_file = os.path.join(mount_point, dmg_source_path)
source_file = source_file.decode("string_escape")
destination_file = destination_file.decode("string_escape")
xattr.listxattr(source_file)
temp = xattr.getxattr(source_file, "com.apple.ResourceFork")
xattr.setxattr(destination_file, "com.apple.ResourceFork", temp)
self.output("Resource Fork copied")
except:
var = traceback.format_exc()
print(("ERROR:", var))
self.output("Resoruce Fork error: " + var)
finally:
if dmg:
self.unmount(dmg_path)
示例2: storeHeaders_
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [as 別名]
def storeHeaders_(self, headers):
'''Store dictionary data as an xattr for self.destination_path'''
plistData, error = (
NSPropertyListSerialization.
dataFromPropertyList_format_errorDescription_(
headers, NSPropertyListXMLFormat_v1_0, None))
if error:
byte_string = b''
else:
try:
byte_string = bytes(plistData)
except NameError:
byte_string = str(plistData)
try:
xattr.setxattr(self.destination_path, self.GURL_XATTR, byte_string)
except IOError as err:
self.log('Could not store metadata to %s: %s'
% (self.destination_path, err))
示例3: on_post
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [as 別名]
def on_post(self, req, resp):
client_common_name = req.get_param("client", required=True)
m = re.match("^(.*, )*CN=(.+?)(, .*)*$", client_common_name) # It's actually DN, resolve it to CN
if m:
_, client_common_name, _ = m.groups()
path, buf, cert, signed, expires = self.authority.get_signed(client_common_name) # TODO: catch exceptions
if req.get_param("serial") and cert.serial_number != req.get_param_as_int("serial"): # OCSP-ish solution for OpenVPN, not exposed for StrongSwan
logger.info("Gateway %s attempted to submit lease information for %s with expired/unknown serial %x, expected %x" % (
req.context["machine"], client_common_name,
req.get_param_as_int("serial"), cert.serial_number))
raise falcon.HTTPForbidden("Forbidden", "Invalid serial number supplied")
now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
xattr.setxattr(path, "user.lease.outer_address", req.get_param("outer_address", required=True).encode("ascii"))
xattr.setxattr(path, "user.lease.inner_address", req.get_param("inner_address", required=True).encode("ascii"))
xattr.setxattr(path, "user.lease.last_seen", now)
push.publish("lease-update", client_common_name)
server_common_name = req.context.get("machine")
path = os.path.join(config.SIGNED_DIR, server_common_name + ".pem")
xattr.setxattr(path, "user.lease.outer_address", "")
xattr.setxattr(path, "user.lease.inner_address", "%s" % req.context.get("remote_addr"))
xattr.setxattr(path, "user.lease.last_seen", now)
push.publish("lease-update", server_common_name)
# client-disconnect is pretty much unusable:
# - Android Connect Client results "IP packet with unknown IP version=2" on gateway
# - NetworkManager just kills OpenVPN client, disconnect is never reported
# - Disconnect is also not reported when uplink connection dies or laptop goes to sleep
示例4: xattr_writes_supported
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [as 別名]
def xattr_writes_supported(path):
"""
Returns True if the we can write a file to the supplied
path and subsequently write a xattr to that file.
"""
try:
import xattr
except ImportError:
return False
def set_xattr(path, key, value):
xattr.setxattr(path, "user.%s" % key, str(value))
# We do a quick attempt to write a user xattr to a temporary file
# to check that the filesystem is even enabled to support xattrs
fake_filepath = os.path.join(path, 'testing-checkme')
result = True
with open(fake_filepath, 'wb') as fake_file:
fake_file.write("XXX")
fake_file.flush()
try:
set_xattr(fake_filepath, 'hits', '1')
except IOError as e:
if e.errno == errno.EOPNOTSUPP:
result = False
else:
# Cleanup after ourselves...
if os.path.exists(fake_filepath):
os.unlink(fake_filepath)
return result
示例5: upgradeCalendarHome
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [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
示例6: createHierarchy
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [as 別名]
def createHierarchy(self, structure, root=None):
if root is None:
root = os.path.abspath(self.mktemp())
os.mkdir(root)
def createChildren(parent, subStructure):
for childName, childStructure in subStructure.iteritems():
if childName.startswith("@"):
continue
childPath = os.path.join(parent, childName)
if "@contents" in childStructure:
# This is a file
with open(childPath, "w") as child:
child.write(childStructure["@contents"])
else:
# This is a directory
os.mkdir(childPath)
createChildren(childPath, childStructure)
if "@xattrs" in childStructure:
xattrs = childStructure["@xattrs"]
for attr, value in xattrs.iteritems():
try:
xattr.setxattr(childPath, attr, value)
except IOError:
pass
# Set access and modified times
if "@timestamp" in childStructure:
timestamp = childStructure["@timestamp"]
os.utime(childPath, (timestamp, timestamp))
createChildren(root, structure)
return root
示例7: persist
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [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
示例8: setMacCreatorAndType
# 需要導入模塊: import xattr [as 別名]
# 或者: from xattr import setxattr [as 別名]
def setMacCreatorAndType(path, fileCreator, fileType):
if xattr is not None:
from fontTools.misc.textTools import pad
if not all(len(s) == 4 for s in (fileCreator, fileType)):
raise TypeError('arg must be string of 4 chars')
finderInfo = pad(bytesjoin([fileType, fileCreator]), 32)
xattr.setxattr(path, 'com.apple.FinderInfo', finderInfo)
if MacOS is not None:
MacOS.SetCreatorAndType(path, fileCreator, fileType)