z.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:xontrib-z 作者: astronouth7303 项目源码 文件源码
def save_data(self, data):
        # Age data
        if hasattr(data, '__len__') and len(data) > self.GROOM_THRESHOLD:
            for i, e in enumerate(data):
                data[i] = ZEntry(e.path, int(e.rank * self.GROOM_LEVEL), e.time)

        # Use a temporary file to minimize time the file is open and minimize clobbering
        from tempfile import NamedTemporaryFile
        with NamedTemporaryFile('wt', encoding=sys.getfilesystemencoding()) as f:
            for e in data:
                f.write("{}|{}|{}\n".format(e.path, int(e.rank), int(e.time.timestamp())))
            f.flush()

            if self.Z_OWNER:
                shutil.chown(f.name, user=self.Z_OWNER)

            # On POSIX, rename() is atomic and will clobber
            # On Windows, neither of these is true, so remove first.
            from xonsh.platform import ON_WINDOWS
            if ON_WINDOWS and os.path.exists(self.Z_DATA):
                os.remove(self.Z_DATA)
            shutil.copy(f.name, self.Z_DATA)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号