added settings file
This commit is contained in:
parent
6aa823f7a4
commit
b285d60fc4
64
OracleSQL.py
64
OracleSQL.py
|
|
@ -1,34 +1,73 @@
|
||||||
import os
|
import os
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
from time import sleep
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
accounts = ["username", "username"]
|
json_file = open("settings.json", "r")
|
||||||
os.chdir("C://Users/joshu/Documents/Uni/CSY1026/scripts/")
|
settings = json.load(json_file)
|
||||||
|
json_file.close()
|
||||||
|
accounts = settings["accounts"]
|
||||||
|
script_dir = settings["script_dir"]
|
||||||
|
password = settings["password"]
|
||||||
|
json_file = open("settings.json", "w")
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.chdir(script_dir)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("\nYour script directory path doesn't exist!\n")
|
||||||
runFlag = True
|
runFlag = True
|
||||||
|
|
||||||
|
def change_settings():
|
||||||
|
setting_choice = int(input("\nWhat would you like to do? \nCommands:\n1)Change accounts\n2)Change script dir path\n3)Quit\n>"))
|
||||||
|
if setting_choice == 1:
|
||||||
|
normal_account = input("\nWhat is your username for your normal account?\n>")
|
||||||
|
course_account = input("\nWhat is your username for your coursework account?\n>")
|
||||||
|
new_password = input("\nWhat is the password for these accounts (This should be your student ID)\n>")
|
||||||
|
settings["accounts"] = [normal_account, course_account]
|
||||||
|
settings["password"] = new_password
|
||||||
|
json.dump(settings, json_file)
|
||||||
|
elif setting_choice == 2:
|
||||||
|
new_dir = input("\nWhat is the path to your script directory?\n>")
|
||||||
|
settings["script_dir"] = new_dir
|
||||||
|
json.dump(settings, json_file)
|
||||||
|
else:
|
||||||
|
if setting_choice != 3:
|
||||||
|
print("\nIncorrect input!\n")
|
||||||
|
print("Returning to homepage...")
|
||||||
|
|
||||||
while runFlag:
|
while runFlag:
|
||||||
account_choice = int(input("\nWhich account would you like to log into?\n1) Normal\n2) Coursework\n>"))
|
account_choice = int(input("\nWhich account would you like to log into?\n1)Normal\n2)Coursework\n3)Change Settings\n4)Quit\n>"))
|
||||||
|
|
||||||
if (account_choice == 1 or account_choice == 2):
|
if (account_choice == 1 or account_choice == 2):
|
||||||
runFlag = False
|
runFlag = False
|
||||||
|
|
||||||
|
elif (account_choice == 3):
|
||||||
|
change_settings()
|
||||||
|
elif (account_choice == 4):
|
||||||
|
json.dump(settings, json_file)
|
||||||
|
json_file.close()
|
||||||
|
quit()
|
||||||
else:
|
else:
|
||||||
print("\nIncorrect Input\n")
|
print("\nIncorrect Input\n")
|
||||||
input("Press Enter to continue...\n")
|
input("Press Enter to continue...\n")
|
||||||
|
|
||||||
|
|
||||||
print("\nHere are your available scripts:\n")
|
|
||||||
files = [f for f in os.listdir(".") if os.path.isfile(f)]
|
files = [f for f in os.listdir(".") if os.path.isfile(f)]
|
||||||
runFlag = True
|
runFlag = True
|
||||||
|
|
||||||
while runFlag:
|
while runFlag:
|
||||||
os.chdir("C://Users/joshu/Documents/Uni/CSY1026/scripts/")
|
os.chdir(script_dir)
|
||||||
|
print("\n")
|
||||||
|
print("\nHere are your available scripts:\n")
|
||||||
for i in range(0,len(files)):
|
for i in range(0,len(files)):
|
||||||
print(files[i][:len(files[i])-4])
|
print(files[i][:len(files[i])-4])
|
||||||
|
|
||||||
choice = input("\nWhat would you like to do? \nform: 'command file'\n\nCommands:\nedit\nedit folder\nrun\nquit\n> ")
|
choice = input("\nWhat would you like to do? \nform: 'command file'\n\nCommands:\nedit\nedit folder (open scripts folder)\nrun\nquit\n> ")
|
||||||
|
|
||||||
if (choice == "quit"):
|
if (choice == "quit"):
|
||||||
runFlag = False
|
runFlag = False
|
||||||
|
json.dump(settings, json_file)
|
||||||
|
json_file.close()
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
split_choice = choice.rsplit(" ",1)
|
split_choice = choice.rsplit(" ",1)
|
||||||
|
|
@ -47,9 +86,14 @@ while runFlag:
|
||||||
|
|
||||||
elif (command == "run"):
|
elif (command == "run"):
|
||||||
os.chdir("C://Oracle12c/")
|
os.chdir("C://Oracle12c/")
|
||||||
run_time = sp.Popen(f"sqlplus.exe {accounts[account_choice-1]}@student/password", stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE)
|
run_time = ""
|
||||||
print("\n"+run_time.communicate(f"@C://Users/joshu/Documents/Uni/CSY1026/scripts/{current_file}.sql\n".encode())[0].decode())
|
|
||||||
|
run_time = sp.Popen(f"sqlplus.exe {accounts[account_choice-1]}@student/{password}", stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE)
|
||||||
|
s = run_time.communicate(f"@{script_dir}{current_file}.sql\n".encode())[0].decode()
|
||||||
|
s = s[s.find("options")+15:]
|
||||||
|
s = s[:s.find("SQL>")]
|
||||||
|
print("\n"+s)
|
||||||
input("Press Enter to continue...\n")
|
input("Press Enter to continue...\n")
|
||||||
else:
|
else:
|
||||||
print("\nIncorrect Input\n")
|
print("\nIncorrect Input\n")
|
||||||
input("Press Enter to continue...\n")
|
input("Press Enter to continue...\n")
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
{"accounts": ["CSY1026_109", "CSY1026_309"], "password": "21427656", "script_dir": "C:\\Users\\joshu\\Documents\\Uni\\CSY1026\\scripts\\"}
|
||||||
Loading…
Reference in New Issue