Update operator command to use new SQLAlchemy ORM
This commit is contained in:
parent
a544628fde
commit
c458d4da95
1 changed files with 16 additions and 9 deletions
|
|
@ -1,32 +1,39 @@
|
|||
from core.controllers.OperatorController import OperatorController
|
||||
from core.models.orm_models.Operator import Operator
|
||||
from core.models.manage.session_management import get_session
|
||||
import pprint
|
||||
|
||||
NAME = 'operator'
|
||||
|
||||
|
||||
def register(subparsers):
|
||||
parser = subparsers.add_parser(NAME)
|
||||
subs = parser.add_subparsers(title='subcommands', dest='subcommand')
|
||||
|
||||
subs.add_parser('list')
|
||||
|
||||
show_parser = subs.add_parser('show')
|
||||
show_parser.add_argument('--id', '-i', type=int, required=True)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def handle(arguments, main_parser):
|
||||
if arguments.subcommand is None:
|
||||
main_parser.parse_args(['operator', '--help'])
|
||||
return
|
||||
|
||||
session = get_session()
|
||||
|
||||
if arguments.subcommand == 'list':
|
||||
pprint.pp(OperatorController.get_all())
|
||||
operators = session.query(Operator).all()
|
||||
pprint.pp([{
|
||||
'id': o.id,
|
||||
'name': o.name,
|
||||
'public_key': o.public_key,
|
||||
} for o in operators])
|
||||
|
||||
elif arguments.subcommand == 'show':
|
||||
operator = OperatorController.get(arguments.id)
|
||||
operator = session.get(Operator, arguments.id)
|
||||
if operator is not None:
|
||||
pprint.pp(operator)
|
||||
pprint.pp({
|
||||
'id': operator.id,
|
||||
'name': operator.name,
|
||||
'public_key': operator.public_key,
|
||||
})
|
||||
else:
|
||||
main_parser.error('the following argument should be a valid reference: --id/-i')
|
||||
Loading…
Reference in a new issue