Skip to content

Commit

Permalink
Add: allow "python -m webtranslate.main" to use a static config.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Oct 4, 2020
1 parent ad65941 commit 8026799
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
@@ -1,7 +1,11 @@
.PHONY: manual epydoc run venv

run: .env/pyvenv.cfg
ifeq (,$(wildcard ./config.xml))
.env/bin/python -m webtranslate --project-root data
else
.env/bin/python -m webtranslate.main
endif

venv: .env/pyvenv.cfg

Expand Down
3 changes: 3 additions & 0 deletions webtranslate/__main__.py
Expand Up @@ -8,6 +8,8 @@

CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}

log = logging.getLogger(__name__)


@click_additional_options
def click_logging():
Expand Down Expand Up @@ -91,6 +93,7 @@ def run(
"""
Run the program (it was started from the command line).
"""
log.info("Generating config.xml ...")

with open("config.xml", "w") as fp:
fp.write('<?xml version="1.0" encoding="UTF-8"?>\n')
Expand Down
13 changes: 13 additions & 0 deletions webtranslate/main.py
@@ -1,6 +1,8 @@
"""
Main program.
"""
import logging

from . import (
bottle,
config,
Expand Down Expand Up @@ -30,6 +32,8 @@
user_profile,
)

log = logging.getLogger(__name__)

# Get template files from 'views' only.
bottle.TEMPLATE_PATH = ["./views/"]

Expand Down Expand Up @@ -75,3 +79,12 @@ def run():
# With 'mod_wsgi', application does not run from here.
if config.cfg.server_mode != "mod_wsgi":
bottle.run(reloader=False, debug=debug, host=config.cfg.server_host, port=config.cfg.server_port)


if __name__ == "__main__":
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S", level=logging.INFO
)
log.info("Using existing config.xml")

run()

0 comments on commit 8026799

Please sign in to comment.