Rename flags and work with sys.argv copy

This commit is contained in:
GeorgianaElena
2020-08-17 16:47:55 +03:00
parent 43c38bc09d
commit cef898fd31
2 changed files with 13 additions and 10 deletions

View File

@@ -30,7 +30,7 @@ html = """
<meta http-equiv="refresh" content="30" > <meta http-equiv="refresh" content="30" >
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<img class= "logo" src="https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/docs/images/logo/logo.png"> <img class="logo" src="https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/docs/images/logo/logo.png">
<div class="loader center"></div> <div class="loader center"></div>
<div class="center main-msg">Please wait while your TLJH is building...</div> <div class="center main-msg">Please wait while your TLJH is building...</div>
<div class="center logs-msg">Click the button below to see the logs</div> <div class="center logs-msg">Click the button below to see the logs</div>
@@ -200,8 +200,10 @@ def serve_forever(server):
pass pass
def main(): def main():
temp_page_flag = "--temporary-page" flags = sys.argv[1:]
if temp_page_flag in sys.argv: temp_page_flag = "--show-progress-page"
if temp_page_flag in flags:
# Serve the loading page until TLJH builds # Serve the loading page until TLJH builds
with open("/var/run/index.html", "w+") as f: with open("/var/run/index.html", "w+") as f:
f.write(html) f.write(html)
@@ -213,8 +215,10 @@ def main():
loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler) loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler)
p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,)) p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,))
p.start() p.start()
# Put the pid after the temp page flag to be passed to the istaller # Pass the server's pid as a flag to the istaller
sys.argv.insert(sys.argv.index(temp_page_flag)+1, str(p.pid)) flags.remove(temp_page_flag)
pid_flag = "--progress-page-server-pid"
flags.extend([pid_flag, str(p.pid)])
except OSError: except OSError:
# Only serve the loading page when installing TLJH # Only serve the loading page when installing TLJH
pass pass
@@ -303,7 +307,7 @@ def main():
os.path.join(hub_prefix, 'bin', 'python3'), os.path.join(hub_prefix, 'bin', 'python3'),
'-m', '-m',
'tljh.installer', 'tljh.installer',
] + sys.argv[1:] ] + flags
) )
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -487,8 +487,9 @@ def main():
help='Plugin pip-specs to install' help='Plugin pip-specs to install'
) )
argparser.add_argument( argparser.add_argument(
'--temporary-page', '--progress-page-server-pid',
help='Serve a temporary page while TLJH is building' type=int,
help='The pid of the progress page server'
) )
args = argparser.parse_args() args = argparser.parse_args()
@@ -510,8 +511,6 @@ def main():
try: try:
os.kill(int(args.temporary_page), signal.SIGINT) os.kill(int(args.temporary_page), signal.SIGINT)
# Remove the pid file and the temporary html page # Remove the pid file and the temporary html page
os.remove('/index.html')
os.remove('/favicon.ico')
except Exception as e: except Exception as e:
pass pass