From fcc8761105613804f150d1bfc8d72531e79f53fe Mon Sep 17 00:00:00 2001 From: cehune Date: Thu, 26 Sep 2024 20:58:49 +0000 Subject: [PATCH 1/2] update requirements update requirements update requirements update file_expiry scripts update scripts update scripts update scripts --- pyproject.toml | 4 +++- requirements.txt | 2 +- src/file_auto_expiry/main.py | 2 ++ src/file_auto_expiry/utils/expiry_checks.py | 10 ++++------ src/file_auto_expiry/utils/interface.py | 9 +++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 944130f..cfc7455 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,9 @@ classifiers = [ "Topic :: Software Development :: Build Tools", "Programming Language :: Python :: 3", ] - +dependencies = [ + "typer>=0.9.0" +] [tool.setuptools] package-dir = {""= "src"} diff --git a/requirements.txt b/requirements.txt index ffe491a..358d846 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -typer>=0.12.3 +typer>=0.9.0 diff --git a/src/file_auto_expiry/main.py b/src/file_auto_expiry/main.py index c43be1c..1e2934b 100644 --- a/src/file_auto_expiry/main.py +++ b/src/file_auto_expiry/main.py @@ -13,6 +13,8 @@ def collect_file_info(path: str, save_file: str = "", days_for_expiry: int = 10) scrape_time = time.time() seconds_for_expiry = int(days_for_expiry) * SECS_PER_DAY expiry_threshold = scrape_time - seconds_for_expiry + print(seconds_for_expiry) + print(expiry_threshold) collect_expired_file_information(folder_path=path, save_file=save_file, scrape_time=scrape_time, diff --git a/src/file_auto_expiry/utils/expiry_checks.py b/src/file_auto_expiry/utils/expiry_checks.py index 69b0eb1..10e868f 100644 --- a/src/file_auto_expiry/utils/expiry_checks.py +++ b/src/file_auto_expiry/utils/expiry_checks.py @@ -52,20 +52,19 @@ def is_expired_filepath(path, file_stat, expiry_threshold): # If all atime, ctime, mtime are more than the expiry date limit, # then this return true, along with the other information return expiry_tuple( - is_expired=timestamps_are_expired(atime, ctime, mtime, + is_expired=timestamps_are_expired(ctime, mtime, expiry_threshold), creators={creator}, atime=atime, ctime=ctime, mtime=mtime) -def timestamps_are_expired(atime, ctime, mtime, expiry_threshold): +def timestamps_are_expired(ctime, mtime, expiry_threshold): """ Checks if all atime, ctime, and mtime are expired. Returns True when all are expired. """ - return ((atime < expiry_threshold) and - (ctime < expiry_threshold) and + return ((ctime < expiry_threshold) and (mtime < expiry_threshold)) def is_expired_link(path, file_stat, expiry_threshold): @@ -98,8 +97,7 @@ def is_expired_folder(folder_path, folder_stat, expiry_threshold): recent_mtime = folder_stat.st_mtime folder_creator = get_file_creator(folder_path) file_creators.add(folder_creator) - is_expired_flag = timestamps_are_expired(recent_atime, - recent_ctime, + is_expired_flag = timestamps_are_expired(recent_ctime, recent_mtime, expiry_threshold) diff --git a/src/file_auto_expiry/utils/interface.py b/src/file_auto_expiry/utils/interface.py index c180bb5..5d2d981 100644 --- a/src/file_auto_expiry/utils/interface.py +++ b/src/file_auto_expiry/utils/interface.py @@ -80,14 +80,15 @@ def collect_expired_file_information(folder_path, save_file, scrape_time, expiry "mtime_datetime": str(datetime.datetime.fromtimestamp(mtime)), }} - write_jsonl_information(path_info, save_file, scrape_time) + write_jsonl_information(path_info, save_file, scrape_time, expiry_threshold) -def write_jsonl_information(dict_info, file_path, scrape_time): +def write_jsonl_information(dict_info, file_path, scrape_time, expiry_threshold): current_time = time.time() with open(file_path, "w") as file: file.write(json.dumps({"scrape_time:": scrape_time, - "scrape_time_datetime": str(datetime.datetime.fromtimestamp(scrape_time))}) + "\n") + "scrape_time_datetime": str(datetime.datetime.fromtimestamp(scrape_time)), + "expiry_threshold": expiry_threshold}), + "\n") file.write(json.dumps({"time_for_scrape_sec": current_time - scrape_time, "time_for_scrape_min": (current_time - scrape_time) / 60}) + "\n") @@ -138,4 +139,4 @@ def collect_creator_information(path_info_file, save_file, scrape_time): "uid": user[1], "gid": user[2]} - write_jsonl_information(creator_info, save_file, scrape_time) + write_jsonl_information(creator_info, save_file, scrape_time, "") From 21ef3a2b2f7c9788e7e8216b96ee0e10d31fe66f Mon Sep 17 00:00:00 2001 From: cehune Date: Wed, 9 Oct 2024 01:51:07 +0000 Subject: [PATCH 2/2] update main --- src/file_auto_expiry/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/file_auto_expiry/main.py b/src/file_auto_expiry/main.py index 1e2934b..c43be1c 100644 --- a/src/file_auto_expiry/main.py +++ b/src/file_auto_expiry/main.py @@ -13,8 +13,6 @@ def collect_file_info(path: str, save_file: str = "", days_for_expiry: int = 10) scrape_time = time.time() seconds_for_expiry = int(days_for_expiry) * SECS_PER_DAY expiry_threshold = scrape_time - seconds_for_expiry - print(seconds_for_expiry) - print(expiry_threshold) collect_expired_file_information(folder_path=path, save_file=save_file, scrape_time=scrape_time,