mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
adding-assignments
This commit is contained in:
parent
14ddb22b2c
commit
5332a32816
2
CLI/back.py
Normal file
2
CLI/back.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import os
|
||||||
|
os.spawnl(os.P_DETACH, 'some_long_running_command')
|
118
CLI/s-git.py
118
CLI/s-git.py
|
@ -56,6 +56,7 @@ def command(command):
|
||||||
p=process.poll()
|
p=process.poll()
|
||||||
output = process.communicate()[0]
|
output = process.communicate()[0]
|
||||||
print(output.decode('utf-8'))
|
print(output.decode('utf-8'))
|
||||||
|
return output.decode('utf-8')
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
|
|
||||||
|
@ -152,30 +153,35 @@ class Student:
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
for c in self.classes:
|
for c in self.classes:
|
||||||
data = getDB("http://127.0.0.1:8000/classes/" + str(c['id']))
|
print("UPDATING CLASS: " + str(c['name']))
|
||||||
|
data = getDB("http://127.0.0.1:8000/classes/" + str(c['name']))
|
||||||
|
command("git checkout master")
|
||||||
command("git checkout " + data['name'])
|
command("git checkout " + data['name'])
|
||||||
command("git add " + data['name'])
|
command("git add .")
|
||||||
command("git commit -m " + data['name'])
|
command("git commit -m " + data['name'])
|
||||||
command("git pull origin " + data['name'])
|
command("git pull origin " + data['name'])
|
||||||
command("git push -u origin " + data['name'])
|
command("git push -u origin " + data['name'])
|
||||||
|
command("git checkout master")
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
for c in self.new:
|
for c in self.new:
|
||||||
self.addClass(str(c['id']))
|
print("ADDING CLASS: " + str(c['name']))
|
||||||
|
self.addClass(str(c['name']))
|
||||||
command("git checkout master")
|
command("git checkout master")
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
#add classes from 'new' field
|
#add classes from 'new' field
|
||||||
def addClass(self, cid):
|
def addClass(self, cid):
|
||||||
if((cid in self.snew) == False):
|
|
||||||
if((cid in self.sclass) == True):
|
|
||||||
print("Already enrolled in this class.")
|
|
||||||
return None
|
|
||||||
if((cid in self.snew) == True):
|
|
||||||
print("Not added by teacher yet.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
data = getDB('http://127.0.0.1:8000/classes/'+ str(cid))
|
data = getDB('http://127.0.0.1:8000/classes/'+ str(cid))
|
||||||
|
if((cid in self.snew) == False or (self.username in data['confirmed'])):
|
||||||
|
print("Already enrolled in this class.")
|
||||||
|
return None
|
||||||
|
if((cid in self.sclass) or (self.username in data['unconfirmed']) == False):
|
||||||
|
print("Not added by teacher yet.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
#add class teacher as cocllaborator to student repo
|
||||||
print(os.getcwd())
|
print(os.getcwd())
|
||||||
pwd= input("Enter Github password: ")
|
pwd= input("Enter Github password: ")
|
||||||
tgit = getDB("http://127.0.0.1:8000/teachers/" + data['teacher'] + "/")['git']
|
tgit = getDB("http://127.0.0.1:8000/teachers/" + data['teacher'] + "/")['git']
|
||||||
|
@ -183,26 +189,7 @@ class Student:
|
||||||
print(url)
|
print(url)
|
||||||
os.system(url)
|
os.system(url)
|
||||||
|
|
||||||
data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "")
|
|
||||||
data['unconfirmed'] = data['unconfirmed'].replace(self.username, "")
|
|
||||||
data['confirmed'] = data['confirmed'] + "," + self.username
|
|
||||||
if(data['confirmed'][0] == ','):
|
|
||||||
data['confirmed'] = data['confirmed'][1:]
|
|
||||||
print(data['confirmed'])
|
|
||||||
print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/"))
|
|
||||||
|
|
||||||
#add teacher as collaborator
|
|
||||||
#curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR'
|
|
||||||
user = self.git
|
|
||||||
|
|
||||||
self.classes.append(data)
|
|
||||||
if(len(self.sclass)==0):
|
|
||||||
self.sclass = data['id']
|
|
||||||
else:
|
|
||||||
self.sclass = self.sclass + "," + str(data['id'])
|
|
||||||
|
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
print(cdir)
|
|
||||||
# path1 = self.username + "/" + self.username
|
# path1 = self.username + "/" + self.username
|
||||||
# path2 = self.username
|
# path2 = self.username
|
||||||
# if(os.path.isdir(path1)):
|
# if(os.path.isdir(path1)):
|
||||||
|
@ -212,24 +199,46 @@ class Student:
|
||||||
# command("git clone " + self.repo)
|
# command("git clone " + self.repo)
|
||||||
# os.chdir(self.username)
|
# os.chdir(self.username)
|
||||||
|
|
||||||
|
#push to git, start at master
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
|
command("git checkout master")
|
||||||
command("git branch " + data['name'])
|
command("git branch " + data['name'])
|
||||||
command("git commit -m initial")
|
command("git commit -m initial")
|
||||||
command("git push origin " + data['name'])
|
command("git push origin " + data['name'])
|
||||||
|
command("git checkout master")
|
||||||
#git clone --single-branch --branch <branchname> <remote-repo>
|
#git clone --single-branch --branch <branchname> <remote-repo>
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
# data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "")
|
||||||
|
# data['unconfirmed'] = data['unconfirmed'].replace(self.username, "")
|
||||||
|
# data['confirmed'] = data['confirmed'] + "," + self.username
|
||||||
|
# if(data['confirmed'][0] == ','):
|
||||||
|
# data['confirmed'] = data['confirmed'][1:]
|
||||||
|
# print(data['confirmed'])
|
||||||
|
# print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/"))
|
||||||
|
|
||||||
|
#add teacher as collaborator
|
||||||
|
#curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR'
|
||||||
|
user = self.git
|
||||||
|
|
||||||
|
self.classes.append(data)
|
||||||
|
if(len(self.sclass)==0):
|
||||||
|
self.sclass = data['name']
|
||||||
|
else:
|
||||||
|
self.sclass = self.sclass + "," + str(data['name'])
|
||||||
|
|
||||||
#upddate self.new
|
#upddate self.new
|
||||||
s=""
|
snew=""
|
||||||
nar = ''
|
new = []
|
||||||
for i in range(len(self.new)):
|
for i in range(len(self.new)):
|
||||||
if(self.new[i]['id'] == int(data['id'])):
|
if(self.new[i]['name'] == data['name']):
|
||||||
del self.new[i]
|
del self.new[i]
|
||||||
#recreate sclass field, using ids
|
#recreate sclass field, using ids
|
||||||
for c in self.new:
|
for c in self.new:
|
||||||
s = s + str(c['id']) + ","
|
snew = snew + str(c['name']) + ","
|
||||||
nar.append(c)
|
new.append(getDB("http://127.0.0.1:8000/classes/" + str(cid)))
|
||||||
self.snew=s
|
self.snew=snew
|
||||||
self.new=nar
|
self.new=new
|
||||||
break
|
break
|
||||||
|
|
||||||
#update teacher instance in db, classes field
|
#update teacher instance in db, classes field
|
||||||
|
@ -296,7 +305,6 @@ class Student:
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
for c in self.classes:
|
for c in self.classes:
|
||||||
if c['name'] == courses:
|
if c['name'] == courses:
|
||||||
print(courses)
|
|
||||||
command("git checkout " + courses)
|
command("git checkout " + courses)
|
||||||
print(os.listdir())
|
print(os.listdir())
|
||||||
return
|
return
|
||||||
|
@ -304,15 +312,35 @@ class Student:
|
||||||
print("Class not found")
|
print("Class not found")
|
||||||
return
|
return
|
||||||
|
|
||||||
def submit(self, courses):
|
def submit(self, course, assignment):
|
||||||
|
cdir = os.getcwd()
|
||||||
|
os.chdir(self.username)
|
||||||
|
print(os.getcwd())
|
||||||
|
command("git add .")
|
||||||
|
command("git commit -m update")
|
||||||
|
command('git checkout ' + course)
|
||||||
|
time.sleep(5)
|
||||||
|
ass = os.listdir()
|
||||||
|
inclass = False
|
||||||
|
for a in ass:
|
||||||
|
if a == assignment:
|
||||||
|
inclass = True
|
||||||
|
break
|
||||||
|
if(inclass == False):
|
||||||
|
print(assignment + " not an assignment of " + course)
|
||||||
|
command('git checkout master')
|
||||||
|
os.chdir(cdir)
|
||||||
|
return
|
||||||
|
|
||||||
|
command('touch ' + assignment + '/SUBMISSION')
|
||||||
command("git add .")
|
command("git add .")
|
||||||
command("git commit -m submit")
|
command("git commit -m submit")
|
||||||
command("git tag " + parts[1] + "-final")
|
command("git tag " + assignment + "-final")
|
||||||
command("git push -u origin " + self.username + " --tags")
|
command("git push -u origin " + course + " --tags")
|
||||||
|
command('git checkout master')
|
||||||
|
os.chdir(cdir)
|
||||||
|
|
||||||
data = getStudent("2023rumareti")
|
data = getStudent("2022rkhondak")
|
||||||
s = Student(data)
|
s = Student(data)
|
||||||
s.update()
|
#s.viewClass("English11_eharris1")
|
||||||
|
s.submit("English11_eharris1", "Entry1")
|
||||||
|
|
||||||
#s.update()
|
|
312
CLI/t-git.py
312
CLI/t-git.py
|
@ -90,59 +90,10 @@ class Teacher:
|
||||||
|
|
||||||
self.classes = classes
|
self.classes = classes
|
||||||
self.sclass=str(data['classes'])
|
self.sclass=str(data['classes'])
|
||||||
if(os.path.isdir(self.username)):
|
if(os.path.isdir(self.username + "/Students")):
|
||||||
print("Synced to " + self.username)
|
print("Synced to " + self.username)
|
||||||
else:
|
else:
|
||||||
os.mkdir(self.username)
|
os.makedirs(self.username + "/Students")
|
||||||
|
|
||||||
|
|
||||||
#update API and Github, all assignments / classes
|
|
||||||
def update(self):
|
|
||||||
#lists all classes
|
|
||||||
ignore=['.git','.DS_Store']
|
|
||||||
classes = os.listdir(self.username)
|
|
||||||
for i in ignore:
|
|
||||||
try:
|
|
||||||
classes.remove(i)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
#list of classes that have been deleted (not with deleteClass)
|
|
||||||
extra = []
|
|
||||||
for c in self.classes:
|
|
||||||
extra.append(c)
|
|
||||||
for i in range(len(extra)):
|
|
||||||
e = extra[i]['path']
|
|
||||||
extra[i] = e
|
|
||||||
print("Extra: "+str(extra))
|
|
||||||
print("Local:" + str(classes))
|
|
||||||
#checks all class directories first
|
|
||||||
for c in classes:
|
|
||||||
path = self.username + "/" + c
|
|
||||||
if(self.checkClass(path) == False):
|
|
||||||
return
|
|
||||||
extra.remove(path)
|
|
||||||
print("Current classes: " + path)
|
|
||||||
|
|
||||||
for e in extra:
|
|
||||||
self.deleteClass(e)
|
|
||||||
|
|
||||||
for i in range(len(classes)):
|
|
||||||
c = classes[i]
|
|
||||||
path = self.username + "/" + c
|
|
||||||
#lists all assignments and default files
|
|
||||||
#if no .git, directory not synced to git or API
|
|
||||||
if (self.checkInDB(path)==False):
|
|
||||||
self.addClass(path)
|
|
||||||
else:
|
|
||||||
#push to git
|
|
||||||
loc = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
command('git fetch origin')
|
|
||||||
command('git pull origin master')
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m "Update"')
|
|
||||||
command('git push -u origin master')
|
|
||||||
os.chdir(loc)
|
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
|
@ -216,12 +167,12 @@ class Teacher:
|
||||||
#upate self.classes
|
#upate self.classes
|
||||||
self.classes.append(data)
|
self.classes.append(data)
|
||||||
if(len(self.sclass)==0):
|
if(len(self.sclass)==0):
|
||||||
self.sclass = data['id']
|
self.sclass = data['name']
|
||||||
else:
|
else:
|
||||||
self.sclass = self.sclass + "," + str(data['id'])
|
self.sclass = self.sclass + "," + str(data['name'])
|
||||||
|
|
||||||
#update teacher instance in db, classes field
|
#update teacher instance in db, classes field
|
||||||
data={
|
teacher={
|
||||||
'first_name':self.first_name,
|
'first_name':self.first_name,
|
||||||
'last_name':self.last_name,
|
'last_name':self.last_name,
|
||||||
'git':self.git,
|
'git':self.git,
|
||||||
|
@ -230,9 +181,9 @@ class Teacher:
|
||||||
'classes':self.sclass,
|
'classes':self.sclass,
|
||||||
'email':self.email
|
'email':self.email
|
||||||
}
|
}
|
||||||
putDB(data, self.url)
|
putDB(teacher, self.url)
|
||||||
|
|
||||||
return data
|
return teacher
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
#make a new class from scratch
|
||||||
|
@ -241,8 +192,16 @@ class Teacher:
|
||||||
def makeClass(self, cname, assignments):
|
def makeClass(self, cname, assignments):
|
||||||
#check if class exists
|
#check if class exists
|
||||||
path = self.username + "/" + cname
|
path = self.username + "/" + cname
|
||||||
if(os.path.exists(path)):
|
isclass = False
|
||||||
|
acourses = getDB("http://127.0.0.1:8000/classes/")['results']
|
||||||
|
for c in acourses:
|
||||||
|
if c['name'] == cname:
|
||||||
|
isclass=True
|
||||||
|
break
|
||||||
|
if(os.path.exists(path) or isclass):
|
||||||
print("Class already exists: " + cname)
|
print("Class already exists: " + cname)
|
||||||
|
if(isclass):
|
||||||
|
print("Class already exists in Database")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if((("_" + self.username) in cname) == False):
|
if((("_" + self.username) in cname) == False):
|
||||||
|
@ -272,22 +231,16 @@ class Teacher:
|
||||||
|
|
||||||
cname = path.split("/")
|
cname = path.split("/")
|
||||||
cname = cname[len(cname)-1]
|
cname = cname[len(cname)-1]
|
||||||
cid = None
|
|
||||||
repo = ''
|
repo = ''
|
||||||
for c in self.classes:
|
print("DELETE: " + self.classes[i]['name'])
|
||||||
if cname == c['name']:
|
|
||||||
cid = str(c['id'])
|
|
||||||
repo = c['repo']
|
|
||||||
|
|
||||||
#remove from api
|
|
||||||
for i in range(len(self.classes)):
|
for i in range(len(self.classes)):
|
||||||
if(self.classes[i]['id'] == int(cid)):
|
c = self.classes[i]
|
||||||
print("DELETE: " + self.classes[i]['name'])
|
if(c['name'] == cname):
|
||||||
del self.classes[i]
|
del self.classes[i]
|
||||||
s=""
|
s=""
|
||||||
#recreate sclass field, using ids
|
#recreate sclass field, using ids
|
||||||
for c in self.classes:
|
for c in self.classes:
|
||||||
s = s + str(c['id']) + ","
|
s = s + str(c['name']) + ","
|
||||||
print(s)
|
print(s)
|
||||||
s = s[:-1]
|
s = s[:-1]
|
||||||
print(s)
|
print(s)
|
||||||
|
@ -301,7 +254,7 @@ class Teacher:
|
||||||
'email':self.email
|
'email':self.email
|
||||||
}
|
}
|
||||||
print(putDB(data, self.url))
|
print(putDB(data, self.url))
|
||||||
delDB("http://127.0.0.1:8000/classes/" + cid + "/")
|
delDB("http://127.0.0.1:8000/classes/" + cname + "/")
|
||||||
break
|
break
|
||||||
|
|
||||||
#remove locally
|
#remove locally
|
||||||
|
@ -312,108 +265,179 @@ class Teacher:
|
||||||
|
|
||||||
#remove from student directories
|
#remove from student directories
|
||||||
|
|
||||||
#make student repo by student id
|
|
||||||
def reqStudent(self, student, classes):
|
|
||||||
cid = None
|
|
||||||
for c in self.classes:
|
|
||||||
print(c['name'])
|
|
||||||
if classes == c['name']:
|
|
||||||
cid = str(c['id'])
|
|
||||||
data1 = getDB("http://127.0.0.1:8000/classes/" + cid)
|
|
||||||
if(student in data1['unconfirmed']):
|
|
||||||
print (student + " already requested.")
|
|
||||||
return
|
|
||||||
if(student in data1['confirmed']):
|
|
||||||
print (student + " alredy enrolled.")
|
|
||||||
break
|
|
||||||
if(cid==None):
|
|
||||||
print(classes +" does not exist.")
|
|
||||||
return
|
|
||||||
|
|
||||||
data = getDB("http://127.0.0.1:8000/students/" + student)
|
def isStudent(self, student):
|
||||||
try:
|
r = requests.get(url = "http://127.0.0.1:8000/students/" + student + "/", auth=('raffukhondaker','hackgroup1'))
|
||||||
if(data['added_to']==""):
|
if(r.status_code != 200):
|
||||||
data['added_to']=cid
|
return False
|
||||||
else:
|
return True
|
||||||
data['added_to']=data['added_to']+ "," + cid
|
|
||||||
except:
|
def reqStudent(self, sname, cname):
|
||||||
print(student + " does not exist.")
|
if(self.isStudent(sname) == False):
|
||||||
|
print(sname + " does not exist.")
|
||||||
return
|
return
|
||||||
print(data['added_to'])
|
course = getDB("http://127.0.0.1:8000/classes/" + cname)
|
||||||
d={
|
if(sname in course['unconfirmed']):
|
||||||
'first_name':data["first_name"],
|
print (sname + " already requested.")
|
||||||
'last_name':data["last_name"],
|
return
|
||||||
'git':data["git"],
|
if(sname in course['confirmed']):
|
||||||
'ion_user':data["ion_user"],
|
print (sname + " alredy enrolled.")
|
||||||
'student_id':data["student_id"],
|
return
|
||||||
'added_to':data['added_to'],
|
|
||||||
'classes':data["classes"],
|
student = getDB("http://127.0.0.1:8000/students/" + sname)
|
||||||
'email':data["email"],
|
try:
|
||||||
'grade':data["grade"],
|
if(student['added_to']==""):
|
||||||
'completed':data["completed"],
|
student['added_to']=course['name']
|
||||||
'repo':data["repo"]
|
else:
|
||||||
|
student['added_to']=student['added_to']+ "," + course['name']
|
||||||
|
except:
|
||||||
|
print(sname + " does not exist.")
|
||||||
|
return
|
||||||
|
print(student['added_to'])
|
||||||
|
s={
|
||||||
|
'first_name':student["first_name"],
|
||||||
|
'last_name':student["last_name"],
|
||||||
|
'git':student["git"],
|
||||||
|
'ion_user':student["ion_user"],
|
||||||
|
'student_id':student["student_id"],
|
||||||
|
'added_to':student['added_to'],
|
||||||
|
'classes':student["classes"],
|
||||||
|
'email':student["email"],
|
||||||
|
'grade':student["grade"],
|
||||||
|
'completed':student["completed"],
|
||||||
|
'repo':student["repo"]
|
||||||
}
|
}
|
||||||
print(putDB(d, data['url']))
|
student = putDB(s, student['url'])
|
||||||
data1 = getDB("http://127.0.0.1:8000/classes/" + cid)
|
|
||||||
if(data1['unconfirmed']==""):
|
if(course['unconfirmed']==""):
|
||||||
data1['unconfirmed']=data['ion_user']
|
course['unconfirmed']=student['ion_user']
|
||||||
else:
|
else:
|
||||||
data1['unconfirmed']=data1['unconfirmed']+ "," + data['ion_user']
|
course['unconfirmed']=course['unconfirmed']+ "," + student['ion_user']
|
||||||
d = {
|
cinfo = {
|
||||||
"name": classes,
|
"name": course['name'],
|
||||||
"repo": "",
|
"repo": "",
|
||||||
"path": self.username + "/" + classes,
|
"path": self.username + "/" + course['name'],
|
||||||
"teacher": self.username,
|
"teacher": self.username,
|
||||||
"assignments": "",
|
"assignments": "",
|
||||||
"default_file": "",
|
"default_file": "",
|
||||||
"confirmed": data1["confirmed"],
|
"confirmed": course["confirmed"],
|
||||||
"unconfirmed": data1['unconfirmed']
|
"unconfirmed": course['unconfirmed']
|
||||||
}
|
}
|
||||||
print(putDB(d, data1['url']))
|
print(putDB(cinfo, course['url']))
|
||||||
|
|
||||||
#confirmed students
|
#Student should have confirmed on their endd, but class had not been updated yet
|
||||||
# pull student work and push updates
|
#git clone confirmed student repo, copy files into repo and push branch
|
||||||
def updateStudent(self, student, classes):
|
def addStudent(self, sname, cname):
|
||||||
for c in self.classes:
|
if(self.isStudent(sname) == False):
|
||||||
if(c['name'] == classes):
|
print(sname + " does not exist.")
|
||||||
cid = c['id']
|
return
|
||||||
data = getDB("http://127.0.0.1:8000/classes/" + str(cid))
|
|
||||||
if(student in data['unconfirmed']):
|
|
||||||
print(student + " has not accepted request to " + classes)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
student = getDB("http://127.0.0.1:8000/students/" + sname)
|
||||||
|
course = getDB("http://127.0.0.1:8000/classes/" + cname)
|
||||||
|
|
||||||
|
if((student['ion_user'] in course['unconfirmed']) == False):
|
||||||
|
print("Student has not been requested to join yet.")
|
||||||
|
return
|
||||||
|
if((cname in student['added_to']) == True or (cname in student['classes']) == False):
|
||||||
|
print("Student has not confirmed class yet")
|
||||||
|
return
|
||||||
|
if(os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (student['ion_user'] in course['confirmed']) == True):
|
||||||
|
print("Student already added to class")
|
||||||
|
|
||||||
|
#git clone and make student/class directories
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
cpath = self.username + "/" + classes
|
cpath = self.username + "/" + cname
|
||||||
path = self.username + "/Students/" + classes
|
path = self.username + "/Students/" + cname
|
||||||
spath = self.username + "/Students/" + classes + "/" + student
|
spath = self.username + "/Students/" + cname + "/" + student['ion_user']
|
||||||
if(os.path.isdir(path) == False):
|
if(os.path.isdir(path) == False):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
if(os.path.isdir(spath) == False):
|
if(os.path.isdir(spath) == False):
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
student = getDB("http://127.0.0.1:8000/students/" + student)
|
|
||||||
command("git clone " + student['repo'])
|
command("git clone " + student['repo'])
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
copy_tree(cpath, path + "/" + student['ion_user'])
|
|
||||||
os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user'])
|
|
||||||
|
|
||||||
command('git checkout ' + classes)
|
#push to git
|
||||||
command('git pull origin ' + classes)
|
copy_tree(cpath, path + "/" + student['ion_user'])
|
||||||
|
os.chdir(spath)
|
||||||
|
command('git checkout ' + cname)
|
||||||
|
command('git pull origin ' + cname)
|
||||||
command('git add .')
|
command('git add .')
|
||||||
command('git commit -m Hello')
|
command('git commit -m Hello')
|
||||||
command('git push -u origin ' + classes)
|
command('git push -u origin ' + cname)
|
||||||
|
command('git checkout master')
|
||||||
|
|
||||||
|
if(course['confirmed']==""):
|
||||||
|
course['confirmed']=student['ion_user']
|
||||||
|
else:
|
||||||
|
course['confirmed']=course['confirmed']+ "," + student['ion_user']
|
||||||
|
cinfo = {
|
||||||
|
"name": course['name'],
|
||||||
|
"repo": "",
|
||||||
|
"path": course['path'],
|
||||||
|
"teacher": course['name'],
|
||||||
|
"assignments": "",
|
||||||
|
"default_file": "",
|
||||||
|
"confirmed": course["confirmed"],
|
||||||
|
"unconfirmed": course['unconfirmed']
|
||||||
|
}
|
||||||
|
print(putDB(cinfo, course['url']))
|
||||||
|
|
||||||
|
def addAssignment(self, path, course):
|
||||||
|
parts = path.split("/")
|
||||||
|
aname = parts[len(parts)-1]
|
||||||
|
if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in self.sclass:
|
||||||
|
print("Not valid path.")
|
||||||
|
return
|
||||||
|
if((parts[1] in self.sclass) == False):
|
||||||
|
print("Not in valid class directory")
|
||||||
|
return
|
||||||
|
ar = [x[2] for x in os.walk(path)]
|
||||||
|
print(ar)
|
||||||
|
for folder in ar:
|
||||||
|
if len(folder) == 0:
|
||||||
|
print("Assignment is completely empty, need a file.")
|
||||||
|
return
|
||||||
|
course = getDB("http://127.0.0.1:8000/classes/" + course)
|
||||||
|
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
|
||||||
|
cdir = os.getcwd()
|
||||||
|
for st in slist:
|
||||||
|
if st in course['confirmed']:
|
||||||
|
spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st)
|
||||||
|
if(os.path.exists(spath + "/" + aname) == False):
|
||||||
|
os.mkdir(spath + "/" + aname)
|
||||||
|
print(st)
|
||||||
|
print(copy_tree(path, spath + "/" + aname))
|
||||||
|
os.chdir(spath)
|
||||||
|
command('git checkout ' + course['name'])
|
||||||
|
command('git pull origin ' + course['name'])
|
||||||
|
command('git add .')
|
||||||
|
command('git commit -m Hello')
|
||||||
|
command('git push -u origin ' + course['name'])
|
||||||
|
os.chdir(cdir)
|
||||||
|
else:
|
||||||
|
print(st + " already has assignment")
|
||||||
|
|
||||||
|
def getHistory(self, student, course):
|
||||||
|
course = getDB("http://127.0.0.1:8000/classes/" + course)
|
||||||
|
try:
|
||||||
|
if((student in course['confirmed']) == False):
|
||||||
|
print("Student not in class")
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
print("class does not exist")
|
||||||
|
return
|
||||||
|
os.chdir(self.username + "/Students/" + course['name'] + "/" + student)
|
||||||
|
process = subprocess.Popen(['git', 'log', course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
|
p=process.poll()
|
||||||
|
output = process.communicate()[0].decode('utf-8')
|
||||||
|
print(output)
|
||||||
|
|
||||||
def comment(self):
|
def comment(self):
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
def addAssignment():
|
|
||||||
print()
|
|
||||||
|
|
||||||
def updateAssignnment():
|
def updateAssignnment():
|
||||||
print()
|
print()
|
||||||
|
|
||||||
data = getTeacher("mlauerbach")
|
data = getTeacher("eharris1")
|
||||||
t = Teacher(data)
|
t = Teacher(data)
|
||||||
t.reqStudent("2023rumareti", 'Math5_mlauerbach')
|
t.getHistory("2022rkhondak", "English11_eharris1")
|
||||||
t.updateStudent("2023rumareti", 'Math5_mlauerbach')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
22
Website/api/migrations/0007_auto_20200611_0831.py
Normal file
22
Website/api/migrations/0007_auto_20200611_0831.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-11 08:31
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0006_auto_20200610_0631'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='classes',
|
||||||
|
name='id',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='classes',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=100, primary_key=True, serialize=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -19,7 +19,7 @@ class Assignment(models.Model):
|
||||||
return '%s' % (self.name)
|
return '%s' % (self.name)
|
||||||
|
|
||||||
class Classes(models.Model):
|
class Classes(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(primary_key=True, max_length=100)
|
||||||
repo=models.URLField(default="")
|
repo=models.URLField(default="")
|
||||||
path=models.CharField(max_length=100, default="")
|
path=models.CharField(max_length=100, default="")
|
||||||
teacher=models.CharField(max_length=100, default="")
|
teacher=models.CharField(max_length=100, default="")
|
||||||
|
|
|
@ -20,7 +20,7 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
# default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
# default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Classes
|
model = Classes
|
||||||
fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id', 'confirmed', 'unconfirmed']
|
fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed']
|
||||||
|
|
||||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user