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.0.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for fifo_folder-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caccf4117d670e3fcda979f83bb42868a18079a1db0107e6993314dbc4336094 |
|
MD5 | 118abbf51744ea64d1ae938ec9950230 |
|
BLAKE2b-256 | 319b0e1d3ee89952fce92dadb0e72254b15cad8630e23497f2c06150988eadf5 |