sscli 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python3
  2. __doc__ = """ Scriptshifter command line interface. """
  3. import click
  4. from glob import glob
  5. from os import path
  6. from scriptshifter import DB_PATH
  7. from scriptshifter.tables import init_db as _init_db
  8. from tests import test_sample
  9. @click.group()
  10. def cli():
  11. """ Scriptshifter CLI. """
  12. pass
  13. @cli.group(name="admin")
  14. def admin_grp():
  15. """ Admin operations. """
  16. pass
  17. @admin_grp.command()
  18. def init_db():
  19. """ Initialize SS database. """
  20. _init_db()
  21. click.echo(f"Initialized Scriptshifter DB in {DB_PATH}")
  22. @cli.group(name="test")
  23. def test_grp():
  24. """ Test operations. """
  25. pass
  26. @test_grp.command()
  27. def list_samples():
  28. """ List string sample sets that can be tested. """
  29. path_ptn = path.join(
  30. path.dirname(path.realpath(__file__)),
  31. "tests", "data", "script_samples", "*.csv")
  32. click.echo("Sample string sets available for batch testing:")
  33. for fn in glob(path_ptn):
  34. click.echo(path.splitext(path.basename(fn))[0])
  35. @test_grp.command()
  36. @click.argument("lang")
  37. def samples(lang):
  38. """
  39. Test sample strings for language LANG.
  40. LANG must match one of the names obtained with `test list-samples` command.
  41. The command will generate a test report file.
  42. """
  43. return test_sample(lang)
  44. @cli.group(name="trans")
  45. def trans_grp():
  46. """ Transliteration and transcription operations. """
  47. pass
  48. if __name__ == "__main__":
  49. cli()