auralib is mostly a way for me to reuse some functions I use a lot in my projects, and a learning exercise. Feel free to use these for your own projects if you want though.
-
Install Python 3.x
-
Open a command prompt window and enter:
pip install auralibrun_command() runs a command line command. Options to use shell and print output.
run_command(
command: str | list[str],
print_output: bool = False,
use_shell: bool = False
) -> Noneread_config() reads a configuration file in INI format and returns it as a dictionary, with data types formatted according to the first character of keys (b: boolean, d: dictionary, f: float, i: integer, l: list, o: set s: string, t: tuple). It allows you to use a variable value to start file paths at the current working directory; option keys must begin or end with specified strings. It also has options to preserve/ignore the case of keys, enable debug logging, and specify custom values for boolean and current working directory variables.
read_config(
file_path: str,
preserve_key_case: bool = False,
comment_prefixes: tuple[str] = (";", "#", "//"),
inline_comment_prefixes: tuple[str] = (";", "#", "//"),
root_dir_key: tuple[str] | str = ("PATH", "Path", "path"),
root_dir_value: str = "[ROOT]",
root_path: str | None = None,
bool_case_sens: bool = False,
bool_true: tuple[str] | str = ("TRUE", "True", "true", "T", "t", "1"),
bool_false: tuple[str] | str = ("FALSE", "False", "false", "F", "f", "0")
) -> dict[str, dict[str]]copy_file() copies a file from one path to another. You can optionally forcibly copy all possible metadata and overwrite an existing file.
copy_file(
source_path: str,
destination_path: str,
force_metadata: bool = False,
force_overwrite: bool = False
) -> Nonecopy_folder() copies a directory from one path to another. Optionally, you may forcibly copy all possible metadata and overwrite an existing directory.
copy_folder(
source_path: str,
destination_path: str,
force_metadata: bool = True,
force_overwrite: bool = False
) -> Nonedelete_file() deletes a file.
delete_file(
file_path: str | tuple[str]
) -> Nonedelete_folder() deletes a directory.
delete_folder(
file_path: str | tuple[str]
) -> Noneget_base_path() gets only the directory elements from a path to a file. Eg: c:\example\folders
get_base_path(
file_path: str
) -> strget_file_name() gets only the file element from a path. Includes the extension by default, but you can disable this. Eg: file.txt, file
get_file_name(
file_path: str
include_extension: bool = True
) -> strget_file_extension() gets only the file extension from a path to a file. Includes the . by default, but you can disable this. Eg: .txt, txt
get_file_extension(
file_path: str
include_dot: bool = True
) -> strget_files_with_extension() get a list of file paths of files with an extension.
get_files_with_extension(
file_path: str
extension: str | list[str] | tuple[str]
) -> list[str]get_root_path() gets the current working directory path.
get_root_path() -> strhas_extension() checks if a path or string ends with an extension or one of a list/tuple of extensions.
has_extension(
file_path: str,
extensions: str | list[str] | tuple[str]
) -> boolis_file() checks if a file exists at a path.
is_file(
file_path: str
) -> boolis_file_with_extension() checks in a file exists at a path and ends with an extension or one of a list/tuple of extensions.
is_file_with_extension(
file_path: str,
extensions: str | list[str] | tuple[str]
) -> boolis_folder() checks if a folder exists at a path.
is_folder(
file_path: str
) -> boolmove_files() moves a single file or a list/tuple of files into a specified folder. If moving a single file you can specify a file name, allowing renaming, however this is not supported with multiple files.
move_files(
source_path: str | list[str] | tuple[str],
destination_path: str,
force_overwrite: bool = False
) -> Nonemove_folders() moves a single folder or a list/tuple of folders into a specified folder.
move_folders(
source_path: str | list[str] | tuple[str],
destination_path: str
) -> Nonerename_file() renames a single file to a new name, including extension. Optionally, you may specify a full file path to move the file as well.
rename_file(
file_path: str,
new_name: str
) -> Nonerename_folder() renames a single folder to a new name. Optionally, you may specify a full file path to move the folder as well.
rename_folder(
file_path: str,
new_name: str
) -> Nonestrip_dot() removes the dot from the beginning of an extension string if it exists.
strip_dot(
extension: str | list[str] | tuple[str]
) -> str | list[str] | tuple[str]escape_json_string() replaces common dangerous characters in a string with their json-escaped equivalents, allowing them to be used in json files.
escape_json_string(
string: str
) -> stris_bethesda_plugin() checks if a string ends in .esp, .esm, or .esl. By default it also checks if the string is a path to a file.
is_bethesda_plugin(
file_path: str,
check_if_file: bool = True
) -> boollowercase() turns a string or list of strings to lowercase.
lowercase(
string: str | list[str] | tuple[str] | set[str] | dict[str, str]
) -> strread_from_file() reads from a text file.
read_from_file(
file_path: str,
encoding: str = "utf-8"
) -> strwrite_to_file() writes to a text file.
write_to_file(
file_path: str,
text: str = "",
encoding: str = "utf-8"
) -> Noneget_type() gets the type of some data and returns it as a string.
get_type(
data: any
) -> strstr_to_bool() turns a string into a boolean. Uses a list of values to consider as true/false that you can optionally override.
str_to_bool(
string: str,
case_sensitive: bool = False,
true_values: list[str] | tuple[str] | str = ("TRUE", "True", "true", "T", "t", "1"),
false_values: list[str] | tuple[str] | str = ("FALSE", "False", "false", "F", "f", "0")
) -> boolstr_to_dict() turns a string into a dictionary.
str_to_dict(
string: str
) -> boolstr_to_float() turns a string into a float.
str_to_float(
string: str
) -> boolstr_to_int() turns a string into a integer.
str_to_int(
string: str
) -> boolstr_to_list() turns a string into a list.
str_to_list(
string: str
) -> boolstr_to_set() turns a string into a set.
str_to_set(
string: str
) -> boolstr_to_tuple() turns a string into a tuple.
str_to_tuple(
string: str
) -> boolescape_xml_string() replaces common dangerous characters in a string with their xml-escaped equivalents, allowing them to be used in xml files.
escape_xml_string(
string: str,
fomod: bool = False
) -> str