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


Python xattr.setxattr方法代码示例

本文整理汇总了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) 
开发者ID:autopkg,项目名称:novaksam-recipes,代码行数:26,代码来源:ResourceForkCopier.py

示例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)) 
开发者ID:macadmins,项目名称:installapplications,代码行数:20,代码来源:gurl.py

示例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 
开发者ID:laurivosandi,项目名称:certidude,代码行数:32,代码来源:lease.py

示例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 
开发者ID:openstack,项目名称:searchlight,代码行数:33,代码来源:utils.py

示例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 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:41,代码来源:upgrade.py

示例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 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:38,代码来源:util.py

示例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 
开发者ID:MetPX,项目名称:sarracenia,代码行数:32,代码来源:sr_xattr.py

示例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) 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:11,代码来源:macCreatorType.py


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