aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-10-18 12:59:43 +0300
committerFrederick Muriuki Muriithi2022-10-18 13:01:38 +0300
commitc8f606b0080a7dd343515c7c2ae830dfeecdf341 (patch)
tree1b2d68b65a4783d0ff44223becc352502512e431
parent8a6c81c8963f72958aa36a488e707669af7c7713 (diff)
downloadgenenetwork2-c8f606b0080a7dd343515c7c2ae830dfeecdf341.tar.gz
Sanitise generated filenames
* wqflask/wqflask/correlation/pre_computes.py: Sanitise the generated filenames to get rid of characters that have special meanings in a file path, and other characters that are just a nuisance.
-rw-r--r--wqflask/wqflask/correlation/pre_computes.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/wqflask/wqflask/correlation/pre_computes.py b/wqflask/wqflask/correlation/pre_computes.py
index 85720013..37f037a7 100644
--- a/wqflask/wqflask/correlation/pre_computes.py
+++ b/wqflask/wqflask/correlation/pre_computes.py
@@ -209,6 +209,10 @@ def read_text_file(sample_dict, file_path):
def write_db_to_textfile(db_name, conn, text_dir=TMPDIR):
+ def __sanitise_filename__(filename):
+ ttable = str.maketrans({" ": "_", "/": "_", "\\": "_"})
+ return str.translate(filename, ttable)
+
def __generate_file_name__(db_name):
# todo add expiry time and checker
with conn.cursor() as cursor:
@@ -216,7 +220,8 @@ def write_db_to_textfile(db_name, conn, text_dir=TMPDIR):
'SELECT Id, FullName FROM ProbeSetFreeze WHERE Name = %s', (db_name,))
results = cursor.fetchone()
if (results):
- return f"ProbeSetFreezeId_{results[0]}_{results[1]}"
+ return __sanitise_filename__(
+ f"ProbeSetFreezeId_{results[0]}_{results[1]}")
def __parse_to_dict__(results):
ids = ["ID"]
@@ -232,10 +237,10 @@ def write_db_to_textfile(db_name, conn, text_dir=TMPDIR):
def __write_to_file__(file_path, data, col_names):
with open(file_path, 'w+', encoding='UTF8') as file_handler:
-
writer = csv.writer(file_handler)
writer.writerow(col_names)
writer.writerows(data.values())
+
with conn.cursor() as cursor:
cursor.execute(
"SELECT ProbeSet.Name, Strain.Name, ProbeSetData.value "