Implemented proper argv handling

This commit is contained in:
Paweł Kołaczyński
2020-10-27 01:31:43 +01:00
parent 982ecd9d4b
commit 77d12eb6ce
3 changed files with 26 additions and 6 deletions

View File

@ -1,4 +1,4 @@
# Rough Editor # The README is not accurate at the moment!
## Description ## Description

View File

@ -1,10 +1,9 @@
import re import re
import os import os
from datetime import timedelta
import json
from rough_edit.utils import str_to_timedelta, escape_string, generate_regex from rough_edit.utils import str_to_timedelta, escape_string, generate_regex
from rough_edit.file_writers import ffmpeg_command, mpv_command from rough_edit.file_writers import ffmpeg_command, mpv_command
from rough_edit.handle_arguments import handle_arguments
if __name__ == '__main__': if __name__ == '__main__':
@ -12,11 +11,9 @@ if __name__ == '__main__':
subs_dir = f"{baseDir}subs/" subs_dir = f"{baseDir}subs/"
outDir = f"{baseDir}out/" outDir = f"{baseDir}out/"
phrase = "I don't know" phrase, padding_left, padding_right = handle_arguments()
regex = generate_regex(phrase) regex = generate_regex(phrase)
padding_left = timedelta(seconds=3)
padding_right = timedelta(seconds=3)
count = 0 count = 0
with open('rip.sh', 'w') as rip_file: with open('rip.sh', 'w') as rip_file:

23
rough_edit/handle_arguments.py Executable file
View File

@ -0,0 +1,23 @@
import sys
from datetime import timedelta
def print_expected_call_message(additional_message):
print(f"""{additional_message}
Expected application call:
python3 regex_text.py [searched phrase] [left_padding] [right_padding]
Example call:
python3 regex_text.py "I don't know" 2 3""")
def handle_arguments():
if not (arg_len := len(sys.argv)) == 4:
print_expected_call_message(f'Expected two arguments, got {arg_len-1}.')
exit()
try:
phrase = sys.argv[1]
padding_left, padding_right = [timedelta(int(number)) for number in sys.argv[2:4]]
return([phrase, padding_left, padding_right])
except:
print_expected_call_message(f'An error has occured.')
exit()