luminal.tools.utils
Module Contents
Classes
Encapsulation of common operating system utilities. |
|
Contains a collection of text generation utilities such as random id and cid strings. |
- class SystemUtils
Encapsulation of common operating system utilities.
- windows = 'nt'
- linux = 'posix'
- macos = 'posix'
- cygwin = 'posix'
- static get_system()
Returns the name of the currently running operating system.
- Returns:
The name of the current system type.
- Return type:
- static get_system_delimiter()
Returns a delimiter character which is appropriate for the current operating system.
- Returns:
The delimiter used during parsing and concatenation of strings.
- Return type:
- static get_line(filepath)
Returns the first line of a provided file in a read-only fashion.
- static read_from_file(filepath)
Returns all data of a provided file in a read-only fashion.
- static write_to_file(filepath, data)
Writes all data to the provided file in a truncated fashion.
- static get_file_checksum(filename, block=2**20)
Generates a calculated
SHA512hash for a given file.- Parameters:
- Returns:
The calculated
SHA512hash of the file, orNoneif there was an error generating the checksum.- Return type:
Notes
This function generates a
SHA512hash for a given file by reading the file in blocks and hashing each block. The generated hash is a digest checksum (a unique fixed-sized representation of the file content). The file is treated as a binary file (read inrbmode) for proper handling of all types of files.The reason
SHA512was chosen is purely for the lack of collisions at runtime when performing dynamic checks.
- static is_submodule(parent, child)
Returns a flag if the compared child module is from the parent and contains a
{parent}.{child}path structure.
- async static continue_async(delay=sys.float_info.min)
|coro|Sleeps the thread for the least possible amount of time for the system in order to allow a function to be truly async and awaitable; or a specified time delay in seconds.
- Parameters:
delay (Optional[
float]) – The amount of time to sleep the thread.- Return type:
None
- class TextUtils
Contains a collection of text generation utilities such as random id and cid strings.
- static generate_id(length=10, use_sample=False)
Returns an alphanumeric identifier based on a given length and random sampling, if desired.
- Parameters:
length (Optional[
int]) – The length of the identifier to be generated.use_sample (Optional[
bool]) – Userandom.sample()instead ofsecrets.choice()on available characters.
- Returns:
The generated id of a specified length.
- Return type: