fix cli
This commit is contained in:
@@ -4,11 +4,19 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
from .api import is_file, list_input_files, process_a_file, select_file
|
from .api import (
|
||||||
from .constants import LANGUAGES
|
pre_process_a_dictionary_file,
|
||||||
|
is_file,
|
||||||
|
list_input_files,
|
||||||
|
process_a_dictionary_file,
|
||||||
|
process_a_phrases_file,
|
||||||
|
select_file,
|
||||||
|
)
|
||||||
|
from .constants import DICT_TYPE, LANGUAGES, PHRASES_TYPE
|
||||||
|
from .utility import ProcessFile
|
||||||
|
|
||||||
|
|
||||||
def cli_select_files():
|
def cli_select_files() -> ProcessFile:
|
||||||
"""Loops until it finds a valid input_file"""
|
"""Loops until it finds a valid input_file"""
|
||||||
print("Select data file:")
|
print("Select data file:")
|
||||||
in_file = None
|
in_file = None
|
||||||
@@ -29,10 +37,28 @@ def cli_select_files():
|
|||||||
return input_file
|
return input_file
|
||||||
|
|
||||||
|
|
||||||
def cli_select_language():
|
def cli_select_dictionay_tsv() -> bool:
|
||||||
"""Selects a language for the trasnlatatio"""
|
"""If a dictionary file is selected, ask if the user wants to proccess it"""
|
||||||
|
s = None
|
||||||
|
while s not in ("y", "yes", "no", "n"):
|
||||||
|
s = input("Do you want to Pre-Process a dictionary (y/n): ")
|
||||||
|
r = s in ("y", "yes")
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def cli_select_language(languages: list = None) -> str:
|
||||||
|
"""Selects a language for the trasnlatation"""
|
||||||
|
if languages:
|
||||||
|
avaliable_languages = {
|
||||||
|
lan_id: lan
|
||||||
|
for lan_id, lan in LANGUAGES.LanguageNames.items()
|
||||||
|
if lan_id in languages
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
avaliable_languages = LANGUAGES.LanguageNames.items()
|
||||||
print("Select a language:")
|
print("Select a language:")
|
||||||
for language_id, language in LANGUAGES.LanguageNames.items():
|
for language_id, language in avaliable_languages:
|
||||||
|
if languages and language_id in languages:
|
||||||
print(f"{language_id} - {language}")
|
print(f"{language_id} - {language}")
|
||||||
s = None
|
s = None
|
||||||
while not s or s not in LANGUAGES.AvailableLanguages:
|
while not s or s not in LANGUAGES.AvailableLanguages:
|
||||||
@@ -44,9 +70,22 @@ def main():
|
|||||||
"""CLI interface for the module"""
|
"""CLI interface for the module"""
|
||||||
while True:
|
while True:
|
||||||
input_file = cli_select_files()
|
input_file = cli_select_files()
|
||||||
|
if DICT_TYPE in input_file.input_file.suffixes:
|
||||||
|
dict_selected = cli_select_dictionay_tsv()
|
||||||
|
if dict_selected:
|
||||||
language_id = cli_select_language()
|
language_id = cli_select_language()
|
||||||
print(f"processing file {input_file.input_file} with language {language_id}")
|
pre_process_a_dictionary_file(input_file, language_id)
|
||||||
process_a_file(input_file, language_id)
|
else:
|
||||||
|
language_id = cli_select_language(
|
||||||
|
input_file.available_dictionary_languages
|
||||||
|
)
|
||||||
|
process_a_dictionary_file(input_file, language_id)
|
||||||
|
elif PHRASES_TYPE in input_file.input_file.suffixes:
|
||||||
|
language_id = cli_select_language()
|
||||||
|
print(
|
||||||
|
f"processing file {input_file.input_file} with language {language_id}"
|
||||||
|
)
|
||||||
|
process_a_phrases_file(input_file, language_id)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user