ocrd_utils.os module

Operating system functions.

ocrd_utils.os.abspath(url: str) str[source]

Get a full path to a file or file URL

See os.abspath

ocrd_utils.os.directory_size(path: str | PathLike) int[source]

Calculates size of all files in directory path

ocrd_utils.os.is_file_in_directory(directory: str | PathLike, file: str | PathLike) bool[source]

Return True if file is in directory (by checking that all components of directory are in file.parts)

ocrd_utils.os.is_git_url(url: str) bool[source]
ocrd_utils.os.get_ocrd_tool_json(executable: str) Dict[str, Any][source]

Get the ocrd-tool description of executable.

ocrd_utils.os.get_moduledir(executable: str) str[source]
ocrd_utils.os.get_processor_resource_types(executable: str, ocrd_tool: Dict[str, Any] | None = None) List[str][source]

Determine what type of resource parameters a processor needs.

Return a list of MIME types (with the special value */* to designate that arbitrary files or directories are allowed).

ocrd_utils.os.get_env_locations(executable: str) List[str][source]
ocrd_utils.os.guess_media_type(input_file: str, fallback: str | None = None, application_xml: str = 'application/xml') str[source]

Guess the media type of a file path

ocrd_utils.os.pushd_popd(newcwd: str | PathLike = None, tempdir: bool = False) Iterator[PathLike][source]
ocrd_utils.os.unzip_file_to_dir(path_to_zip: str | PathLike, output_directory: str) None[source]

Extract a ZIP archive to a directory

ocrd_utils.os.atomic_write(fpath: str) Iterator[str][source]
ocrd_utils.os.redirect_stderr_and_stdout_to_file(filename)[source]