Commit 271cb724 authored by lavocat's avatar lavocat
Browse files

From getopt to argparse, related to #1

Need to port socket_bridge too.
parent 47270737
#!/usr/bin/env python3
import argparse
import logging
import getopt
import sys
import signal
import yggdrasil
......@@ -10,81 +10,149 @@ from ..isengard import create_logger
def runner(argv, Controler=None):
print("start")
try:
options, argv = getopt.getopt(
argv[1:],
"F:l:p:P:dDt:f:h:d:i:n",
[ "debug-file=", "debug-level=",
"erebor-path=", "taktuk-path=",
"erebor-deploy", "taktuk-deploy",
"time-file=", "file-host=","host-list=",
"debug=", "id=", "non-root" ]
)
except getopt.GetoptError as message:
sys.stdout.write("toto")
parser = argparse.ArgumentParser(description='Main Erebor launcher')
parser.add_argument(
"-n",
"--non-root",
action="store_false",
default=True,
help='''Precise if this instance is user controled or not
Non supposed to be manually set''')
parser.add_argument(
"-i",
"--id",
default="root",
help='''ID of the instance
Non supposed to be manually set'''
)
parser.add_argument(
"-d",
"--debug",
default="erebor,network,isengard,wrapper,unix_socket,bridge,mpi",
help='''Set which parts needs to output debug infos (comma
separated
Goes along with debug-level and debug-file'''
)
parser.add_argument(
"-l",
"--debug-level",
default="CRITICAL",
help='''\
Debug precision level.
To be choosed in the following list :
-------------------------------------
NOTSET DEBUG INFO WARNING ERROR CRITICAL
'''
)
parser.add_argument(
"-F",
"--debug-file",
default="",
help='''Path where write the logs.
Will be the same on every nodes'''
)
parser.add_argument(
"-t",
"--time-file",
help='''
Give a file name where to checkpoint some execution points.
Can be used in the user code using self.time_log(...)'''
)
parser.add_argument(
"-H",
"--host-list",
default="",
help='''Specifies a comma separated node list to log on to.
Can also be specified on a file -> file-host'''
)
parser.add_argument(
"-f",
"--file-list",
default="",
help='''Specifies a file containing nodes to log on.
A node per line'''
)
parser.add_argument(
"-D",
"--taktuk-deploy",
default=False,
action="store_true",
help="Specifies if taktuk need to deploy itself on the ndoes",
)
parser.add_argument(
"-E",
"--erebor-deploy",
action="store_true",
default=False,
help='''Specifies if erebor need to deploy itself on the ndoes.
Non yet implemented'''
)
parser.add_argument(
"-P",
"--taktuk-path",
default="",
help='''Path where to find TakTuk executable.
If set, this path needs to be the same on each connected
computer'''
)
parser.add_argument(
"-p",
"--erebor-path",
default="",
help='''Path where to find Erebor executable.
Not implemented'''
)
try:
root = True # is root or not
ID = "root" # group id to launch
hlist= [] # host list
tfile= None # time-logger file
epath= "" # path to erebor (if not in the system path)
tpath= "" # path to taktuk (if not in the system path)
deple= False # erebor need to deploy itself
deplt= False # taktuk need to deploy itself
# default logging, everyone logs, and only for fatal messages
log = ["erebor", "network", "isengard", "wrapper",
"unix_socket", "bridge", "mpi"]
loglv= logging.CRITICAL
logf = ""
for option, value in options:
if option in ['t', '--time-file'] :
tfile = value
if option in ["-n", "--non-root"]:
root = False;
if option in ["-i", "--id"]:
ID = value
if option in ["-d", "--debug"]:
if value == "*" :
log = ["erebor", "network", "isengard", "wrapper",
"unix_socket", "bridge", "mpi"]
else :
log = value.split(",")
if option in ["-l", "--debug-level"] :
if value == "CRITICAL" :
loglv = logging.CRITICAL
elif value == "ERROR":
loglv = logging.ERROR
elif value == "WARNING":
loglv = logging.WARNING
elif value == "INFO":
loglv = logging.INFO
elif value == "DEBUG":
loglv = logging.DEBUG
else :
loglv = logging.NOTSET
if option in ["-F", "--debug-file"] :
logf = value
if option in ["-h", "--host-list"]:
hlist = value
if option in ["-f", "--file-host"]:
f = open(value, 'r')
hlist = ",".join(f.readlines())
hlist = hlist.replace("\n", "")
hlist = hlist.replace("\r", "")
if option in ["-p", "--erebor-path"]:
epath = value
if not epath.endswith("/") :
epath = epath+"/"
if option in ["-P", "--taktuk-path"]:
tpath = value
if not tpath.endswith("/") :
tpath = tpath+"/"
if option in ["-p", "--erebor-deploy"]:
deple = True
if option in ["-p", "--taktuk-deploy"]:
deplt = True
args = parser.parse_args()
#print(args)
root = args.non_root
ID = args.id
hlist= args.host_list
tfile= args.time_file
epath= args.erebor_path
tpath= args.taktuk_path
deple= args.erebor_deploy
deplt= args.taktuk_deploy
log = args.debug
loglv= args.debug_level
logf = args.debug_file
# Custom operations for parameters
# Transform * to a list of loggers
if log == "*" :
log = ["erebor", "network", "isengard", "wrapper",
"unix_socket", "bridge", "mpi"]
else :
log = log.split(",")
# Transform a log value to its integer value
if loglv in ["-l", "--debug-level"] :
if value == "CRITICAL" :
loglv = logging.CRITICAL
elif value == "ERROR":
loglv = logging.ERROR
elif value == "WARNING":
loglv = logging.WARNING
elif value == "INFO":
loglv = logging.INFO
elif value == "DEBUG":
loglv = logging.DEBUG
else :
loglv = logging.NOTSET
# Parse the host file
hosts = args.file_list
if hosts != "" :
f = open(hosts, 'r')
hlist = ",".join(f.readlines())
hlist = hlist.replace("\n", "")
hlist = hlist.replace("\r", "")
# Remove unecessary /
if epath != "" and not epath.endswith("/") :
epath = epath+"/"
if tpath != "" and not tpath.endswith("/") :
tpath = tpath+"/"
# Create logger
logger = create_logger('yggdrasil.erebor.main', loglv, logf)
logger.info("Option parsing done")
erebor = Erebor(root, log, loglv, logf, epath, tpath)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment