A FIFO folder management library that manages files using queue-like principles.
Project description
fifo_folder
A FIFO folder management library that manages files using queue-like principles.
Install
pip install fifo_folder
Example
Here's an example logger using fifo_folder
to limit the resources used by log files:
import os
from fifo_folder import FIFOFolder
LOG_DIR_PATH = "/path/to/your/log/folder/"
log_manager = FIFOFolder(
LOG_DIR_PATH, # path to the folder to manage
count_limit=100, # keep at most 100 files
total_size_limit=(1 << 30), # keep sum of file sizes no greater than 1GB
)
def log(file_name: str, text: str) -> None:
# create a new log file
file_path = os.path.join(LOG_DIR_PATH, file_name)
with open(file_path, "w") as file:
file.write(text)
log_manager.load_items() # load current files
removed_items = log_manager.manage() # removed extra files
if len(removed_items): # display removed files
print(
"removed log files:",
[os.path.basename(item.data.path) for item in removed_items]
)
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fifo_folder-0.1.1.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for fifo_folder-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 459b98611411f9c3f861126d41110f36bf02868b9d87a22c3139818e4f42dc73 |
|
MD5 | 595d5ce115db765bde7385087616028b |
|
BLAKE2b-256 | 490b8dcf7ef512ec018ab546d476609744d4e1c8e3313eed3ecff3bfaefd0d60 |