From 40af2b37828570221ff5ae8deef835a31c38d451 Mon Sep 17 00:00:00 2001 From: Ayush-Jain2 Date: Sun, 17 Mar 2019 18:04:14 +0530 Subject: [PATCH 1/3] Finding langNames default using pkg_resources --- apertium_apy/apy.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apertium_apy/apy.py b/apertium_apy/apy.py index baaa09810..8a4e6e08e 100755 --- a/apertium_apy/apy.py +++ b/apertium_apy/apy.py @@ -19,6 +19,10 @@ import sys from datetime import timedelta from logging import handlers as logging_handlers # type: ignore +try: + import pkg_resources +except ImportError: + pkg_resources = None # type: ignore import tornado import tornado.httpserver @@ -55,6 +59,8 @@ TranslateWebpageHandler, ) +lang_names_default_path = 'langNames.db' + def sig_handler(sig, frame): global missing_freqs_db @@ -178,11 +184,16 @@ def apply_config(args, parser, apy_section): def parse_args(cli_args=sys.argv[1:]): + if pkg_resources: + lang_names_path = os.path.abspath(pkg_resources.resource_filename('apertium_apy', os.path.join('..', lang_names_default_path))) + else: + lang_names_path = lang_names_default_path parser = argparse.ArgumentParser(description='Apertium APY -- API server for machine translation and language analysis') parser.add_argument('pairs_path', help='path to Apertium installed pairs (all modes files in this path are included)') parser.add_argument('-s', '--nonpairs-path', help='path to Apertium tree (only non-translator debug modes are included from this path)') parser.add_argument('-l', '--lang-names', - help='path to localised language names sqlite database (default = langNames.db)', default='langNames.db') + help='path to localised language names sqlite database (default = %s)' % (lang_names_path), + default=lang_names_path) parser.add_argument('-f', '--missing-freqs', help='path to missing word frequency sqlite database (default = None)', default=None) parser.add_argument('-p', '--port', help='port to run server on (default = 2737)', type=int, default=2737) parser.add_argument('-c', '--ssl-cert', help='path to SSL Certificate', default=None) From 3c1e1a50b9749e9b27e148f9b0342733b016d513 Mon Sep 17 00:00:00 2001 From: Ayush-Jain2 Date: Wed, 20 Mar 2019 00:27:10 +0530 Subject: [PATCH 2/3] Finding the correct path for datafile --- apertium_apy/apy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apertium_apy/apy.py b/apertium_apy/apy.py index 8a4e6e08e..570d2c51a 100755 --- a/apertium_apy/apy.py +++ b/apertium_apy/apy.py @@ -185,7 +185,7 @@ def apply_config(args, parser, apy_section): def parse_args(cli_args=sys.argv[1:]): if pkg_resources: - lang_names_path = os.path.abspath(pkg_resources.resource_filename('apertium_apy', os.path.join('..', lang_names_default_path))) + lang_names_path = os.path.abspath(('apertium_apy', os.path.join('../../../..', 'share', 'apertium-apy', lang_names_default_path)))) else: lang_names_path = lang_names_default_path parser = argparse.ArgumentParser(description='Apertium APY -- API server for machine translation and language analysis') From 375e1ea791892e4612793e9ba5bc97c26fc3166d Mon Sep 17 00:00:00 2001 From: ayushjainrksh Date: Fri, 22 Mar 2019 02:48:28 +0530 Subject: [PATCH 3/3] Finding the path for langNames.db using os module --- apertium_apy/apy.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apertium_apy/apy.py b/apertium_apy/apy.py index 570d2c51a..1b76cdd1f 100755 --- a/apertium_apy/apy.py +++ b/apertium_apy/apy.py @@ -183,9 +183,15 @@ def apply_config(args, parser, apy_section): setattr(args, name, res) +def find(name, path): + for root, dirs, files in os.walk(path): + if name in files: + return os.path.join(root, name) + + def parse_args(cli_args=sys.argv[1:]): if pkg_resources: - lang_names_path = os.path.abspath(('apertium_apy', os.path.join('../../../..', 'share', 'apertium-apy', lang_names_default_path)))) + lang_names_path = find(lang_names_default_path, '/') else: lang_names_path = lang_names_default_path parser = argparse.ArgumentParser(description='Apertium APY -- API server for machine translation and language analysis')