From 739329605e3d0f939fb5262b77a51545c2bcb4a8 Mon Sep 17 00:00:00 2001 From: jpez Date: Mon, 21 Mar 2022 22:55:30 +0000 Subject: [PATCH] first commit --- OracleSQL.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 8 +++++++ 2 files changed, 67 insertions(+) create mode 100644 OracleSQL.py create mode 100644 README.md diff --git a/OracleSQL.py b/OracleSQL.py new file mode 100644 index 0000000..b6098ad --- /dev/null +++ b/OracleSQL.py @@ -0,0 +1,59 @@ +import os +import subprocess as sp +from time import sleep + +accounts = ["username", "username"] +os.chdir("C://Users/joshu/Documents/Uni/CSY1026/scripts/") +runFlag = True + +while runFlag: + choice = int(input("\nWhich account would you like to log into?\n1) Normal\n2) Coursework\n>")) + + if (choice == 1 or choice == 2): + runFlag = False + else: + print("\nIncorrect Input\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)] +runFlag = True + +while runFlag: + os.chdir("C://Users/joshu/Documents/Uni/CSY1026/scripts/") + for i in range(0,len(files)): + 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> ") + + if (choice == "quit"): + runFlag = False + break + try: + split_choice = choice.rsplit(" ",1) + command = split_choice[0] + current_file = split_choice[1] + except IndexError: + print ("\nIncorrect Input\n") + input("Press Enter to continue...\n") + continue + + if (command == "edit"): + if (current_file == "folder"): + os.system("code --n .") + else: + os.system(f"code {current_file}.sql") + + elif (command == "run"): + os.chdir("C://Oracle12c/") + run_time = "" + + if (choice == 1 or choice == 2): + run_time = sp.Popen(f"sqlplus.exe {accounts[choice-1]}@student/password", stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE) + + print("\n"+run_time.communicate(f"@C://Users/joshu/Documents/Uni/CSY1026/scripts/{current_file}.sql\n".encode())[0].decode()) + input("Press Enter to continue...\n") + else: + print("\nIncorrect Input\n") + input("Press Enter to continue...\n") \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a967abb --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# CSY1026_cli_ide + +This code was to made to make accessing my university CSY1026 module database server easier and also allowed the running of scripts. +Editing was also made possible by opening the files in vscode. + +All operations are achieved using native libraries os and subprocess + +This code is not usable unless you have been given the specific binaries from the module tutors at the University of Northampton