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


Python TempFS.open方法代码示例

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


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

示例1: snapshot

# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import open [as 别名]
    def snapshot(self, path):
        """Takes a snapshot of an individual file."""

        # try grabbing the temp filesystem system path
        temp_dir = None
        temp_dir = self.tmp.getsyspath('/')

        # Create a temp file system to be snapshotted
        temp_snapshot_fs = TempFS(temp_dir=temp_dir)
        src_path = temp_snapshot_fs.getsyspath('/')

        with self.fs.open(path, 'rb') as source_file:
            with temp_snapshot_fs.open('datafile', 'wb') as temp_file:
                shutil.copyfileobj(source_file, temp_file)

        # snapshot destination directory
        dest_dir = self.snapshot_snap_path(path)

        command = ['rdiff-backup',
                   '--parsable-output',
                   '--no-eas',
                   '--no-file-statistics',
                   '--no-acls',
                   '--tempdir', self.tmp.getsyspath('/'),
                   src_path, dest_dir]

        # speed up the tests
        if self.__testing:
            command.insert(5, '--current-time')
            command.insert(6, str(self.__testing['time']))
            self.__testing['time'] += 1

        process = Popen(command, stdout=PIPE, stderr=PIPE)
        stderr = process.communicate()[1]

        ignore = [lambda x: x.startswith("Warning: could not determine case")]

        if len(stderr) is not 0:
            for rule in ignore:
                if not rule(stderr):
                    raise SnapshotError(stderr)

        # close the temp snapshot filesystem
        temp_snapshot_fs.close()
开发者ID:pombreda,项目名称:file-versioning,代码行数:46,代码来源:__init__.py

示例2: run_install

# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import open [as 别名]
    def run_install(self):
        args = self.args
        console = self.console
        installed = []
        install_package = args.package

        install_select = package_select = self.call('package.select', package=install_package)
        install_notes = package_select['notes']

        if package_select['version'] is None:
            raise CommandError("no install candidate for '{}', run 'moya-pm list' to see available packages".format(install_package))

        package_name = package_select['name']
        install_version = versioning.Version(package_select['version'])

        filename = package_select['md5']
        download_url = package_select['download']
        package_filename = download_url.rsplit('/', 1)[-1]

        libs = []
        output_fs = fsopendir(args.output)
        force = args.force

        installed_libs = {}

        archive = None
        if not args.download:
            try:
                application = WSGIApplication(self.location, args.settings, disable_autoreload=True)
                archive = application.archive
                if archive is None:
                    console.text('unable to load project, use the --force switch to force installation')
                    return -1
            except Exception as e:
                if not args.force:
                    console.exception(e)
                    console.text('unable to load project, use the --force switch to force installation')
                    return -1
            else:
                libs = [(lib.long_name, lib.version, lib.install_location)
                        for lib in archive.libs.values() if lib.long_name == package_name]

                installed_libs = archive.libs.copy()

                if not force:
                    for name, version, location in libs:
                        if name == package_name:
                            if version > install_version:
                                if not args.force:
                                    raise CommandError("a newer version ({}) is already installed, use --force to force installation".format(version))
                            elif install_version == version:
                                if not args.force:
                                    raise CommandError("version {} is already installed, use --force to force installation".format(version))
                            else:
                                if not args.upgrade:
                                    raise CommandError("an older version ({}) is installed, use --upgrade to force upgrade".format(version))
                            force = True

        username = self.settings.get('upload', 'username', None)
        password = self.settings.get('upload', 'password', None)
        if username and password:
            auth = (username, password)
        else:
            auth = None

        install_app = args.app or package_name.split('.')[-1]
        packages = dependencies.gather_dependencies(self.rpc,
                                                    install_app,
                                                    args.mount,
                                                    install_package,
                                                    console,
                                                    no_deps=args.no_deps)

        if not args.no_add:
            for package_name, (app_name, mount, package_select) in packages.items():
                if package_select['version'] is None:
                    raise CommandError("no install candidate for required package '{}', run 'moya-pm list {}' to see available packages".format(package_name, package_name))

        download_temp_fs = TempFS()
        for package_name, (app_name, mount, package_select) in packages.items():

            package_name = package_select['name']
            install_version = versioning.Version(package_select['version'])

            filename = "{}-{}.{}".format(package_name, install_version, package_select['md5'])
            download_url = package_select['download']
            package_filename = download_url.rsplit('/', 1)[-1]

            with download_temp_fs.open(filename, 'wb') as package_file:
                checksum = downloader.download(download_url,
                                               package_file,
                                               console=console,
                                               auth=auth,
                                               verify_ssl=False,
                                               msg="requesting {name}=={version}".format(**package_select))
                if checksum != package_select['md5']:
                    raise CommandError("md5 checksum of download doesn't match server! download={}, server={}".format(checksum, package_select['md5']))

            if args.download:
                with fsopendir(args.download) as dest_fs:
#.........这里部分代码省略.........
开发者ID:chrmorais,项目名称:moya,代码行数:103,代码来源:moyapi.py


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