• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Review Bot 4.x
    2. Version 4.x
    3. Version 3.0
    4. Version 2.0
    5. Version 1.0
    6. Module and Class Reference
    7. reviewbot.utils.filesystem
  • Home
  • Installation
  • Manually Installing Review Bot
  • Review Bot Docker Images
  • Upgrading Review Bot
  • Configuring Review Bot
  • Review Bot Tools
  • Cargo Tool
  • Checkstyle
  • Clang Static Analyzer
  • Cppcheck
  • Cpplint
  • Doc8
  • FBInfer
  • Flake8
  • Go Fmt
  • Go Tool
  • JSHint
  • PMD
  • Pycodestyle
  • Pydocstyle
  • Pyflakes
  • RuboCop
  • Rust Fmt
  • Secret Scanner
  • ShellCheck
  • Module and Class Reference
  • reviewbot.tools.base
  • reviewbot.tools.base.mixins
  • reviewbot.tools.base.registry
  • reviewbot.tools.base.tool
  • reviewbot.testing.testcases
  • reviewbot.testing.utils
  • reviewbot.tools.testing
  • reviewbot.tools.testing.decorators
  • reviewbot.tools.testing.testcases
  • reviewbot.processing.review
  • reviewbot.utils.api
  • reviewbot.utils.filesystem
  • reviewbot.utils.log
  • reviewbot.utils.process
  • reviewbot.utils.text
  • reviewbot.celery
  • reviewbot.config
  • reviewbot.deprecation
  • reviewbot.errors
  • reviewbot.repositories
  • reviewbot.tasks
  • reviewbot.tools.cargotool
  • reviewbot.tools.checkstyle
  • reviewbot.tools.clang
  • reviewbot.tools.cppcheck
  • reviewbot.tools.cpplint
  • reviewbot.tools.doc8
  • reviewbot.tools.fbinfer
  • reviewbot.tools.flake8
  • reviewbot.tools.gofmt
  • reviewbot.tools.gotool
  • reviewbot.tools.jshint
  • reviewbot.tools.pmd
  • reviewbot.tools.pycodestyle
  • reviewbot.tools.pydocstyle
  • reviewbot.tools.pyflakes
  • reviewbot.tools.rbsecretscanner
  • reviewbot.tools.rubocop
  • reviewbot.tools.rustfmt
  • reviewbot.tools.shellcheck
  • General Index
  • Python Module Index
  • Release Notes
  • reviewbot.utils.filesystem¶

    Utilities for filesystem operations and path normalization.

    Functions

    chdir(path)

    Temporarily change directory into the given working directory.

    cleanup_tempfiles()

    Clean up all temporary files.

    ensure_dirs_exist(path)

    Ensure directories exist to an absolute path.

    get_path_platform(path)

    Return the platform most likely used to generate a path.

    make_tempdir()

    Create a temporary directory and return the path.

    make_tempfile([content, extension])

    Create a temporary file and return the path.

    normalize_platform_path(path[, relative_to, ...])

    Normalize a path from a diff, making it suitable for local use.

    Classes

    PathPlatform(value[, names, module, ...])

    The platform used to generate a filesystem path.

    class PathPlatform(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶

    Bases: Enum

    The platform used to generate a filesystem path.

    New in version 3.0.

    WINDOWS = 'win'[source]¶

    A DOS/Windows path.

    POSIX = 'posix'[source]¶

    A POSIX path.

    LOCAL = 'posix'¶
    property path_mod[source]¶

    The path module used to work with paths of this type.

    Returns:

    The path module (either ntpath or posixpath).

    Return type:

    module

    chdir(path)[source]¶

    Temporarily change directory into the given working directory.

    Parameters:

    path (str) – The directory to operate within.

    cleanup_tempfiles()[source]¶

    Clean up all temporary files.

    This will delete all the files created by make_tempfile().

    make_tempfile(content=None, extension='')[source]¶

    Create a temporary file and return the path.

    Parameters:
    • content (bytes, optional) – Optional content to put in the file.

    • extension (str, optional) – An optional file extension to add to the end of the filename.

    Returns:

    The name of the new file.

    Return type:

    str

    make_tempdir()[source]¶

    Create a temporary directory and return the path.

    Returns:

    The name of the new directory.

    Return type:

    str

    ensure_dirs_exist(path)[source]¶

    Ensure directories exist to an absolute path.

    Parameters:

    path (str) – The absolute path for which directories should be created if they don’t exist.

    Raises:
    • ValueError – If the path is not absolute.

    • OSError – If making the directory failed.

    get_path_platform(path)[source]¶

    Return the platform most likely used to generate a path.

    This supports Windows and POSIX filesystem and UNC paths.

    New in version 3.0.

    Parameters:

    path (str) – The Windows or POSIX path.

    Returns:

    The platform that the path is most likely for.

    Return type:

    PathPlatform

    normalize_platform_path(path, relative_to=None, target_platform=PathPlatform.POSIX)[source]¶

    Normalize a path from a diff, making it suitable for local use.

    This will convert either a Windows or POSIX path to the local platform, collapsing any relative components (such as ..) within, and then making the result relative.

    The path can optionally be joined to a path specified in relative_to.

    New in version 3.0.

    Parameters:
    • path (str) – The path to normalize.

    • relative_to (str, optional) – An optional directory that the normalized path should be joined to.

    • target_platform (PathPlatform, optional) – The target platform for the normalized path. This is mostly for unit testing purposes.

    Returns:

    The resulting normalized path.

    Return type:

    str

    Raises:

    reviewbot.errors.SuspiciousFilePath – The resulting normalized file path is suspicious. It would have resulted in access outside the source tree.

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • PathPlatform
      • PathPlatform.WINDOWS
      • PathPlatform.POSIX
      • PathPlatform.LOCAL
      • PathPlatform.path_mod
    • chdir()
    • cleanup_tempfiles()
    • make_tempfile()
    • make_tempdir()
    • ensure_dirs_exist()
    • get_path_platform()
    • normalize_platform_path()