Skip to content

Commit

Permalink
Merge pull request #130 from lcnetdev/test
Browse files Browse the repository at this point in the history
DB back end.
  • Loading branch information
scossu authored Sep 16, 2024
2 parents 5211e7e + 3f2b732 commit f5b1e37
Show file tree
Hide file tree
Showing 24 changed files with 925 additions and 247 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ tags.temp

# Local
ext/arabic_rom/data
scriptshifter/data/*.db
!.keep
VERSION
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ ARG WORKROOT "/usr/local/scriptshifter/src"

# Copy core application files.
WORKDIR ${WORKROOT}
COPY entrypoint.sh uwsgi.ini wsgi.py VERSION ./
COPY VERSION entrypoint.sh sscli uwsgi.ini wsgi.py ./
COPY scriptshifter ./scriptshifter/
COPY tests ./tests/
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

Expand Down
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ Currently, the following environment variables are defined:
- `TXL_DICTA_EP`: Endpoint for the Dicta Hebrew transliteration service. This
is mandatory for using the Hebrew module.

## Initial setup

In order to run Scriptshifter, a local SQLite database must be created. The
simplest way to do that is via command-line:

```bash
./sscli admin init-db
```

This step is already included in the `entrypoint.sh` script that gets executed
by Docker, so no additional action is necessary.

Note that the DB must be recreated every time any of the configuration tables
in `scriptshifter/tables/data` changes.

## Local development server

For local development, it is easiest to run Flask without the WSGI wrapper,
Expand Down Expand Up @@ -73,11 +88,12 @@ string in a production environment.

`TXL_LOGLEVEL`: Logging level. Use Python notation. The default is `WARN`.

`TXL_SMTP_HOST`: SMTP host to send feedback messages through. Defaults to
`localhost`.
`TXL_SMTP_HOST`: SMTP host to send feedback messages through. If not defined,
the feedback form will not be shown in the UI.

`TXL_SMTP_PORT`: Port of the SMTP server. Defaults to `1025`.


## Web UI

`/` renders a simple HTML form to test the transliteration service.
Expand All @@ -88,6 +104,25 @@ the drop-down automatically. The value must be one of the keys found in
`/languages`.


## Command-line interface

Various Scriptshifter commands can be accessed via the shell command `sscli`.
At the moment only a few essential admin and testing tools are available. More
commands can be made avaliable on an as-needed basis.

Help menu:

```
/path/to/sscli --help
```

Section help:

```
/path/to/sscli admin --help
```


## Contributing

See the [contributing guide](./doc/contributing.md).
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fi
host=${TXL_WEBAPP_HOST:-"0.0.0.0"}
port=${TXL_WEBAPP_PORT:-"8000"}

./sscli admin init-db

if [ "${FLASK_ENV}" == "development" ]; then
exec flask run -h $host -p $port
else
Expand Down
8 changes: 8 additions & 0 deletions scriptshifter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

APP_ROOT = path.dirname(path.realpath(__file__))

"""
SQLite database path.
This DB stores all the runtime transliteration data.
"""
DB_PATH = environ.get(
"DB_PATH", path.join(APP_ROOT, "data", "scriptshifter.db"))

"""
SMTP server for sending email. For a dummy server that just echoes the
messages, run: `python -m smtpd -n -c DebuggingServer localhost:1025`
Expand Down
Empty file added scriptshifter/data/.keep
Empty file.
4 changes: 2 additions & 2 deletions scriptshifter/hooks/greek/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from scriptshifter.exceptions import CONT


# Suffixed by ʹ
# Indices are positions in the numeric string from the right
DIGITS = {
# Suffixed by ʹ (U+0374)
1: { # Units
"α": 1,
"β": 2,
Expand Down Expand Up @@ -45,7 +45,7 @@
"ω": 8,
"ϡ": 9,
},
# Prefixed by ͵
# Prefixed by ͵ (U+0375)
4: {
"α": 1,
"β": 2,
Expand Down
16 changes: 4 additions & 12 deletions scriptshifter/rest_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

from base64 import b64encode
from copy import deepcopy
from email.message import EmailMessage
from json import dumps
from os import environ, urandom
Expand All @@ -15,7 +14,7 @@
GIT_COMMIT, GIT_TAG,
SMTP_HOST, SMTP_PORT)
from scriptshifter.exceptions import ApiError
from scriptshifter.tables import list_tables, load_table
from scriptshifter.tables import list_tables, get_language
from scriptshifter.trans import transliterate


Expand Down Expand Up @@ -89,24 +88,17 @@ def list_languages():
@app.route("/table/<lang>")
def dump_table(lang):
"""
Dump parsed transliteration table for a language.
Dump a language configuration from the DB.
"""
tbl = deepcopy(load_table(lang))
for sec_name in ("roman_to_script", "script_to_roman"):
if sec_name in tbl:
for hname, fn_defs in tbl[sec_name].get("hooks", {}).items():
tbl[sec_name]["hooks"][hname] = [
(fn.__name__, kw) for (fn, kw) in fn_defs]

return jsonify(tbl)
return get_language(lang)


@app.route("/options/<lang>", methods=["GET"])
def get_options(lang):
"""
Get extra options for a table.
"""
tbl = load_table(lang)
tbl = get_language(lang)

return jsonify(tbl.get("options", []))

Expand Down
Loading

0 comments on commit f5b1e37

Please sign in to comment.