Parcourir la source

Add CLI and init-db command.

scossu il y a 8 mois
Parent
commit
44918381bc
3 fichiers modifiés avec 64 ajouts et 4 suppressions
  1. 22 2
      README.md
  2. 3 2
      scriptshifter/trans.py
  3. 39 0
      sscli

+ 22 - 2
README.md

@@ -73,11 +73,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.
@@ -88,6 +89,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`.
+Note: at the moment only `sscli admin init-db` is available. More commands
+will 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).

+ 3 - 2
scriptshifter/trans.py

@@ -121,6 +121,8 @@ def transliterate(src, lang, t_dir="s2r", capitalize=False, options={}):
         if _run_hook("post_normalize", ctx) == BREAK:
             return getattr(ctx, "dest", ""), ctx.warnings
 
+        lang_map = get_lang_map(ctx.conn, ctx.lang_id, ctx.t_dir)
+
         # Loop through source characters. The increment of each loop depends on
         # the length of the token that eventually matches.
         ctx.cur = 0
@@ -190,8 +192,7 @@ def transliterate(src, lang, t_dir="s2r", capitalize=False, options={}):
             # Begin transliteration token lookup.
             ctx.match = False
 
-            for ctx.src_tk, ctx.dest_str in get_lang_map(
-                    ctx.conn, ctx.lang_id, ctx.t_dir):
+            for ctx.src_tk, ctx.dest_str in lang_map:
                 hret = _run_hook("pre_tx_token", ctx)
                 if hret == BREAK:
                     break

+ 39 - 0
sscli

@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+__doc__ = """ Scriptshifter command line interface. """
+
+
+import click
+
+from scriptshifter import DB_PATH
+from scriptshifter.tables import init_db as _init_db
+
+
+@click.group()
+def cli():
+    """ Scriptshifter CLI. """
+    pass
+
+
+@cli.group(name="admin")
+def admin_grp():
+    """ Admin operations. """
+    pass
+
+
+@admin_grp.command()
+def init_db():
+    """ Initialize SS database. """
+    _init_db()
+
+    click.echo(f"Initialized Scriptshifter DB in {DB_PATH}")
+
+
+@cli.group(name="trans")
+def trans_grp():
+    """ Transliteration and transcription operations. """
+    pass
+
+
+if __name__ == "__main__":
+    cli()