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


Python os.truncate方法代码示例

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


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

示例1: truncate

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def truncate(self, path, length, fh=None):
        realpath = self.remotepath(path)
        cachefile = self.cachefile(realpath)
        if not os.path.exists(cachefile):
            if self.empty_file(realpath):
                self.create(path, 'wb')
            else:
                raise FuseOSError(ENOENT)

        status = os.truncate(cachefile, length)
        self.logger.info(self.extract(os.lstat(cachefile)))
        self.attributes.insert(realpath, self.extract(os.lstat(cachefile)))
        task = Task(xxhash.xxh64(realpath).intdigest(),
                    self._truncate, realpath, length)
        self.taskpool.submit(task)
        return status 
开发者ID:RainMark,项目名称:oxfs,代码行数:18,代码来源:oxfs.py

示例2: create_image

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def create_image(args: CommandLineArguments, root: str, for_cache: bool) -> Optional[BinaryIO]:
    if not args.output_format.is_disk():
        return None

    with complete_step('Creating partition table',
                       'Created partition table as {.name}') as output:

        f: BinaryIO = cast(BinaryIO, tempfile.NamedTemporaryFile(prefix='.mkosi-', delete=not for_cache,
                                                                 dir=os.path.dirname(args.output)))
        output.append(f)
        disable_cow(f.name)
        f.truncate(image_size(args))

        table, run_sfdisk = determine_partition_table(args)

        if run_sfdisk:
            run(["sfdisk", "--color=never", f.name], input=table.encode("utf-8"), check=True)
            run(["sync"])

        args.ran_sfdisk = run_sfdisk

    return f 
开发者ID:systemd,项目名称:mkosi,代码行数:24,代码来源:mkosi.py

示例3: make_minimal_ext4

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def make_minimal_ext4(args: CommandLineArguments, root: str, for_cache: bool) -> Optional[BinaryIO]:
    if args.output_format != OutputFormat.gpt_ext4:
        return None
    if not args.minimize:
        return None
    if for_cache:
        return None

    with complete_step('Creating ext4 root file system'):
        f: BinaryIO = cast(BinaryIO, tempfile.NamedTemporaryFile(prefix=".mkosi-mkfs-ext4",
                                                                 dir=os.path.dirname(args.output)))
        f.truncate(args.root_size)
        run(["mkfs.ext4", "-I", "256", "-L", "root", "-M", "/", "-d", root, f.name], check=True)

    with complete_step('Minimizing ext4 root file system'):
        run(["resize2fs", "-M", f.name])

    return f 
开发者ID:systemd,项目名称:mkosi,代码行数:20,代码来源:mkosi.py

示例4: make_minimal_btrfs

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def make_minimal_btrfs(args: CommandLineArguments, root: str, for_cache: bool) -> Optional[BinaryIO]:
    if args.output_format != OutputFormat.gpt_btrfs:
        return None
    if not args.minimize:
        return None
    if for_cache:
        return None

    with complete_step('Creating minimal btrfs root file system'):
        f: BinaryIO = cast(BinaryIO, tempfile.NamedTemporaryFile(prefix=".mkosi-mkfs-btrfs",
                                                                 dir=os.path.dirname(args.output)))
        f.truncate(args.root_size)

        command = ["mkfs.btrfs", "-L", "root", "-d", "single", "-m", "single", "--shrink", "--rootdir", root, f.name]
        try:
            run(command, check=True)
        except subprocess.CalledProcessError as e:
            # The --shrink option was added in btrfs-tools 4.14.1, before that it was the default behaviour.
            # If the above fails, let's see if things work if we drop it
            command.remove("--shrink")
            run(command, check=True)

    return f 
开发者ID:systemd,项目名称:mkosi,代码行数:25,代码来源:mkosi.py

示例5: _truncate

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def _truncate(self, thread_local_data, path, length):
        self.logger.info('sftp truncate {}'.format(path))
        sftp = self.current_thread_sftp(thread_local_data)
        return sftp.truncate(path, length) 
开发者ID:RainMark,项目名称:oxfs,代码行数:6,代码来源:oxfs.py

示例6: test_ftruncate

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def test_ftruncate(self):
        self.check(os.truncate, 0)
        self.check(os.ftruncate, 0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_os.py

示例7: create_internal_disk

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def create_internal_disk(self):
        """Create a internal-image*.wic in the resultdir that runqemu can use."""
        copyfile(os.path.join(self.image_dir, 'refkit-installer-image-%s.qemuboot.conf' % self.image_arch),
                 os.path.join(self.resultdir, 'internal-image-%s.qemuboot.conf' % self.image_arch))
        for ovmf in glob('%s/ovmf*' % self.image_dir):
            os.symlink(ovmf, os.path.join(self.resultdir, os.path.basename(ovmf)))
        with open(os.path.join(self.resultdir, 'internal-image-%s.wic' % self.image_arch), 'w') as f:
            # empty, sparse file of 8GB
            os.truncate(f.fileno(), 8 * 1024 * 1024 * 1024) 
开发者ID:intel,项目名称:intel-iot-refkit,代码行数:11,代码来源:image_installer.py

示例8: TODO_i18n_fetch_error

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def TODO_i18n_fetch_error(output_path: Path, message: str):
    os.truncate(output_path, 0)
    return [I18nMessage("TODO_i18n", {"text": message}, None)] 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:5,代码来源:googlesheets.py

示例9: _truncate

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def _truncate(path, length):
    fd = os.open(path, os.O_RDWR)
    try:
        os.truncate(fd, length)
    finally:
        os.close(fd) 
开发者ID:dw,项目名称:mitogen,代码行数:8,代码来源:mitogen-fuse.py

示例10: truncate

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def truncate(self, path, length, fh=None):
        path = path.decode(self.encoding)
        _evil_name(path)
        return errno_call(self._context, _truncate, path, length) 
开发者ID:dw,项目名称:mitogen,代码行数:6,代码来源:mitogen-fuse.py

示例11: do_download

# 需要导入模块: import os [as 别名]
# 或者: from os import truncate [as 别名]
def do_download(
    sheet_id: str, sheet_mime_type: str, oauth2_client: oauth2.Client, output_path: Path
) -> List[I18nMessage]:
    """
    Download spreadsheet from Google.

    If `sheet_mime_type` is 'application/vnd.google-apps.spreadsheet', use
    GDrive API to _export_ a text/csv. Otherwise, use GDrive API to _download_
    the file.
    """
    if sheet_mime_type == "application/vnd.google-apps.spreadsheet":
        url = _generate_google_sheet_url(sheet_id)
        sheet_mime_type = "text/csv"
    else:
        url = _generate_gdrive_file_url(sheet_id)
        # and use the passed sheet_mime_type

    url, headers, _ = oauth2_client.add_token(url, headers={})

    try:
        await httpfile.download(url, output_path, headers=headers, ssl=SSL_CONTEXT)
    except HttpError.NotSuccess as err:
        response = err.response
        if response.status_code == 401:
            return TODO_i18n_fetch_error(
                output_path, "Invalid credentials. Please reconnect to Google Drive."
            )
        elif response.status_code == 403:
            return TODO_i18n_fetch_error(
                output_path,
                "You chose a file your logged-in user cannot access. Please reconnect to Google Drive or choose a different file.",
            )
        elif response.status_code == 404:
            return TODO_i18n_fetch_error(
                output_path, "File not found. Please choose a different file."
            )
        else:
            return [err.i18n_message]
    except HttpError as err:
        # HACK: *err.i18n_message because i18n_message is a tuple
        # compatible with I18nMessage() ctor
        os.truncate(output_path, 0)
        return [err.i18n_message]

    return [] 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:47,代码来源:googlesheets.py


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