From fd7aca764046cee40fa8be1f196807e3126e2fed Mon Sep 17 00:00:00 2001 From: cehune Date: Wed, 26 Jun 2024 22:43:33 +0000 Subject: [PATCH] Update Readme --- README.md | 50 +++++++++++++++++++++++++++++++++++---- source/utils/interface.py | 3 +-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 94a99ed..0ecfb43 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,56 @@ # infra_file_auto_expiry +### Requirement +This project requires sudo priveleges to run +## Purpose Relating to issue: https://github.com/WATonomous/infra-config/issues/1143 This project is meant to help automatically expire and delete files. It's currently at the stage of gathering all necessary information about file deletion easier. In the future, it is required to add a notification system for users whose files are to be deleted, and an actual deletion system. Currently it moves through every single top level folder in a directory, and checks whether it is expired or not. This means that every single file in that directory tree must be expired. As it does this, it gathers all the users who created files in that directory, and the days since the most RECENT atime, ctime, and mtime of ANY file in that directory. It only collects these for folders which have been confirmed to be expired. -To collect the expiry information of all top level directories in a given path: -sudo $(which python3) /path_to_directory/infra_file_auto_expiry/infra_file_auto_expiry/source/main.py collect-file-info path_to_check_expiry_of +## Usage +There are two commands currently, which are associated with the first two stages of the project. +1. collect-file-info +2. collect-creator-info -This will return a jsonl file. You can then use this in the following command to tabulate all expired paths that are associated with a particular user. +### To collect the expiry information of all top level directories in a given path: +``` +sudo $(which python3) /path_to_directory/infra_file_auto_expiry/infra_file_auto_expiry/source/main.py collect-file-info folder_path --days-for-expiry=5 +``` +Required flags: + folder_path : STRING | Path to folder to check expiry of +Optional flags: + --days-for-expiry=x : INT | The amount of days of non-usage that indicates any file is expired. -sudo $(which python3) /path_to_directory/infra_file_auto_expiry/infra_file_auto_expiry/source/main.py collect-creator-info path_to_jsonl_file \ No newline at end of file +This will return a jsonl file of the following form. After the first two dictionary type objects, each dictionary contains the information of ONE top level folder inside of the folder_path flag. AKA. This program reports information by iterating through the top level folders, but checks expiry by entering recursively through each of those folders. Essentially, each dictionary is associated with a PATH, and all creators who are associated with said path. +``` +{"scrape_time:": x, "scrape_time_datetime": "a datetime"} +{"time_for_scrape_sec": x, "time_for_scrape_min": x} +{"path": "", +"creators": [list of people who created any file in the folder], +"expired": Boolean whether the file is expired or not, +"time_variables": {"atime_datetime": "most recent access datetime", + "ctime_datetime": "most recent change datetime", + "mtime_datetime": "most recent modification datetime"}} +... +``` + +### You can then use this in the following command to tabulate all expired paths that are associated with a particular user. +``` +sudo $(which python3) /path_to_directory/infra_file_auto_expiry/infra_file_auto_expiry/source/main.py collect-creator-info path_to_jsonl_file +``` +Required flags: + path_to_jsonl : STRING | Should be a file that is from calling collect-file-info. + +Optional flags: + --save-file="" : SRING | A path to a jsonl file to save the collected information to. If this is undefined, then the program will just generate a filename and save it to the working directory. + +This command will return a file of the following form. Essentially, each dictionary is associated with a USER, and all paths that are associated with said user. +``` +{"scrape_time:": x, "scrape_time_datetime": "a datetime"} +{"paths": {"path1": {dictionary of it's atime, ctime, mtime datetimes}, + "path2": {dictionary of it's atime, ctime, mtime datetimes}, + "pathx": {dictionary of it's atime, ctime, mtime datetimes}}, "name": "username", "uid": "user id", "gid": "user global id"} +... +``` \ No newline at end of file diff --git a/source/utils/interface.py b/source/utils/interface.py index 3421394..51544ee 100644 --- a/source/utils/interface.py +++ b/source/utils/interface.py @@ -43,7 +43,6 @@ def scan_folder_for_expired(folder_path, expiry_threshold): for entry in os.scandir(folder_path): if os.path.exists(entry.path): expiry_result = is_expired(entry.path, expiry_threshold) - print(entry.path) # path, creator tuple (name, uid, gid), atime, ctime, mtime yield entry.path, expiry_result.is_expired, expiry_result.creators, \ expiry_result.atime, expiry_result.ctime, expiry_result.mtime @@ -90,7 +89,7 @@ def write_jsonl_information(dict_info, file_path, scrape_time): file.write(json.dumps({"scrape_time:": scrape_time, "scrape_time_datetime": str(datetime.datetime.fromtimestamp(scrape_time))}) + "\n") file.write(json.dumps({"time_for_scrape_sec": current_time - scrape_time, - "time_for_scrape_min": (current_time - scrape_time) / 60})) + "time_for_scrape_min": (current_time - scrape_time) / 60}) + "\n") for key in dict_info: file.write(json.dumps(dict_info[key]) + "\n")