commit ddeae9161140da87c535fb2aecd8cfd48919a678
parent d94cf08719bf3a996117badfbd24bff2a2656ee9
Author: lash <dev@holbrook.no>
Date: Fri, 6 May 2022 08:47:29 +0000
Add state parser cli tool
Diffstat:
4 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,5 +1,6 @@
- 0.1.16
* Queue list cli tool
+ * State parser cli tool
* Provide pluggable renderer capability for queue list cli tool
* Move path and state query parsing to settings module
* Add queue path and digest parameters to base config
diff --git a/chainqueue/runnable/sql.py b/chainqueue/runnable/sql.py
@@ -1,14 +0,0 @@
-# standard imports
-import logging
-
-# local imports
-from chainqueue.db.models.base import SessionBase
-from chainqueue.db import dsn_from_config
-
-logg = logging.getLogger(__name__)
-
-
-def setup_backend(config, debug=False):
- dsn = dsn_from_config(config)
- logg.debug('dsn {}'.format(dsn))
- SessionBase.connect(dsn, debug=debug)
diff --git a/chainqueue/runnable/state.py b/chainqueue/runnable/state.py
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# standard imports
+import os
+import logging
+import argparse
+
+# local imports
+from chainqueue.state import Status
+
+argparser = argparse.ArgumentParser()
+argparser.add_argument('-r', '--raw', dest='r', action='store_true', help='Always print pure state element strings')
+argparser.add_argument('state', type=str, help='State to interpret')
+args = argparser.parse_args()
+
+status_interpreter = Status(None, allow_invalid=True)
+
+
+def handle_numeric(v, elements=False):
+ if elements:
+ if not status_interpreter.is_pure(v):
+ return status_interpreter.elements(v)
+ return status_interpreter.name(v)
+
+
+def handle_string(v):
+ try:
+ return status_interpreter.from_name(v)
+ except AttributeError:
+ return status_interpreter.from_elements(v)
+
+
+def main():
+ v = None
+ numeric = False
+ try:
+ v = int(args.state)
+ numeric = True
+ except:
+ v = args.state
+
+ r = None
+ if numeric:
+ r = handle_numeric(v, elements=args.r)
+ else:
+ r = handle_string(v)
+
+ print(r)
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.cfg b/setup.cfg
@@ -35,6 +35,7 @@ packages =
chainqueue.runnable
chainqueue.cli
-#[options.entry_points]
-#console_scripts =
-# chainqueue-list = chainqueue.runnable.list:main
+[options.entry_points]
+console_scripts =
+ chainqueue-list = chainqueue.runnable.list:main
+ chainqueue-state = chainqueue.runnable.state:main