Add state parser cli tool
This commit is contained in:
parent
d94cf08719
commit
ddeae91611
@ -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
|
||||
|
@ -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)
|
51
chainqueue/runnable/state.py
Normal file
51
chainqueue/runnable/state.py
Normal file
@ -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()
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user