From 6eca3af569997f28eee9d169a68cef4bbd6fd789 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Wed, 1 Mar 2023 21:50:04 +0100 Subject: Integrate main app into package --- bsie.app | 49 +++---------------------------------------------- bsie/apps/__init__.py | 40 +++++++++++++++++++++++++++++++++++++++- test/apps/test_index.py | 2 ++ 3 files changed, 44 insertions(+), 47 deletions(-) diff --git a/bsie.app b/bsie.app index d5808e7..0f6f7bc 100755 --- a/bsie.app +++ b/bsie.app @@ -1,49 +1,6 @@ -"""BSIE tools. - -Part of the bsie module. -A copy of the license is provided with the project. -Author: Matthias Baumgartner, 2022 -""" -# standard imports -import argparse -import typing - -# bsie imports -import bsie -import bsie.apps - -# exports -__all__: typing.Sequence[str] = ( - 'main', - ) - -# config -apps = { - 'index' : bsie.apps.index, - 'info' : bsie.apps.info, - } - - -## code ## - -def main(argv): - """Black Star File System maintenance tools.""" - parser = argparse.ArgumentParser(description=main.__doc__, prog='bsie') - parser.add_argument('--version', action='version', - version='%(prog)s version {}.{}.{}'.format(*bsie.version_info)) - parser.add_argument('app', choices=apps.keys(), - help='Select the application to run.') - parser.add_argument('rest', nargs=argparse.REMAINDER) - # parse - args = parser.parse_args() - # run application - apps[args.app](args.rest) - - -## main ## - +#!/usr/bin/env python3 if __name__ == '__main__': + import bsie.apps import sys - main(sys.argv[1:]) + bsie.apps.main(sys.argv[1:]) -## EOF ## diff --git a/bsie/apps/__init__.py b/bsie/apps/__init__.py index 1c3d0f9..4c852a9 100644 --- a/bsie/apps/__init__.py +++ b/bsie/apps/__init__.py @@ -1,12 +1,17 @@ -""" +#!/usr/bin/env python3 +"""BSIE tools. Part of the bsie module. A copy of the license is provided with the project. Author: Matthias Baumgartner, 2022 """ # standard imports +import argparse import typing +# bsie imports +import bsie + # inner-module imports from .index import main as index from .info import main as info @@ -15,6 +20,39 @@ from .info import main as info __all__: typing.Sequence[str] = ( 'index', 'info', + 'main', ) +# config +apps = { + 'index' : index, + 'info' : info, + } + + +## code ## + +def main(argv=None): + """Black Star File System maintenance tools.""" + parser = argparse.ArgumentParser(description=main.__doc__, prog='bsie') + # version + parser.add_argument('--version', action='version', + version='%(prog)s version {}.{}.{}'.format(*bsie.version_info)) + # application selection + parser.add_argument('app', choices=apps.keys(), + help='Select the application to run.') + # dangling args + parser.add_argument('rest', nargs=argparse.REMAINDER) + # parse + args = parser.parse_args(argv) + # run application + apps[args.app](args.rest) + + +## main ## + +if __name__ == '__main__': + import sys + main(sys.argv[1:]) + ## EOF ## diff --git a/test/apps/test_index.py b/test/apps/test_index.py index a877684..f632599 100644 --- a/test/apps/test_index.py +++ b/test/apps/test_index.py @@ -225,6 +225,8 @@ class TestIndex(unittest.TestCase): outbuf = io.StringIO() with contextlib.redirect_stdout(outbuf): bsfs = main([ + '--config', + self.config_path, '--print', '-r', '--host', 'http://example.com', -- cgit v1.2.3