fix cli
This commit is contained in:
@@ -4,11 +4,19 @@
|
||||
from pathlib import Path
|
||||
|
||||
# Local
|
||||
from .api import is_file, list_input_files, process_a_file, select_file
|
||||
from .constants import LANGUAGES
|
||||
from .api import (
|
||||
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"""
|
||||
print("Select data file:")
|
||||
in_file = None
|
||||
@@ -29,11 +37,29 @@ def cli_select_files():
|
||||
return input_file
|
||||
|
||||
|
||||
def cli_select_language():
|
||||
"""Selects a language for the trasnlatatio"""
|
||||
def cli_select_dictionay_tsv() -> bool:
|
||||
"""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:")
|
||||
for language_id, language in LANGUAGES.LanguageNames.items():
|
||||
print(f"{language_id} - {language}")
|
||||
for language_id, language in avaliable_languages:
|
||||
if languages and language_id in languages:
|
||||
print(f"{language_id} - {language}")
|
||||
s = None
|
||||
while not s or s not in LANGUAGES.AvailableLanguages:
|
||||
s = input(f"Please select the language {LANGUAGES.AvailableLanguages}: ")
|
||||
@@ -44,9 +70,22 @@ def main():
|
||||
"""CLI interface for the module"""
|
||||
while True:
|
||||
input_file = cli_select_files()
|
||||
language_id = cli_select_language()
|
||||
print(f"processing file {input_file.input_file} with language {language_id}")
|
||||
process_a_file(input_file, language_id)
|
||||
if DICT_TYPE in input_file.input_file.suffixes:
|
||||
dict_selected = cli_select_dictionay_tsv()
|
||||
if dict_selected:
|
||||
language_id = cli_select_language()
|
||||
pre_process_a_dictionary_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__":
|
||||
|
||||
@@ -183,7 +183,7 @@ class ProcessFile:
|
||||
def dictionary_resource_file(self):
|
||||
"""The path for the resource tsv for dictionary files"""
|
||||
return self.resources / f"dictionary.{self.language_id}.tsv"
|
||||
|
||||
|
||||
@property
|
||||
def relative_dictionary_resource_file(self):
|
||||
"""The path for the resource tsv for dictionary files"""
|
||||
|
||||
Reference in New Issue
Block a user