alogos._utilities.operating_system

Functions

ensure_file_extension(filepath, extension)

Ensure that a filepath ends with a given extension.

delete_file(filepath)

Delete a file.

ensure_new_path(path)

Check whether a given path exists. If yes, try to find a novel, incremented variant of it.

create_directory(dirpath)

Given a directory path, create it and all necessary parent directories.

open_in_webbrowser(html_text, start_delay=0.1, stop_delay_fast=0.25, stop_delay_slow=10.0)

Open the given HTML text in the default webbrowser.

Attributes

NEWLINE


Detailed object descriptions

alogos._utilities.operating_system.NEWLINE
alogos._utilities.operating_system.ensure_file_extension(filepath, extension)[source]

Ensure that a filepath ends with a given extension.

References

alogos._utilities.operating_system.delete_file(filepath)[source]

Delete a file.

References

alogos._utilities.operating_system.ensure_new_path(path)[source]

Check whether a given path exists. If yes, try to find a novel, incremented variant of it.

Caution: Not threadsafe.

Examples

  • If some_dir exists, it becomes some_dir_1.mp3, then some_dir_2.mp3, …

  • If some_file exists, it becomes some_file_1, then some_file_2, …

  • If some_file.mp3 exists, it becomes some_file_1.mp3, then some_file_2.mp3, …

  • If x_1.y_2.z.txt exists, it becomes x_1.y_2.z_1.txt, then x_1.y_2.z_2.txt, …

alogos._utilities.operating_system.create_directory(dirpath)[source]

Given a directory path, create it and all necessary parent directories.

Do nothing if the directory already exists.

References

alogos._utilities.operating_system.open_in_webbrowser(html_text, start_delay=0.1, stop_delay_fast=0.25, stop_delay_slow=10.0)[source]

Open the given HTML text in the default webbrowser.

A short-lived local HTTP server is created that serves HTML text, so that it can be opened in the default webbrowser. An alternative would be to write the HTML text to a temporary file and open this file in the webbrowser.

Parameters:
  • html_text (str)

  • start_delay (float) – Delay between starting the server and opening the webbrowser in another thread. If too short, the webbrowser might send the request before the server is running.

  • stop_delay_fast (float) – Delay between opening the webbrowser (or a new tab) and shutting down the server after it received the first GET request from the browser.

  • stop_delay_slow (float) – Delay between opening the webbrowser (or a new tab) and shutting down the server even if it never receives a GET request, e.g. because the browser does not open.

References