more documentation

This commit is contained in:
Nathaniel Kenschaft 2020-06-16 15:01:29 -04:00
parent a9ee300708
commit 71f288eaae
2 changed files with 364 additions and 310 deletions

View File

@ -9,6 +9,7 @@ import time
import pyperclip
import datetime
# git clone student directory ==> <student-id>/classes/assignments
# get teacher info from api
@ -28,31 +29,37 @@ def getStudent(ion_user):
return None
print(r.status_code)
def getDB(url):
r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1'))
print("GET:" + str(r.status_code))
return (r.json())
def postDB(data, url):
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
print("POST:" + str(r.status_code))
return (r.json())
def putDB(data, url):
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
print("PUT:" + str(r.status_code))
return (r.json())
def patchDB(data, url):
r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
print("PATH:" + str(r.status_code))
return (r.json())
def delDB(url):
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1'))
print("DELETE:" + str(r.status_code))
return None
def command(command):
ar = []
command = command.split(" ")
@ -64,6 +71,7 @@ def command(command):
print(output.decode('utf-8'))
return output.decode('utf-8')
####################################################################################################################################
# public methods: deleteClass, makeClass, update
@ -369,6 +377,7 @@ class Student:
command('git checkout master')
os.chdir(cdir)
# data = getStudent("2022rkhondak")
# s = Student(data)
# s.viewClass("APLit_eharris1")
@ -379,6 +388,7 @@ class Student:
def main():
pass
if __name__ == "__main__":
# stuff only to run when not called via 'import' here
main()

View File

@ -9,6 +9,8 @@ import time
import pyperclip
from distutils.dir_util import copy_tree
from datetime import datetime
# from django.conf import settings
# import django
@ -25,45 +27,80 @@ from datetime import datetime
# get teacher info from api
def getTeacher(ion_user):
"""
Gets information about a teacher from the api
:param ion_user: a teacher
:return: teacher information or error
"""
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1'))
if(r.status_code == 200):
if r.status_code == 200:
data = r.json()
return data
elif(r.status_code == 404):
elif r.status_code == 404:
return None
print("Make new account!")
elif(r.status_code == 403):
elif r.status_code == 403:
return None
print("Invalid username/password")
else:
return None
print(r.status_code)
def getDB(url):
"""
Sends a GET request to the URL
:param url: URL for request
"""
r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1'))
print("GET:" + str(r.status_code))
return(r.json())
return r.json()
def patchDB(data, url):
"""
Sends a PATCH request to the URL
:param data:
:param url: URL for request
"""
r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
print("PATCH:" + str(r.status_code))
return(r.json())
return r.json()
def postDB(data, url):
"""
Sends a POST request to the URL
:param data:
:param url: URL for request
"""
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
print("POST:" + str(r.status_code))
return(r.json())
return r.json()
def putDB(data, url):
"""
Sends a PUT request to the URL
:param data:
:param url: URL for request
"""
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
print("PUT:" + str(r.status_code))
return(r.json())
return r.json()
def delDB(url):
"""
Sends a DELETE request to the URL
:param url: URL for request
"""
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1'))
print("DELETE:" + str(r.status_code))
return None
def command(command):
ar = []
command = command.split(" ")
@ -74,6 +111,7 @@ def command(command):
output = process.communicate()[1]
print(output.decode('utf-8'))
####################################################################################################################################
# public methods: deleteClass, makeClass, update
@ -81,6 +119,10 @@ class Teacher:
def __init__(self, data):
# teacher info already stored in API
# intitialze fields after GET request
"""
Initializes a Teacher with the data from the api
:param data: api data
"""
self.git = data['git']
self.username = data['ion_user']
self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/"
@ -89,15 +131,13 @@ class Teacher:
# array
self.classes = data['classes']
if(os.path.isdir(self.username + "/Students")):
if os.path.isdir(self.username + "/Students"):
print("Synced to " + self.username)
else:
os.makedirs(self.username + "/Students")
# 2020-05-11 12:25:00
# class name format: <course-name>_<ion_user>
# turn existing directory into class, Pre-condition: directory exists
@ -105,11 +145,12 @@ class Teacher:
def checkClass(self, path):
cname = path.split("/")
cname = cname[len(cname) - 1]
if(os.path.isfile(path)):
if os.path.isfile(path):
print(path + " must be in a Class directory.")
return False
if(("_" + self.username) in cname) == False:
print("Incorrect class name: Must be in the format: " + self.username+ "/<course-name>_<ion_user>, not " + path)
if not (("_" + self.username) in cname):
print(
"Incorrect class name: Must be in the format: " + self.username + "/<course-name>_<ion_user>, not " + path)
return False
dirs = os.listdir(path)
# checks if there is a file (not within Assignments) in class, need at least 1
@ -119,23 +160,23 @@ class Teacher:
as_bad = ""
for d in dirs:
if(os.path.isfile(d)):
if os.path.isfile(d):
deffile = True
else:
# checks if there is a file in an Assignment, need at least 1
as_file = False
asdir = os.listdir(path + "/" + d)
for a in asdir:
if(os.path.isfile(path + "/" + d + "/" +a)):
if os.path.isfile(path + "/" + d + "/" + a):
as_file = True
if(as_file==False):
if not as_file:
as_bad = d
break
if(as_file==False):
if not as_file:
print("Assignment '" + as_bad + "' does not have a default file!")
return False
if(deffile==False):
if not deffile:
print("Need a default file in the " + path + " Directory!")
return False
return True
@ -144,7 +185,7 @@ class Teacher:
n = path.split("/")
n = n[len(n) - 1]
for c in self.classes:
if(n == c['name']):
if n == c['name']:
return True
return False
@ -156,7 +197,7 @@ class Teacher:
if c == cname:
print(cname + " already exists.")
return
if (self.checkClass(path)):
if self.checkClass(path):
cpath = self.username + "/" + cname
data = {
"name": cname,
@ -169,7 +210,7 @@ class Teacher:
postDB(data, 'http://127.0.0.1:8000/api/classes/')
self.classes.append(cname)
# add to instance
#upate self.classes
# update self.classes
data = {
'classes': self.classes
}
@ -188,13 +229,13 @@ class Teacher:
if c['name'] == cname:
isclass = True
break
if(os.path.exists(path) or isclass):
if os.path.exists(path) or isclass:
print("Class already exists: " + cname)
if(isclass):
if isclass:
print("Class already exists in Database")
return
else:
if((("_" + self.username) in cname) == False):
if not (("_" + self.username) in cname):
print("class name must be: " + cname + "_" + self.username)
return
cdir = os.getcwd()
@ -213,10 +254,10 @@ class Teacher:
self.addClass(path)
def deleteClass(self, path):
if(os.path.exists(path) == False):
if not os.path.exists(path):
print(path + " does not exist locally.")
resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ")
if(resp != 'y'):
if resp != 'y':
return
cname = path.split("/")
@ -225,7 +266,7 @@ class Teacher:
print("DELETE: " + self.classes[i]['name'])
for i in range(len(self.classes)):
c = self.classes[i]
if(c == cname):
if c == cname:
del self.classes[i]
# data={
# 'classes':self.classes,
@ -242,28 +283,28 @@ class Teacher:
# remove from student directories
def isStudent(self, student):
r = requests.get(url = "http://127.0.0.1:8000/api/students/" + student + "/", auth=('raffukhondaker','hackgroup1'))
if(r.status_code != 200):
r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/",
auth=('raffukhondaker', 'hackgroup1'))
if r.status_code != 200:
return False
return True
def reqStudent(self, sname, cname):
if(self.isStudent(sname) == False):
if not self.isStudent(sname):
print(sname + " does not exist.")
return False
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
if(sname in str(course['unconfirmed'])):
if sname in str(course['unconfirmed']):
print(sname + " already requested.")
return True
if(sname in str(course['confirmed'])):
print (sname + " alredy enrolled.")
if sname in str(course['confirmed']):
print(sname + " already enrolled.")
return False
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
try:
if(student['added_to']==""):
if student['added_to'] == "":
student['added_to'] = course['name']
else:
student['added_to'] = student['added_to'] + "," + course['name']
@ -275,8 +316,8 @@ class Teacher:
'added_to': student['added_to'],
}
student = patchDB(data, "http://localhost:8000/api/students/" + student['ion_user'] + "/")
student = getDB( "http://localhost:8000/api/students/" + (sname)+ "/")
if(course['unconfirmed']==[]):
student = getDB("http://localhost:8000/api/students/" + sname + "/")
if not course['unconfirmed']:
course['unconfirmed'] = student['ion_user']
else:
course['unconfirmed'] = course['unconfirmed'].append(student['ion_user'])
@ -290,20 +331,21 @@ class Teacher:
# Student should have confirmed on their endd, but class had not been updated yet
# git clone confirmed student repo, copy files into repo and push branch
def addStudent(self, sname, cname):
if(self.isStudent(sname) == False):
if not self.isStudent(sname):
print(sname + " does not exist.")
return False
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
if(os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (student['ion_user'] in course['confirmed']) == True):
if (os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (
student['ion_user'] in course['confirmed']) == True):
print(student['ion_user'] + " already added to class")
return True
if((cname in student['added_to']) == True or (cname in student['classes']) == False):
if (cname in student['added_to']) or not (cname in student['classes']):
print(student['ion_user'] + " has not confirmed class yet")
return False
if((student['ion_user'] in course['unconfirmed']) == False):
if not (student['ion_user'] in course['unconfirmed']):
print(course['unconfirmed'])
print(student['ion_user'] + " has not been requested to join yet.")
return False
@ -313,9 +355,9 @@ class Teacher:
cpath = self.username + "/" + cname
path = self.username + "/Students/" + cname
spath = self.username + "/Students/" + cname + "/" + student['ion_user']
if(os.path.isdir(path) == False):
if not os.path.isdir(path):
os.makedirs(path)
if(os.path.isdir(spath) == False):
if not os.path.isdir(spath):
os.chdir(path)
command("git clone " + student['repo'])
os.chdir(cdir)
@ -332,13 +374,13 @@ class Teacher:
command('git push -u origin ' + cname)
os.chdir(cdir)
if(course['confirmed']==[]):
if not course['confirmed']:
course['confirmed'] = student['ion_user']
else:
course['confirmed'].append(student['ion_user'])
# only 1 pereson on confirmeed
if(len(course['unconfirmed']) == 1):
if len(course['unconfirmed']) == 1:
course['unconfirmed'] = []
# mutiple
else:
@ -356,7 +398,7 @@ class Teacher:
unconf = []
for i in range(len(array)):
a = array[i]
if(self.addStudent(a, cname) == False):
if not self.addStudent(a, cname):
self.reqStudent(a, cname)
unconf.append(a)
return unconf
@ -370,7 +412,7 @@ class Teacher:
if (os.path.isdir(path) == 0 or len(parts) < 3) or aname in str(self.classes):
print("Not valid path.")
return False
if((parts[1] in str(self.classes)) == False):
if not (parts[1] in str(self.classes)):
print("Not in valid class directory")
return False
# parts of assignment name (Essay1, APLit)
@ -395,14 +437,14 @@ class Teacher:
return False
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
if(aname in str(course['assignments'])):
if aname in str(course['assignments']):
print("Assignment name already taken.")
return False
print(course['assignments'])
print(aname)
#################### FINISH VERIFYING
if(os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']) == False):
if not os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']):
print("No students in this class yet")
return True
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
@ -410,7 +452,7 @@ class Teacher:
for st in slist:
if st in str(course['confirmed']):
spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st)
if(os.path.exists(spath + "/" + aname) == False):
if not os.path.exists(spath + "/" + aname):
os.mkdir(spath + "/" + aname)
print(st)
print(copy_tree(path, spath + "/" + aname))
@ -426,7 +468,7 @@ class Teacher:
# check if assignment already exists
r = requests.get(url='http://127.0.0.1:8000/api/assignments/' + aname, auth=('raffukhondaker', 'hackgroup1'))
if(r.status_code != 200):
if r.status_code != 200:
ass = {
'name': oname,
'path': path,
@ -452,11 +494,11 @@ class Teacher:
parts = path.split("/")
aname = parts[len(parts) - 1]
oname = aname + "_" + course
if(os.path.isdir(path) == False):
if not os.path.isdir(path):
print(path + " is not an assignment.")
return
try:
if(due != None or due == ""):
if due != None or due == "":
datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
d = {
'due_date': due,
@ -484,7 +526,7 @@ class Teacher:
# pull student's work, no modifications
def getStudents(self, course):
if((course in self.sclass) == False):
if not (course in self.sclass):
print(course + " not a class.")
return
path = self.username + "/Students/" + course
@ -499,7 +541,7 @@ class Teacher:
def getCommits(self, student, course, commits):
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
try:
if((student in course['confirmed']) == False):
if not (student in course['confirmed']):
print("Student not in class")
return
except:
@ -508,19 +550,20 @@ class Teacher:
cdir = os.getcwd()
os.chdir(self.username + "/Students/" + course['name'] + "/" + student)
process = subprocess.Popen(['git', 'log', '-' + str(commits), course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process = subprocess.Popen(['git', 'log', '-' + str(commits), course['name']], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p = process.poll()
output = process.communicate()[0].decode('utf-8').split('\n\n')
months = ['Jan', 'Feb', 'Mar', "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]
fout = []
for i in range(len(output)):
if("Date" in output[i]):
if "Date" in output[i]:
c = output[i].split("\n")
for k in range(len(c)):
temp = []
if('commit' in c[k]):
if 'commit' in c[k]:
c[k] = c[k].replace('commit', '').strip()
elif('Date:' in c[k]):
elif 'Date:' in c[k]:
c[k] = c[k].replace('Date:', '').strip()
date = c[2].split(" ")
times = date[3].split(":")
@ -546,7 +589,8 @@ class Teacher:
print("START: " + start)
cdir = os.getcwd()
os.chdir(self.username + "/Students/" + course['name'] + "/" + student)
process = subprocess.Popen(['git', 'diff', commit, '--name-status'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process = subprocess.Popen(['git', 'diff', commit, '--name-status'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p = process.poll()
output = process.communicate()[0].decode('utf-8')
print(output)
@ -559,6 +603,7 @@ class Teacher:
}
'''
# check if assignment changed after due date
def afterSubmit(self, course, assignment, student):
assignment = getDB("http://127.0.0.1:8000/api/assignments/" + assignment)
@ -576,11 +621,11 @@ class Teacher:
process = subprocess.Popen(['git', 'show', l[0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = process.poll()
output = process.communicate()[0].decode('utf-8')
if(assignment['name'] in output):
if assignment['name'] in output:
print(l[1])
print(assignment['due_date'])
print("--------------")
if(l[1] > assignment['due_date']):
if l[1] > assignment['due_date']:
print("LATE")
os.chdir(cdir)
return True
@ -614,4 +659,3 @@ TO-DO
- check differences between commits
- check if student changes file after submissionn deadline
'''