Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding langNames default using pkg_resources issue #107 #129

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apertium_apy/apy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,6 +59,8 @@
TranslateWebpageHandler,
)

lang_names_default_path = 'langNames.db'


def sig_handler(sig, frame):
global missing_freqs_db
Expand Down Expand Up @@ -177,12 +183,23 @@ 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 = 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')
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)
Expand Down