Skip to content

Commit

Permalink
arrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
Arslan-Siraj committed Oct 16, 2023
1 parent dd073bb commit 7d40b6b
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 134 deletions.
26 changes: 13 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ def main():
if "local" in sys.argv:
main()

# If not in local mode, assume it's hosted/online mode
else:

# WORK LIKE MULTIPAGE APP
# If captcha control is not in session state or set to False
if 'controllo' not in st.session_state or st.session_state['controllo'] == False:
#delete pages
delete_page("app", "File_Upload")
delete_page("app", "Analyze")
delete_page("app", "Result_View")
#apply captcha
# hide app pages as long as captcha not solved
#delete_all_pages("app")

# Apply captcha control to verify the user
captcha_control()
else:
#run main

else:
# Run the main function
main()
#add all pages back
add_page("app", "File_Upload")
add_page("app", "Analyze")
add_page("app", "Result_View")

# Restore all pages (assuming "app" is the main page)
#restore_all_pages("app")

12 changes: 3 additions & 9 deletions pages/0_πŸ“_File_Upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

params = page_setup()

#if local no need captcha
if st.session_state.location == "local":
params["controllo"] = True
st.session_state["controllo"] = True

#if controllo is false means not captcha applied
# If run in hosted mode, show captcha as long as it has not been solved
if 'controllo' not in st.session_state or params["controllo"] == False:
#apply captcha
captcha_control()

# Apply captcha by calling the captcha_control function
captcha_control()

### main content of page

Expand Down
64 changes: 4 additions & 60 deletions pages/1_βš™οΈ_Analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
from src.ini2dec import *
import threading
from src.captcha_ import *
from src.run_subprocess import *

params = page_setup()

#if local no need captcha
if st.session_state.location == "local":
params["controllo"] = True
st.session_state["controllo"] = True

#if controllo is false means not captcha applied
# If run in hosted mode, show captcha as long as it has not been solved
if 'controllo' not in st.session_state or params["controllo"] == False:
#apply captcha
captcha_control()

# Apply captcha by calling the captcha_control function
captcha_control()

### main content of page

Expand Down Expand Up @@ -190,57 +185,6 @@
result_dict["success"] = False
result_dict["log"] = " "

def run_subprocess(args, variables, result_dict):
"""
run subprocess e-g: NuXL command
Args:
args: command with args
variables: variable if any
result_dict: contain success (success flag) and log (capture long log)
should contain result_dict["success"], result_dict["log"]
Returns:
None
"""
#st.write("inside run_subprocess")
#process = subprocess.Popen(args + list(variables), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, text=True)
# run subprocess and get every line of executable log in same time
process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)

stdout_ = []
stderr_ = []

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
#print every line of exec on page
st.text(output.strip())
#append line to store log
stdout_.append(output.strip())

while True:
error = process.stderr.readline()
if error == '' and process.poll() is not None:
break
if error:
#print every line of exec on page even error
st.error(error.strip())
#append line to store log of error
stderr_.append(error.strip())

#check if process run successfully
if process.returncode == 0:
result_dict["success"] = True
#save in to log all lines
result_dict["log"] = " ".join(stdout_)
else:
result_dict["success"] = False
#save in to log all lines even process cause error
result_dict["log"] = " ".join(stderr_)

#create terminate flag from even function
terminate_flag = threading.Event()
terminate_flag.set()
Expand Down
9 changes: 2 additions & 7 deletions pages/2_πŸ“Š_Result_View.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@

params = page_setup()

#if local no need captcha
if st.session_state.location == "local":
params["controllo"] = True
st.session_state["controllo"] = True

#if controllo is false means not captcha applied
# If run in hosted mode, show captcha as long as it has not been solved
if 'controllo' not in st.session_state or params["controllo"] == False:
#apply captcha
# Apply captcha by calling the captcha_control function
captcha_control()

### main content of page
Expand Down
Loading

0 comments on commit 7d40b6b

Please sign in to comment.