diff --git a/CLI/commands.py b/CLI/commands.py index 1780d32..ed1c1f3 100644 --- a/CLI/commands.py +++ b/CLI/commands.py @@ -5,134 +5,4 @@ import os import argparse -#already ccrerrated account through website, has to login -def update(): - #get data from database - return - -def yesorno(question): - questions = [ - { - 'type': 'input', - 'name': 'response', - 'message': question, - }, - ] - answers = prompt(questions) - if(answers["response"] == "y"): - return True - return False - -def login(): - #enter username - #enter password - questions = [ - { - 'type': 'input', - 'name': 'webmail', - 'message': 'What\'s TJ Webmail', - }, - { - 'type': 'password', - 'name': 'password', - 'message': 'Password?', - }, - ] - user = prompt(questions) - #reading from json of users (replace w GET to database) to check if user is registered - with open('users.json', 'r') as json_file: - data = json.load(json_file) - for i in range(len(data)): - if user["webmail"] == data[i]["webmail"]: - if(user["password"] == data[i]["password"]): - print("Logged in!") - return data[i] - else: - print("Password incorrect. Try again.") - return None - print("User not found. Please Try again") - return None - -#did not create account through website, has to signup/login -def signup(): - questions = [ - { - 'type': 'input', - 'name': 'first-name', - 'message': 'What\'s your first name', - }, - { - 'type': 'input', - 'name': 'last-name', - 'message': 'What\'s your last name?', - }, - { - 'type': 'list', - 'name': 'grade', - 'message': 'Grade?', - 'choices':["9","10","11","12"] - }, - { - 'type': 'input', - 'name': 'webmail', - 'message': 'What\'s your TJ Webmail?', - }, - { - 'type': 'password', - 'name': 'password', - 'message': 'Password?', - }, - ] - user = prompt(questions) - for i in user: - if user[i] == "": - print("Some forms were left blank. Try again.\n") - return None - if len(user["password"]) < 6: - print("Password is too short. Try again.") - return None - if (("@tjhsst.edu" in user['webmail']) == False): - print("Webmail entered was not a @tjhhsst.edu. Try again.") - return None - - user["classes"] = [] - with open('users.json', 'r') as json_file: - data = json.load(json_file) - data.append(user) - open("users.json", "w").write(str(json.dumps(data))) - return user - -def relogin(): - questions = [ - { - 'type': 'list', - 'name': 'choice', - 'message': '', - 'choices':["Continue as current user","Login into new user","Sign up into new account"] - }, - ] - answer = prompt(questions) - - -def setup(user): - #Read classes/assignenments and setup directory: - #SkoolOS/Math/Week1 - for c in user["classes"]: - os.makedirs("../" + c) - for a in user["classes"][c]: - os.makedirs("../" + c + "/" + a) - -def start(): - if(os.path.exists(".login.txt") == False): - b = yesorno("Do you have a SkoolOS account?(y/N)") - if(b): - user = login() - if(user != None): - setup(user) - open(".login.txt", "w").write(str(user)) - else: - user = signup() - if(user != None): - open(".login.txt").write(str(user)) - \ No newline at end of file diff --git a/CLI/git.py b/CLI/git.py new file mode 100644 index 0000000..b6c45fd --- /dev/null +++ b/CLI/git.py @@ -0,0 +1,38 @@ +import subprocess +import os + +#students +def initialize(repo, subject): + process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + output = process.communicate() + dirname = repo[repo.rindex('/')+1:repo.index(".git")] + os.rename(dirname, subject) + #print(output) + +#Teachers + +#make student repo by student id +def addStudent(stid, teacher): + os.mkdir(stid) + os.chdir(os.getcwd() + "/" + stid) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + +def addStudents(filename): + print(filename) + +def addAsignment(name): + print(name) + +def updateAssignment(name): + print(name) + +def comment(filename, text): + print(text) + + +initialize("https://github.com/therealraffi/1579460.git", "Math1") diff --git a/CLI/run.py b/CLI/run.py index aca8859..6a51e78 100644 --- a/CLI/run.py +++ b/CLI/run.py @@ -1,11 +1,137 @@ from __future__ import print_function, unicode_literals from PyInquirer import prompt, print_json -from commands import start, update import argparse import json import os import argparse +def yesorno(question): + questions = [ + { + 'type': 'input', + 'name': 'response', + 'message': question, + }, + ] + answers = prompt(questions) + if(answers["response"] == "y"): + return True + return False + +#already ccrerrated account through website, has to login +def login(): + #enter username + #enter password + questions = [ + { + 'type': 'input', + 'name': 'webmail', + 'message': 'What\'s TJ Webmail', + }, + { + 'type': 'password', + 'name': 'password', + 'message': 'Password?', + }, + ] + user = prompt(questions) + #reading from json of users (replace w GET to database) to check if user is registered + with open('users.json', 'r') as json_file: + data = json.load(json_file) + for i in range(len(data)): + if user["webmail"] == data[i]["webmail"]: + if(user["password"] == data[i]["password"]): + print("Logged in!") + return data[i] + else: + print("Password incorrect. Try again.") + return None + print("User not found. Please Try again") + return None + +#did not create account through website, has to signup/login +def update(): + questions = [ + { + 'type': 'input', + 'name': 'first-name', + 'message': 'What\'s your first name', + }, + { + 'type': 'input', + 'name': 'last-name', + 'message': 'What\'s your last name?', + }, + { + 'type': 'list', + 'name': 'grade', + 'message': 'Grade?', + 'choices':["9","10","11","12"] + }, + { + 'type': 'input', + 'name': 'webmail', + 'message': 'What\'s your TJ Webmail?', + }, + { + 'type': 'password', + 'name': 'password', + 'message': 'Password?', + }, + ] + user = prompt(questions) + for i in user: + if user[i] == "": + print("Some forms were left blank. Try again.\n") + return None + if len(user["password"]) < 6: + print("Password is too short. Try again.") + return None + if (("@tjhsst.edu" in user['webmail']) == False): + print("Webmail entered was not a @tjhhsst.edu. Try again.") + return None + + #post user to json, replace w POST to db + user["classes"] = [] + with open('users.json', 'r') as json_file: + data = json.load(json_file) + data.append(user) + open("users.json", "w").write(str(json.dumps(data))) + return user + +def relogin(): + questions = [ + { + 'type': 'list', + 'name': 'choice', + 'message': '', + 'choices':["Continue as current user","Login into new user","Sign up into new account"] + }, + ] + answer = prompt(questions) + + +def setup(user): + #Read classes/assignenments and setup directory: + #SkoolOS/Math/Week1 + for c in user["classes"]: + os.makedirs("../" + c) + for a in user["classes"][c]: + os.makedirs("../" + c + "/" + a) + +def start(): + if(os.path.exists(".login.txt") == False): + b = yesorno("Do you have a SkoolOS account?(y/N)") + if(b): + user = login() + if(user != None): + setup(user) + open(".login.txt", "w").write(str(user)) + else: + user = update() + if(user != None): + open(".login.txt").write(str(user)) + my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS control your system', epilog="Try again") my_parser.add_argument('--init', action="store_true") #returns true if run argument args = my_parser.parse_args()