#!/usr/bin/python3

import argparse
#import subprocess
#import os
#import server
# import sys

# from nitpo import Nitpo
from runic import Runic
desc = 'launch nitpo web server'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-s', action='store_true', help='stop only')
args = parser.parse_args()

r = Runic()

r.stop()
if args.s:
    quit()

r.start()
print('done')
quit()


# n = Nitpo()
#
# run = '/usr/bin/gunicorn --workers 1'
# if not n.has_conf('files', 'socket'):
#     print("I need a socket file in nitpo.ini.")
#     quit()
# socket_fufi = n.conf['files']['socket']
# if not n.has_conf('files', 'pid'):
#     print("I need a pid file in nitpo.ini.")
#     quit()
# pid_fufi = n.conf['files']['pid']
# if not n.has_conf('files', 'guniconf'):
#     print("I need guniconf file in nitpo.ini.")
#     quit()
# conf_fufi = n.conf['files']['guniconf']
#
# logi = '--log-file /tmp/gunicorn.log --log-level debug'
# kill = f"/bin/kill `/bin/cat {pid_fufi}` ; "
# run += f" {logi} -c {conf_fufi} "
# run += f" -D -b unix:{socket_fufi} -p {pid_fufi} "
# if os.path.isfile(pid_fufi):
#     run = kill + " " + run
# if args.s:
#     subprocess.run(kill, check=True, shell=True)
#     quit()
# run += ' server:app > /dev/null'
# print(run)
# #try:
# subprocess.run(run, check=True, shell=True)