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

@@ -200,8 +200,10 @@ def serve_forever(server):
pass
def main():
temp_page_flag = "--temporary-page"
if temp_page_flag in sys.argv:
flags = sys.argv[1:]
temp_page_flag = "--show-progress-page"
if temp_page_flag in flags:
# Serve the loading page until TLJH builds
with open("/var/run/index.html", "w+") as f:
f.write(html)
@@ -213,8 +215,10 @@ def main():
loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler)
p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,))
p.start()
# Put the pid after the temp page flag to be passed to the istaller
sys.argv.insert(sys.argv.index(temp_page_flag)+1, str(p.pid))
# Pass the server's pid as a flag to the istaller
flags.remove(temp_page_flag)
pid_flag = "--progress-page-server-pid"
flags.extend([pid_flag, str(p.pid)])
except OSError:
# Only serve the loading page when installing TLJH
pass
@@ -303,7 +307,7 @@ def main():
os.path.join(hub_prefix, 'bin', 'python3'),
'-m',
'tljh.installer',
] + sys.argv[1:]
] + flags
)
if __name__ == '__main__':

View File

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