Added -backend for frontend intergration
This commit is contained in:
39
CLI/Init.py
39
CLI/Init.py
@@ -2,6 +2,12 @@ import configparser
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import requests
|
import requests
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='TiropitLauncher CLI & Back-End')
|
||||||
|
parser.add_argument('-backend', help="Runs the app in backend mode (no UI)", action="store_true")
|
||||||
|
|
||||||
#declare default vars
|
#declare default vars
|
||||||
class Config():
|
class Config():
|
||||||
|
|
||||||
@@ -20,6 +26,8 @@ class Server():
|
|||||||
else:
|
else:
|
||||||
Icon = "⛔"
|
Icon = "⛔"
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
#declare files
|
#declare files
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
@@ -29,12 +37,16 @@ class Display():
|
|||||||
def Clear():
|
def Clear():
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def showIntroText():
|
def showIntroText():
|
||||||
print("Tiropit Launcher CLI - Release Branch")
|
print("Tiropit Launcher CLI - Release Branch")
|
||||||
print(f"[TCLI]=============[Select option]==============[{Config.version}]")
|
print(f"[TCLI]=============[Select option]==============[{Config.version}]")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def WarnMissingConfig(ConfigError):
|
def WarnMissingConfig(ConfigError):
|
||||||
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
|
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
|
||||||
print("Program will exit before it crashes :)")
|
print("Program will exit before it crashes :)")
|
||||||
@@ -45,6 +57,8 @@ def WarnMissingConfig(ConfigError):
|
|||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def makeConfig():
|
def makeConfig():
|
||||||
config['DEFAULT'] = {'Version': Config.version}
|
config['DEFAULT'] = {'Version': Config.version}
|
||||||
config['ACCOUNT'] = {}
|
config['ACCOUNT'] = {}
|
||||||
@@ -101,20 +115,27 @@ def loadConfig():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
WarnMissingConfig(e)
|
WarnMissingConfig(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def grabServerResolver():
|
def grabServerResolver():
|
||||||
try:
|
try:
|
||||||
response = requests.get("https://kevinblog.sytes.net/APIS/test1.php")
|
response = requests.get("https://kevinblog.sytes.net/APIhS/test1.php")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
server_ip = data.get("HostIp")
|
server_ip = data.get("HostIp")
|
||||||
Server.isReachable = False
|
Server.isReachable = True
|
||||||
|
Server.state = "Connected"
|
||||||
Server.host = server_ip
|
Server.host = server_ip
|
||||||
|
if args.backend: print(f"2:CONNECTED TO: {server_ip}")
|
||||||
return server_ip
|
return server_ip
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print("Error resolving a host, Considering service is offline.")
|
|
||||||
Server.isReachable = False
|
Server.isReachable = False
|
||||||
|
Server.state = f"Failed/Timed Out - {e}"
|
||||||
|
if args.backend: print(f"3:FAILED CONN TO: {e}")
|
||||||
|
else: print("Error resolving a host, Considering service is offline.")
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -230,6 +251,12 @@ def showMenu(menuID):
|
|||||||
|
|
||||||
|
|
||||||
#Begin
|
#Begin
|
||||||
grabServerResolver()
|
if not args.backend:
|
||||||
checkConfig()
|
|
||||||
showMenu(1)
|
grabServerResolver()
|
||||||
|
checkConfig()
|
||||||
|
showMenu(1)
|
||||||
|
else:
|
||||||
|
print("1:=== BACKEND MODE ===")
|
||||||
|
grabServerResolver()
|
||||||
|
|
||||||
Reference in New Issue
Block a user