mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
jwutils.Cmds: Beautify log invocations
Add from jwutils import log to avoid unnecessary jwutils.log module path. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
c0b31bb968
commit
ad67dd3832
1 changed files with 7 additions and 5 deletions
|
|
@ -7,6 +7,7 @@ import re
|
||||||
import pickle
|
import pickle
|
||||||
import asyncio
|
import asyncio
|
||||||
import jwutils
|
import jwutils
|
||||||
|
from jwutils import log
|
||||||
|
|
||||||
class Cmds: # export
|
class Cmds: # export
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ class Cmds: # export
|
||||||
self.__description = description
|
self.__description = description
|
||||||
self.__filter = filter
|
self.__filter = filter
|
||||||
self.__modules = modules
|
self.__modules = modules
|
||||||
default_log_level = jwutils.log.NOTICE
|
default_log_level = log.NOTICE
|
||||||
default_log_flags = 'stderr,position,prio,color'
|
default_log_flags = 'stderr,position,prio,color'
|
||||||
# poor man's parsing in the absence of a complete command-line definition
|
# poor man's parsing in the absence of a complete command-line definition
|
||||||
for i in range(1, len(sys.argv)):
|
for i in range(1, len(sys.argv)):
|
||||||
|
|
@ -28,8 +29,8 @@ class Cmds: # export
|
||||||
if arg == '--log-flags':
|
if arg == '--log-flags':
|
||||||
default_log_flags = sys.argv[i]
|
default_log_flags = sys.argv[i]
|
||||||
continue
|
continue
|
||||||
jwutils.log.set_flags(default_log_flags)
|
log.set_flags(default_log_flags)
|
||||||
jwutils.log.set_level(default_log_level)
|
log.set_level(default_log_level)
|
||||||
self.__parser = argparse.ArgumentParser(usage=os.path.basename(sys.argv[0]) + ' [command] [options]',
|
self.__parser = argparse.ArgumentParser(usage=os.path.basename(sys.argv[0]) + ' [command] [options]',
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, description=self.__description)
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter, description=self.__description)
|
||||||
self.__parser.add_argument('--log-flags', help='Log flags', default=default_log_flags)
|
self.__parser.add_argument('--log-flags', help='Log flags', default=default_log_flags)
|
||||||
|
|
@ -50,14 +51,15 @@ class Cmds: # export
|
||||||
continue
|
continue
|
||||||
if inspect.isabstract(c):
|
if inspect.isabstract(c):
|
||||||
continue
|
continue
|
||||||
|
log.slog(log.DEBUG, 'instantiating command "{}"'.format(c))
|
||||||
cmd = c()
|
cmd = c()
|
||||||
cmd.cmds = self
|
cmd.cmds = self
|
||||||
cmd.add_parser(subparsers)
|
cmd.add_parser(subparsers)
|
||||||
|
|
||||||
async def __run(self):
|
async def __run(self):
|
||||||
args = self.__parser.parse_args()
|
args = self.__parser.parse_args()
|
||||||
jwutils.log.set_flags(args.log_flags)
|
log.set_flags(args.log_flags)
|
||||||
jwutils.log.set_level(args.log_level)
|
log.set_level(args.log_level)
|
||||||
return await args.func(args)
|
return await args.func(args)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue