From 00e900cdf5daf4914e369c249d061d0ef5c436b1 Mon Sep 17 00:00:00 2001 From: thatgirlginger Date: Fri, 11 Sep 2026 17:51:41 -0400 Subject: [PATCH 1/2] added function to sanitize codename input for SQL safety --- opendoors/utils.py | 7 +++++++ requirements.txt | 2 +- start.py | 27 +++++++++++++++------------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/opendoors/utils.py b/opendoors/utils.py index 3bc878c..0d9c5da 100644 --- a/opendoors/utils.py +++ b/opendoors/utils.py @@ -171,3 +171,10 @@ def get_prefixed_path(step: str, path: str, filename: str = ""): return os.path.join(path, f"{prefix}-{filename}") else: return os.path.join(path, prefix) + +def sanitize_codename(codename: str): + """ + processes and sanitizes the archive codename used for db identifiers and file naming + """ + newname = "".join([x for x in list(codename.lower()) if x.isalpha()]) + return newname[:10] diff --git a/requirements.txt b/requirements.txt index d4c9945..0afc826 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ atomicwrites==1.4.0 attrs==20.2.0 -cffi==1.14.3 +cffi==1.17.0 colorama==0.4.4 colorlog==4.2.1 configparser==5.0.0 diff --git a/start.py b/start.py index 073542b..acaa94a 100755 --- a/start.py +++ b/start.py @@ -8,7 +8,7 @@ from opendoors.logging import Logging from opendoors.mysql import SqlDb from opendoors.step_base import StepInfo -from opendoors.utils import make_banner, set_working_dir +from opendoors.utils import make_banner, set_working_dir, sanitize_codename from steps import step_01, step_02, step_03, step_04 steps = { @@ -62,22 +62,25 @@ def save_config_and_exit(): Example: python3 start.py mvw /users/me/otw_opendoors Prompts user if no codename is given, and uses an "otw_opendoors" in the user's home directory if no root path given """ - if len(sys.argv) > 1: - code_name = sys.argv[1] + if len(sys.argv) != 3: + code_name = sanitize_codename(input( + "Please provide a short, lowercase code name with no spaces or punctuation for the archive: " + "\n>> " + )) + path = input( + "Please provide a full path to the working directory: " + "\n>> " + ) else: - code_name = None - while code_name == None or any( # noqa: E711 - [x not in "qwertyuiopasdfghjklzxcvbnm" for x in code_name] - ): - code_name = input( - "Please provide a short, lowercase code name with no spaces or punctuation for the archive " - "you are processing (and make a note of it as you'll need it in future!):\n>> " - ) + code_name = sanitize_codename(sys.argv[1]) + path = sys.argv[2] + + print(f"Your codename is: {code_name}\n" + "(note: If this is different from your input, this is because it has been sanitized for MySQL safety)") banner_text = f"""Starting processing for archive "{code_name}"...""" banner = make_banner("=", banner_text) - path = sys.argv[2] if len(sys.argv) > 2 else None working_dir = set_working_dir(path, code_name) logger = Logging(working_dir, code_name).logger() From fb1804e2e2a91e315fdf10dd21d41929a4ddfb0d Mon Sep 17 00:00:00 2001 From: thatgirlginger Date: Fri, 11 Sep 2026 19:58:06 -0400 Subject: [PATCH 2/2] ruff formatting implemented --- opendoors/utils.py | 1 + start.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/opendoors/utils.py b/opendoors/utils.py index 0d9c5da..681efc9 100644 --- a/opendoors/utils.py +++ b/opendoors/utils.py @@ -172,6 +172,7 @@ def get_prefixed_path(step: str, path: str, filename: str = ""): else: return os.path.join(path, prefix) + def sanitize_codename(codename: str): """ processes and sanitizes the archive codename used for db identifiers and file naming diff --git a/start.py b/start.py index acaa94a..aa18b2e 100755 --- a/start.py +++ b/start.py @@ -63,20 +63,21 @@ def save_config_and_exit(): Prompts user if no codename is given, and uses an "otw_opendoors" in the user's home directory if no root path given """ if len(sys.argv) != 3: - code_name = sanitize_codename(input( + code_name = sanitize_codename( + input( "Please provide a short, lowercase code name with no spaces or punctuation for the archive: " "\n>> " - )) - path = input( - "Please provide a full path to the working directory: " - "\n>> " + ) ) + path = input("Please provide a full path to the working directory: " "\n>> ") else: code_name = sanitize_codename(sys.argv[1]) path = sys.argv[2] - print(f"Your codename is: {code_name}\n" - "(note: If this is different from your input, this is because it has been sanitized for MySQL safety)") + print( + f"Your codename is: {code_name}\n" + "(note: If this is different from your input, this is because it has been sanitized for MySQL safety)" + ) banner_text = f"""Starting processing for archive "{code_name}"...""" banner = make_banner("=", banner_text)