Skip to content

Commit

Permalink
creating the credentials.toml file on the fly, hoping to skip the str…
Browse files Browse the repository at this point in the history
…eamlit welcome msg!
  • Loading branch information
acycliq committed Mar 19, 2024
1 parent f956078 commit 93080f2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pciSeq/src/diagnostics/launch_diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from pathlib import Path
import tomlkit
import subprocess
import pciSeq.src.diagnostics.utils as utils
import logging
Expand All @@ -11,9 +13,35 @@ def launch_dashboard():
filename = os.path.join(dirname, 'diagnostics.py')
code_1, code_2 = utils.validate_redis()
if code_1 == 0 and code_2 == 0:
make_credentials()
p = subprocess.Popen(["streamlit", "run", filename, " --server.headless true"])
# TODO: you need to kill the process on exit
# logger.info('Starting process with pid: %d to run the diagnostics' % p.pid)
# launch_diagnostics_logger.info('Starting process with pid: %d to run the diagnostics' % p.pid)
else:
launch_diagnostics_logger.info("Skipping diagnostics, cannot run them. Either redis not installed or not running.")


def make_credentials():
"""
creates a credentials.toml file in the .streamlit folder under the user's home dir and
in the [general] section it creates an email key with value an empty string.
If an email key/value pair exists already, the file remains intact
The only purpose of this is to skip the annoying streamlit welcome message so that
the diagnostics will be launched without any user interaction. (otherwise the welcome msf
might pause the program flow)
"""
credentials = os.path.join(Path.home(), '.streamlit', 'credentials.toml')
mode = 'rt' if os.path.exists(credentials) else 'w+'
with open(credentials, mode) as fp:
doc = tomlkit.load(fp)
append_email(doc, credentials)


def append_email(doc, fname):
if doc.get('general') is None:
general = tomlkit.table()
doc.add("general", general)
if doc.get('general').get('email') is None:
doc.get('general').add("email", "")
with open(fname, 'w') as outfile:
tomlkit.dump(doc, outfile)

0 comments on commit 93080f2

Please sign in to comment.