commit 8b0c00d9a1de66a029bd8d93751b716059793753 Author: vivekvardhanadepu Date: Fri Jul 16 01:14:17 2021 +0530 added additional paths to search for lex-tools diff --git a/check_config.py b/check_config.py index 94a5c1a..a09767a 100644 --- a/check_config.py +++ b/check_config.py @@ -14,7 +14,8 @@ yasmet_url = "https://wiki.apertium.org/wiki/Using_weights_for_ambiguous_rules" def check_config(filename='config.toml'): misconfigured = False - lex_tools = '/usr/share/apertium-lex-tools' + lex_tools_paths = ['/opt/local/share/apertium-lex-tools', + '/usr/local/share/apertium-lex-tools', '/usr/share/apertium-lex-tools'] with open(filename) as config_file: config_toml = config_file.read() config = parse(config_toml) @@ -37,20 +38,24 @@ def check_config(filename='config.toml'): f"'{config['CORPUS_TL']}'(CORPUS_TL) is not a file, provide a valid file or \nto download, look {corpora_url}\n") misconfigured = True - if not os.path.isdir(lex_tools): + is_lex_tools_present = False + for lex_tools in lex_tools_paths: + if os.path.isdir(lex_tools): + scripts = ['extract-sentences.py', 'extract-freq-lexicon.py', + 'ngram-count-patterns-maxent2.py', 'merge-ngrams-lambdas.py', 'lambdas-to-rules.py', + 'ngrams-to-rules-me.py', 'common.py'] + + for script in scripts: + if not os.path.isfile(os.path.join(lex_tools, script)): + print( + f"'{script}' is not present in '{lex_tools}', re-install apertium-lex-tools {apertium_url}\n") + misconfigured = True + is_lex_tools_present = True + + if not is_lex_tools_present: print( - f"'{lex_tools}'is not a directory, install apertium-lex-tools {apertium_url}\n") + f"'apertium_lex_tools'is not installed, to install apertium-lex-tools follow {apertium_url}\n") misconfigured = True - else: - scripts = ['extract-sentences.py', 'extract-freq-lexicon.py', - 'ngram-count-patterns-maxent2.py', 'merge-ngrams-lambdas.py', 'lambdas-to-rules.py', - 'ngrams-to-rules-me.py'] - - for script in scripts: - if not os.path.isfile(os.path.join(lex_tools, script)): - print( - f"'{script}' is present in '{lex_tools}', install apertium-lex-tools {apertium_url}\n") - misconfigured = True # assuming scripts are intact # if 'process-tagger-output' not in os.listdir(config['LEX_TOOLS']): diff --git a/tests/check_config_test.py b/tests/check_config_test.py index 7dee417..2b1ccf4 100644 --- a/tests/check_config_test.py +++ b/tests/check_config_test.py @@ -1,10 +1,11 @@ # tests check_config.py -from check_config import check_config -from tomlkit import parse, dumps import os import shutil import sys +from tomlkit import parse, dumps + sys.path.append('../') +from check_config import check_config def main(argc, argv): @@ -43,11 +44,14 @@ def main(argc, argv): # config['SL'] += "abc" - lex_tools = '/usr/share/apertium-lex-tools' - if os.path.isdir(lex_tools): - scripts = ['extract-sentences.py', 'extract-freq-lexicon.py', - 'ngram-count-patterns-maxent2.py', 'merge-ngrams-lambdas.py', 'lambdas-to-rules.py', - 'ngrams-to-rules-me.py'] + lex_tools_paths = ['/opt/local/share/apertium-lex-tools', + '/usr/local/share/apertium-lex-tools', '/usr/share/apertium-lex-tools'] + + for lex_tools in lex_tools_paths: + if os.path.isdir(lex_tools): + scripts = ['extract-sentences.py', 'extract-freq-lexicon.py', + 'ngram-count-patterns-maxent2.py', 'merge-ngrams-lambdas.py', 'lambdas-to-rules.py', + 'ngrams-to-rules-me.py', 'common.py'] for script in scripts: if os.path.isfile(os.path.join(lex_tools, script)): @@ -71,16 +75,17 @@ def main(argc, argv): shutil.move(os.path.join(path, 'process-tagger-output'), os.path.join(path, 'process-tagger-output'+tamper_string)) break - - if os.path.isdir(lex_tools): - scripts = ['extract-sentences.py', 'extract-freq-lexicon.py', - 'ngram-count-patterns-maxent2.py', 'merge-ngrams-lambdas.py', 'lambdas-to-rules.py', - 'ngrams-to-rules-me.py'] - - for script in scripts: - if os.path.isfile(os.path.join(lex_tools, script+tamper_string)): - shutil.move(os.path.join(lex_tools, script+tamper_string), - os.path.join(lex_tools, script)) + + for lex_tools in lex_tools_paths: + if os.path.isdir(lex_tools): + # scripts = ['extract-sentences.py', 'extract-freq-lexicon.py', + # 'ngram-count-patterns-maxent2.py', 'merge-ngrams-lambdas.py', 'lambdas-to-rules.py', + # 'ngrams-to-rules-me.py', 'common.py'] + + for script in scripts: + if os.path.isfile(os.path.join(lex_tools, script+tamper_string)): + shutil.move(os.path.join(lex_tools, script+tamper_string), + os.path.join(lex_tools, script)) # if os.path.isfile(os.path.join(config['LEX_TOOLS'], 'process-tagger-output')): # shutil.move(os.path.join(config['LEX_TOOLS'], 'process-tagger-output'), # os.path.join(config['LEX_TOOLS'], 'process-tagger-output'+tamper_string))