Update remaining lexicon CRUD commands

This commit is contained in:
Tim Van Baak 2020-04-23 23:04:13 -07:00
parent 668feadda9
commit 97ac9bf7e3
1 changed files with 35 additions and 32 deletions

View File

@ -1,5 +1,4 @@
# Standard library imports # Standard library imports
import json
import logging import logging
# Module imports # Module imports
@ -57,16 +56,17 @@ def command_delete(args):
""" """
Delete a lexicon and optionally its data Delete a lexicon and optionally its data
""" """
# Module imports raise NotImplementedError()
from amanuensis.config import logger # # Module imports
from amanuensis.lexicon.manage import delete_lexicon # from amanuensis.config import logger
# from amanuensis.lexicon.manage import delete_lexicon
# Perform command # # Perform command
delete_lexicon(args.lexicon, args.purge) # delete_lexicon(args.lexicon, args.purge)
# Output # # Output
logger.info('Deleted lexicon "{}"'.format(args.lexicon.name)) # logger.info('Deleted lexicon "{}"'.format(args.lexicon.name))
return 0 # return 0
@alias('ll') @alias('ll')
@ -75,37 +75,40 @@ def command_list(args):
""" """
List all lexicons and their statuses List all lexicons and their statuses
""" """
# Module imports raise NotImplementedError()
from amanuensis.lexicon.manage import get_all_lexicons # # Module imports
# from amanuensis.lexicon.manage import get_all_lexicons
# Execute command # # Execute command
lexicons = get_all_lexicons() # lexicons = get_all_lexicons()
# Output # # Output
statuses = [] # statuses = []
for lex in lexicons: # for lex in lexicons:
statuses.append("{0.lid} {0.name} ({1})".format(lex, lex.status())) # statuses.append("{0.lid} {0.name} ({1})".format(lex, lex.status()))
for s in statuses: # for s in statuses:
print(s) # print(s)
return 0 # return 0
@alias('ln') @alias('ln')
@requires_lexicon @requires_lexicon
@add_argument( @add_argument("--get",
"--get", metavar="PATHSPEC", dest="get", metavar="PATHSPEC",
nargs="?", const=CONFIG_GET_ROOT_VALUE, dest="get",
nargs="?",
const=CONFIG_GET_ROOT_VALUE,
help="Get the value of a config key") help="Get the value of a config key")
@add_argument( @add_argument("--set",
"--set", metavar=("PATHSPEC", "VALUE"), dest="set", metavar=("PATHSPEC", "VALUE"),
nargs=2, help="Set the value of a config key") dest="set",
nargs=2,
help="Set the value of a config key")
def command_config(args): def command_config(args):
""" """
Interact with a lexicon's config Interact with a lexicon's config
""" """
# Module imports lexicon: LexiconModel = args.lexicon
from amanuensis.config import logger, json_ro, json_rw
from amanuensis.lexicon import LexiconModel
# Verify arguments # Verify arguments
if args.get and args.set: if args.get and args.set:
@ -114,11 +117,11 @@ def command_config(args):
# Execute command # Execute command
if args.get: if args.get:
config_get(args.lexicon.config, args.get) config_get(lexicon.cfg, args.get)
if args.set: if args.set:
with json_rw(args.lexicon.config_path) as cfg: with lexicon.ctx.edit_config() as cfg:
config_set(args.lexicon.id, cfg, args.set) config_set(lexicon.lid, cfg, args.set)
# config_* functions handle output # config_* functions handle output
return 0 return 0