main.py: add fqmod param; add test/misc/opts.py launcher

This commit is contained in:
The MMGen Project 2024-03-08 14:13:23 +00:00
commit 5c419c802b
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 10 additions and 2 deletions

View file

@ -22,7 +22,7 @@ main: Script launcher for the MMGen Project
import sys,os
def launch(*, mod=None, func=None, package='mmgen'):
def launch(*, mod=None, func=None, fqmod=None, package='mmgen'):
if sys.platform == 'linux' and sys.stdin.isatty():
import termios,atexit
@ -31,7 +31,7 @@ def launch(*, mod=None, func=None, package='mmgen'):
atexit.register(lambda: termios.tcsetattr(fd,termios.TCSADRAIN,old))
try:
__import__(f'{package}.main_{mod}') if mod else func()
__import__(f'{package}.main_{mod}') if mod else func() if func else __import__(fqmod)
except KeyboardInterrupt:
from .color import yellow
sys.stderr.write(yellow('\nUser interrupt\n'))

8
test/misc/opts.py Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env python3
from mmgen.main import launch
import sys
sys.path.insert(0,'test')
launch(fqmod='misc.opts_main')