summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Friedli2020-05-21 18:09:38 +0200
committerjfriedli2020-05-21 09:14:28 -0700
commite20ae955028bd2fd4730e01b9b461461693fa790 (patch)
tree828b3f4e1e3fa8d99484bb194380b15581ec96bb
parent28ab47c4eb59f2f8da47f17e90a65b09bde66460 (diff)
removed randint from bandit inspection
Diffstat (limited to '')
-rw-r--r--matweb/file_removal_scheduler.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/matweb/file_removal_scheduler.py b/matweb/file_removal_scheduler.py
index 59bb9ca..d0f0d4b 100644
--- a/matweb/file_removal_scheduler.py
+++ b/matweb/file_removal_scheduler.py
@@ -1,3 +1,8 @@
1"""
2Check regularly if files have not been downloaded
3and delete them if they're too old
4"""
5
1import glob 6import glob
2import time 7import time
3import sys 8import sys
@@ -7,13 +12,23 @@ import random
7from matweb import utils 12from matweb import utils
8 13
9 14
10def run_file_removal_job(upload_folder_path): 15def run_file_removal_job(upload_folder_path: str):
11 if random.randint(0, 10) == 0: 16 """
17 Check for removals at about every 10th request
18 :param upload_folder_path: path were the uploaded files are stored
19 :return: Void
20 """
21 if random.randint(0, 10) == 0: # nosec
12 for file in glob.glob(upload_folder_path + '/*'): 22 for file in glob.glob(upload_folder_path + '/*'):
13 delete_file_when_too_old(file) 23 delete_file_when_too_old(file)
14 24
15 25
16def delete_file_when_too_old(filepath): 26def delete_file_when_too_old(filepath: str):
27 """
28 Check if files are too old and remove em
29 :param filepath: Path of the file to check
30 :return: Void
31 """
17 file_mod_time = os.stat(filepath).st_mtime 32 file_mod_time = os.stat(filepath).st_mtime
18 33
19 # time in second since last modification of file 34 # time in second since last modification of file