Skip to content

Commit

Permalink
Collect info on the num of days since last usage (#18)
Browse files Browse the repository at this point in the history
This will be useful when checking whether a path is fully expired or
only expiring soon when we're sending emails.
  • Loading branch information
cehune authored Feb 5, 2025
1 parent e326bb8 commit cef3c2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "file_auto_expiry"
version = "0.0.10"
version = "0.0.11"
description = "WATCloud project containing scripts to check if directories / files are expired"
readme = "README.md"
requires-python = ">=3.7, <4"
Expand Down
10 changes: 4 additions & 6 deletions src/file_auto_expiry/utils/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ def get_file_creator(path):
return f"user{os.stat(path).st_uid}"
return creator_tuple(username, os.stat(path).st_uid, os.stat(path).st_gid)

def notify_file_creators():
"""
TODO: implement proper notification system
Currently is just the code to print information to a text file
"""

def scan_folder_for_expired(folder_path, expiry_threshold, check_folder_atime):
"""Generator function which iterates the expired top level folders
Expand Down Expand Up @@ -72,7 +67,9 @@ def collect_expired_file_information(folder_path, save_file, scrape_time, expiry
for path, is_expired, creators, atime, ctime, mtime in scan_folder_for_expired(
folder_path, expiry_threshold, check_folder_atime):
# handles generating the dictionary

oldest_time = min(datetime.datetime.fromtimestamp(atime), datetime.datetime.fromtimestamp(ctime));
oldest_time = min(oldest_time, datetime.datetime.fromtimestamp(mtime))
days_unused = (datetime.datetime.now() - oldest_time).days
path_info[path] = {
"path": path, # storing pathname so we keep it when we transfer the dictionary to jsonl
"creators": [creator for creator in creators if isinstance(creator[1], int) and creator[1] > 0 and creator[1] == creator[2]],
Expand All @@ -81,6 +78,7 @@ def collect_expired_file_information(folder_path, save_file, scrape_time, expiry
"atime_datetime": str(datetime.datetime.fromtimestamp(atime)),
"ctime_datetime": str(datetime.datetime.fromtimestamp(ctime)),
"mtime_datetime": str(datetime.datetime.fromtimestamp(mtime)),
"days_unused": days_unused
}}

write_jsonl_information(path_info, save_file, scrape_time, expiry_threshold, overwrite_file=overwrite_file)
Expand Down

0 comments on commit cef3c2c

Please sign in to comment.