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