Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions opendoors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,11 @@ 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]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 16 additions & 12 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -62,22 +62,26 @@ 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]
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>> "
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 = 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()
Expand Down
Loading