mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-20 20:30:18 -04:00
f
This commit is contained in:
parent
c9a71d6f24
commit
9755974491
|
@ -14,7 +14,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="d-flex align-items-center justify-content-center" style="height: 100vh">
|
<div class="d-flex align-items-center justify-content-center" style="height: 100vh">
|
||||||
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=QzCUoJEflSWlZe2v7Y3IQEXJFWKIOA" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
|
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=bVchSMe63qFXMYxOYthCfuqEr9FAdI" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
|
||||||
<img src="https://ion.tjhsst.edu/static/img/favicon.png">
|
<img src="https://ion.tjhsst.edu/static/img/favicon.png">
|
||||||
Sign in with Ion
|
Sign in with Ion
|
||||||
</a>
|
</a>
|
||||||
|
|
303
CLI/s-git.py
303
CLI/s-git.py
|
@ -1,101 +1,256 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import webbrowser
|
||||||
import pprint
|
import pprint
|
||||||
import json
|
import json
|
||||||
|
import shutil
|
||||||
|
import time
|
||||||
|
import pyperclip
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
def initStudent(ion_user):
|
|
||||||
#check if git has already been initialized
|
|
||||||
if(os.path.exists(str(ion_user) +"/" + ".git")):
|
|
||||||
print("Already synced to: " + str(ion_user))
|
|
||||||
return
|
|
||||||
|
|
||||||
#get student repo from API
|
#get teacher info from api
|
||||||
|
def getStudent(ion_user):
|
||||||
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
||||||
r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr'))
|
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
||||||
if(r.status_code == 200):
|
if(r.status_code == 200):
|
||||||
data = r.json()
|
data = r.json()
|
||||||
repo = data['repo']
|
return data
|
||||||
classes = data['classes']
|
|
||||||
print(data)
|
|
||||||
#git clone repo
|
|
||||||
process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
|
|
||||||
# make classes directory
|
|
||||||
for c in classes:
|
|
||||||
cpath = str(ion_user) + "/" + c['name']
|
|
||||||
if(os.path.exists(cpath)):
|
|
||||||
print(cpath + " already exists...")
|
|
||||||
else:
|
|
||||||
os.mkdir(str(ion_user) + "/" + c['name'])
|
|
||||||
|
|
||||||
#make assignments directory
|
|
||||||
for a in c['assignments']:
|
|
||||||
path = str(ion_user) + "/" + c['name'] + "/" + a['name']
|
|
||||||
print(path)
|
|
||||||
if(os.path.exists("/" +path)):
|
|
||||||
print(path + " already exists...")
|
|
||||||
else:
|
|
||||||
os.mkdir(str(ion_user) + "/" + c['name'] + "/" + a['name'])
|
|
||||||
|
|
||||||
#push to remote repo
|
|
||||||
os.chdir(ion_user)
|
|
||||||
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
|
|
||||||
elif(r.status_code == 404):
|
elif(r.status_code == 404):
|
||||||
|
return None
|
||||||
print("Make new account!")
|
print("Make new account!")
|
||||||
elif(r.status_code == 403):
|
elif(r.status_code == 403):
|
||||||
|
return None
|
||||||
print("Invalid username/password")
|
print("Invalid username/password")
|
||||||
else:
|
else:
|
||||||
|
return None
|
||||||
print(r.status_code)
|
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 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(" ")
|
||||||
|
for c in command:
|
||||||
|
ar.append(c)
|
||||||
|
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
|
p=process.poll()
|
||||||
|
output = process.communicate()[1]
|
||||||
|
print(output.decode('utf-8'))
|
||||||
|
|
||||||
|
####################################################################################################################################
|
||||||
|
|
||||||
|
#public methods: deleteClass, makeClass, update
|
||||||
|
class Student:
|
||||||
|
def __init__(self, data):
|
||||||
|
# teacher info already stored in API
|
||||||
|
# intitialze fields after GET request
|
||||||
|
self.first_name=data['first_name']
|
||||||
|
self.last_name=data['last_name']
|
||||||
|
self.git=data['git']
|
||||||
|
self.username=data['ion_user']
|
||||||
|
self.url= "http://127.0.0.1:8000/students/" + self.username + "/"
|
||||||
|
self.email = data['email']
|
||||||
|
self.grade = data['grade']
|
||||||
|
self.student_id=data['student_id']
|
||||||
|
self.completed = data['completed']
|
||||||
|
#classes in id form (Example: 4,5)
|
||||||
|
|
||||||
|
#storing actual classes
|
||||||
|
cid=data['classes'].split(",")
|
||||||
|
try:
|
||||||
|
cid.remove('')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
cid.remove("")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
classes=[]
|
||||||
|
for c in cid:
|
||||||
|
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
||||||
|
classes.append(getDB(url))
|
||||||
|
|
||||||
|
self.classes = classes
|
||||||
|
self.sclass=str(data['classes'])
|
||||||
|
|
||||||
|
#storing added_to classes
|
||||||
|
nid=data['added_to'].split(",")
|
||||||
|
try:
|
||||||
|
nid.remove('')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
nid.remove("")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
nclasses=[]
|
||||||
|
for c in nid:
|
||||||
|
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
||||||
|
nclasses.append(getDB(url))
|
||||||
|
|
||||||
|
self.new = nclasses
|
||||||
|
self.snew=str(data['added_to'])
|
||||||
|
if(os.path.isdir(self.username)):
|
||||||
|
print("Synced to " + self.username)
|
||||||
|
else:
|
||||||
|
os.mkdir(self.username)
|
||||||
|
|
||||||
|
|
||||||
#Teachers
|
#update API and Github, all assignments / classes
|
||||||
|
def update(self):
|
||||||
|
#lists all classes
|
||||||
|
ignore=['.DS_Store']
|
||||||
|
classes = os.listdir(self.username)
|
||||||
|
for i in ignore:
|
||||||
|
try:
|
||||||
|
classes.remove(i)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
#make student repo by student id
|
for i in range(len(classes)):
|
||||||
def addStudent(stid, teacher):
|
c = classes[i]
|
||||||
os.mkdir(stid)
|
path = self.username + "/" + c
|
||||||
os.chdir(os.getcwd() + "/" + stid)
|
#lists all assignments and default files
|
||||||
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
#push to git
|
||||||
process.communicate()
|
isclass = False
|
||||||
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
for d in os.listdir(path):
|
||||||
process.communicate()
|
if(d == '.git'):
|
||||||
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
isclass=True
|
||||||
process.communicate()
|
break
|
||||||
|
if(isclass):
|
||||||
|
loc = os.getcwd()
|
||||||
|
os.chdir(path)
|
||||||
|
command('git fetch origin')
|
||||||
|
command('git checkout ' + self.username)
|
||||||
|
command('git add .')
|
||||||
|
command('git commit -m ' + self.username + '-update')
|
||||||
|
command('git push -u origin ' + self.username)
|
||||||
|
command('git merge master')
|
||||||
|
os.chdir(loc)
|
||||||
|
print("Updated: " + c)
|
||||||
|
else:
|
||||||
|
print(d + " is not a class")
|
||||||
|
|
||||||
def addStudents(filename):
|
#class name format: <course-name>_<ion_user>
|
||||||
print(filename)
|
|
||||||
|
|
||||||
def addAsignment(name):
|
|
||||||
print(name)
|
|
||||||
|
|
||||||
def updateAssignment(name):
|
#add classes from 'new' field
|
||||||
print(name)
|
def addClass(self, cid):
|
||||||
|
if((cid in self.snew) == False):
|
||||||
|
if((cid in self.sclass) == True):
|
||||||
|
print("Already enrolled in this class.")
|
||||||
|
else:
|
||||||
|
print("Not added by teacher yet.")
|
||||||
|
return None
|
||||||
|
data = getDB('http://127.0.0.1:8000/classes/'+cid)
|
||||||
|
|
||||||
def comment(filename, text):
|
#clone class repo and make student branch (branch name: username)
|
||||||
print(text)
|
os.chdir(self.username)
|
||||||
|
command("git clone " + data['repo'])
|
||||||
|
os.chdir(data['name'])
|
||||||
|
command("git checkout " + self.username)
|
||||||
|
command("git push -u origin " + self.username)
|
||||||
|
|
||||||
#initStudent("2022rkhondak")
|
self.classes.append(data)
|
||||||
ion_user = "2022rkhondak"
|
if(len(self.sclass)==0):
|
||||||
headers = {'Content-type': 'application/json'}
|
self.sclass = data['id']
|
||||||
data = {'first_name': 'Jeff',
|
else:
|
||||||
'git': 'https://github.com/',
|
self.sclass = self.sclass + "," + str(data['id'])
|
||||||
'grade': 10,
|
|
||||||
'ion_user': '2022jlol1',
|
#upddate self.new
|
||||||
'last_name': 'lol.',
|
s=""
|
||||||
'student_id': 11111
|
nar = ''
|
||||||
|
for i in range(len(self.new)):
|
||||||
|
if(self.new[i]['id'] == int(data['id'])):
|
||||||
|
print("DELETE: " + self.new[i]['name'])
|
||||||
|
del self.new[i]
|
||||||
|
#recreate sclass field, using ids
|
||||||
|
for c in self.new:
|
||||||
|
s = s + str(c['id']) + ","
|
||||||
|
nar.append(c)
|
||||||
|
self.snew=s
|
||||||
|
self.new=nar
|
||||||
|
break
|
||||||
|
|
||||||
|
#update teacher instance in db, classes field
|
||||||
|
data={
|
||||||
|
'first_name':self.first_name,
|
||||||
|
'last_name':self.last_name,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username,
|
||||||
|
'student_id':self.student_id,
|
||||||
|
'added_to':self.snew,
|
||||||
|
'url':self.url,
|
||||||
|
'classes':self.sclass,
|
||||||
|
'email':self.email,
|
||||||
|
'grade':self.grade,
|
||||||
|
'completed':self.completed
|
||||||
}
|
}
|
||||||
data = json.dumps(data)
|
print(self.url)
|
||||||
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
print(putDB(data, self.url))
|
||||||
r = requests.put(url = URL, data= data, headers=headers ,auth=('raffukhondaker','hackgroup1'))
|
return data
|
||||||
pprint.pprint(r.json())
|
|
||||||
|
def submit(self, path):
|
||||||
|
#2022rkhondak/English11_eharris1/Essay1
|
||||||
|
#check if valid assignment
|
||||||
|
parts = path.split("/")
|
||||||
|
if(len(parts) != 3):
|
||||||
|
print("Assignment path too short")
|
||||||
|
return
|
||||||
|
isclass = False
|
||||||
|
for c in self.classes:
|
||||||
|
if(c['name'] == parts[1]):
|
||||||
|
isclass==True
|
||||||
|
break
|
||||||
|
if(parts[0] != self.username and isclass and os.path.isdir(path) == False):
|
||||||
|
print("Not valid assignment")
|
||||||
|
return
|
||||||
|
if((parts[1] + "/" + parts[2]) in self.completed):
|
||||||
|
print(parts[2] + " already submited. ")
|
||||||
|
# return
|
||||||
|
resp = input("Are you sure you want to submit? You cannot do this again.(y/N) ")
|
||||||
|
if(resp == 'y'):
|
||||||
|
os.chdir(self.username + "/" + parts[1])
|
||||||
|
command("git add .")
|
||||||
|
command("git commit -m submit")
|
||||||
|
command("git tag " + parts[1] + "-final")
|
||||||
|
command("git push -u origin " + self.username + " --tags")
|
||||||
|
self.completed = self.completed + "," + parts[1] + "/" + parts[2]
|
||||||
|
data={
|
||||||
|
'first_name':self.first_name,
|
||||||
|
'last_name':self.last_name,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username,
|
||||||
|
'student_id':self.student_id,
|
||||||
|
'added_to':self.snew,
|
||||||
|
'url':self.url,
|
||||||
|
'classes':self.sclass,
|
||||||
|
'email':self.email,
|
||||||
|
'grade':self.grade,
|
||||||
|
'completed':self.completed
|
||||||
|
}
|
||||||
|
#print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/"))
|
||||||
|
|
||||||
|
data = getStudent("2022rkhondak")
|
||||||
|
s = Student(data)
|
||||||
|
s.update()
|
567
CLI/t-git-old.py
567
CLI/t-git-old.py
|
@ -4,46 +4,12 @@ import requests
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import pprint
|
import pprint
|
||||||
import json
|
import json
|
||||||
|
import shutil
|
||||||
|
import time
|
||||||
|
import pyperclip
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
'''
|
|
||||||
{
|
|
||||||
"url": "http://127.0.0.1:8000/teachers/eharris1/",
|
|
||||||
"first_name": "Errin",
|
|
||||||
"last_name": "Harris",
|
|
||||||
"classes": [
|
|
||||||
{
|
|
||||||
"url": "http://127.0.0.1:8000/classes/1/",
|
|
||||||
"name": "Math5",
|
|
||||||
"assignments": [
|
|
||||||
{
|
|
||||||
"name": "Week1_HW",
|
|
||||||
"due_date": "2020-06-07T07:46:30.537197Z",
|
|
||||||
"url": "http://127.0.0.1:8000/assignments/1/",
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"name": "instructions.txt"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Week2_HW",
|
|
||||||
"due_date": "2020-06-07T07:46:30.548596Z",
|
|
||||||
"url": "http://127.0.0.1:8000/assignments/2/",
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"name": "instructions.txt"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"repo": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"git": "therealraffi",
|
|
||||||
"ion_user": "eharris1"
|
|
||||||
},
|
|
||||||
'''
|
|
||||||
#get teacher info from api
|
#get teacher info from api
|
||||||
def getTeacher(ion_user):
|
def getTeacher(ion_user):
|
||||||
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
||||||
|
@ -63,8 +29,37 @@ def getTeacher(ion_user):
|
||||||
|
|
||||||
def getDB(url):
|
def getDB(url):
|
||||||
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
||||||
return r.json()
|
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 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(" ")
|
||||||
|
for c in command:
|
||||||
|
ar.append(c)
|
||||||
|
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
|
p=process.poll()
|
||||||
|
output = process.communicate()[1]
|
||||||
|
#print(output.decode('utf-8'))
|
||||||
|
|
||||||
|
####################################################################################################################################
|
||||||
|
|
||||||
|
#public methods: deleteClass, makeClass, update
|
||||||
class Teacher:
|
class Teacher:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
# teacher info already stored in API
|
# teacher info already stored in API
|
||||||
|
@ -74,260 +69,78 @@ class Teacher:
|
||||||
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/teachers/" + self.username + "/"
|
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
||||||
|
self.email = data['email']
|
||||||
|
#classes in id form (Example: 4,5)
|
||||||
|
|
||||||
classes=data['classes'].split(",")
|
cid=data['classes'].split(",")
|
||||||
cdict = []
|
try:
|
||||||
for cid in classes:
|
cid.remove('')
|
||||||
adict=[]
|
except:
|
||||||
c = getDB("http://127.0.0.1:8000/classes/" + cid + "/")
|
pass
|
||||||
name=c['name']
|
try:
|
||||||
repo=c['repo']
|
cid.remove("")
|
||||||
path=c['path']
|
except:
|
||||||
teacher=c['teacher']
|
pass
|
||||||
id=c['id']
|
classes=[]
|
||||||
assignments=c['assignments'].split(",")
|
for c in cid:
|
||||||
dfs = c['default_file'].split(' ')
|
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
||||||
dfdict=[]
|
classes.append(getDB(url))
|
||||||
for fid in dfs:
|
|
||||||
f = getDB("http://127.0.0.1:8000/files/" + fid + "/")
|
|
||||||
fname=f['name']
|
|
||||||
fpath=f['path']
|
|
||||||
dfdict.append({
|
|
||||||
'name':fname,
|
|
||||||
'path':fpath,
|
|
||||||
'classes':classes,
|
|
||||||
'assignment':"none",
|
|
||||||
'id':fid,
|
|
||||||
})
|
|
||||||
for aid in assignments:
|
|
||||||
fdict=[]
|
|
||||||
a = getDB("http://127.0.0.1:8000/assignments/" + aid + "/")
|
|
||||||
aname= a['name']
|
|
||||||
due_date = a['due_date']
|
|
||||||
apath=a['path']
|
|
||||||
classes=a['classes']
|
|
||||||
files = a['files'].split(' ')
|
|
||||||
for fid in files:
|
|
||||||
f = getDB("http://127.0.0.1:8000/files/" + fid + "/")
|
|
||||||
fname=f['name']
|
|
||||||
fpath=f['path']
|
|
||||||
fdict.append({
|
|
||||||
'name':fname,
|
|
||||||
'path':fpath,
|
|
||||||
'classes':classes,
|
|
||||||
'assignment':aname,
|
|
||||||
'id':fid,
|
|
||||||
})
|
|
||||||
adict.append({
|
|
||||||
'name':aname,
|
|
||||||
'due_date':due_date,
|
|
||||||
'path':apath,
|
|
||||||
'classes':classes,
|
|
||||||
'teacher':teacher,
|
|
||||||
'files':fdict,
|
|
||||||
})
|
|
||||||
cdict.append({
|
|
||||||
'name':name,
|
|
||||||
'path':path,
|
|
||||||
'teacher':teacher,
|
|
||||||
'assignments':adict,
|
|
||||||
'default_file':adict,
|
|
||||||
})
|
|
||||||
|
|
||||||
self.classes = cdict
|
self.classes = classes
|
||||||
|
self.sclass=str(data['classes'])
|
||||||
def command(self,command):
|
if(os.path.isdir(self.username)):
|
||||||
ar = []
|
print("Synced to " + self.username)
|
||||||
command = command.split(" ")
|
else:
|
||||||
for c in command:
|
|
||||||
ar.append(c)
|
|
||||||
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
p=process.poll()
|
|
||||||
output = process.communicate()[0]
|
|
||||||
#print(output.decode('utf-8'))
|
|
||||||
|
|
||||||
def initTeacher(self):
|
|
||||||
if(os.path.exists(self.username )):
|
|
||||||
print("Already synced to: " + str(self.username))
|
|
||||||
return
|
|
||||||
os.mkdir(self.username)
|
os.mkdir(self.username)
|
||||||
classes = self.classes
|
|
||||||
# make classes directory
|
|
||||||
for c in classes:
|
|
||||||
cname= c['name']
|
|
||||||
cpath = self.username + "/" + cname
|
|
||||||
|
|
||||||
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
|
||||||
webbrowser.open('https://github.com/new')
|
|
||||||
input("Repo created? (Press any key to continue)\n")
|
|
||||||
|
|
||||||
url='https://github.com/' + self.git + "/" + cname
|
|
||||||
print(url)
|
|
||||||
while(requests.get(url).status_code != 200):
|
|
||||||
print(requests.get(url))
|
|
||||||
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
|
||||||
if(r=="N" or r=="No"):
|
|
||||||
return
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.chdir(self.username)
|
|
||||||
self.command('git clone ' + url)
|
|
||||||
os.chdir(cdir)
|
|
||||||
|
|
||||||
#make class directory
|
|
||||||
#make default files for each class
|
|
||||||
for filename in c['default_file']:
|
|
||||||
f=open(cpath+"/"+filename['name'], "w")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
#make assignments directory
|
|
||||||
for a in c['assignments']:
|
|
||||||
path = cpath + "/" + a['name']
|
|
||||||
if(os.path.exists(path)):
|
|
||||||
print(path + " already exists...")
|
|
||||||
else:
|
|
||||||
os.mkdir(path)
|
|
||||||
f=open(path + "/instructions.txt", "w")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
#push to remote repo
|
|
||||||
os.chdir(cpath)
|
|
||||||
print(cpath)
|
|
||||||
self.command('git add .')
|
|
||||||
self.command('git commit -m Hello_Class')
|
|
||||||
self.command('git push -u origin master')
|
|
||||||
|
|
||||||
def checkGit(self, ass):
|
|
||||||
for a in ass:
|
|
||||||
if a =='.git':
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def compareDB(self, fdict, url):
|
|
||||||
URL = url
|
|
||||||
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
data = r.json()['results']
|
|
||||||
allfiles = data
|
|
||||||
# far = []
|
|
||||||
# for f in allfiles:
|
|
||||||
# far.append(f['path'])
|
|
||||||
|
|
||||||
for f in fdict:
|
|
||||||
URL = url
|
|
||||||
in_db = False
|
|
||||||
pid=None
|
|
||||||
for dbf in allfiles:
|
|
||||||
if(dbf['path'] == f['path']):
|
|
||||||
in_db=True
|
|
||||||
break
|
|
||||||
if(in_db==False):
|
|
||||||
r = requests.post(url = URL, data=f , auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("POST: (" + URL + "): " + f['path'])
|
|
||||||
f['url']=r.json()['url']
|
|
||||||
print(r.status_code)
|
|
||||||
else:
|
|
||||||
URL = URL + str(dbf['id']) + "/"
|
|
||||||
r = requests.put(url = URL, data=f , auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print(r.status_code)
|
|
||||||
print("UPDATED: (" + URL + "): " + f['path'])
|
|
||||||
f['url']=r.json()['url']
|
|
||||||
f['id']=dbf['id']
|
|
||||||
print(f)
|
|
||||||
|
|
||||||
return fdict
|
|
||||||
|
|
||||||
#update API and Github, all assignments / classes
|
#update API and Github, all assignments / classes
|
||||||
def update(self):
|
def update(self):
|
||||||
#lists all classes
|
#lists all classes
|
||||||
|
ignore=['.git','.DS_Store']
|
||||||
classes = os.listdir(self.username)
|
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
|
#checks all class directories first
|
||||||
for c in classes:
|
for c in classes:
|
||||||
path = self.username + "/" + c
|
path = self.username + "/" + c
|
||||||
if(self.checkClass(path) == False):
|
if(self.checkClass(path) == False):
|
||||||
return
|
return
|
||||||
cdict = []
|
extra.remove(path)
|
||||||
for c in classes:
|
print("Current classes: " + path)
|
||||||
|
|
||||||
|
for e in extra:
|
||||||
|
self.deleteClass(e)
|
||||||
|
|
||||||
|
for i in range(len(classes)):
|
||||||
|
c = classes[i]
|
||||||
path = self.username + "/" + c
|
path = self.username + "/" + c
|
||||||
#lists all assignments and default files
|
#lists all assignments and default files
|
||||||
ass = os.listdir(path)
|
|
||||||
#if no .git, directory not synced to git or API
|
#if no .git, directory not synced to git or API
|
||||||
if (self.checkGit(ass)==False):
|
if (self.checkInDB(path)==False):
|
||||||
self.addClass(path)
|
self.addClass(path)
|
||||||
else:
|
else:
|
||||||
#push to git
|
#push to git
|
||||||
loc = os.getcwd()
|
loc = os.getcwd()
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
self.command('git add .')
|
command('git fetch origin')
|
||||||
self.command('git commit -m "Update"')
|
command('git pull origin master')
|
||||||
self.command('git push -u origin master')
|
command('git add .')
|
||||||
|
command('git commit -m "Update"')
|
||||||
|
command('git push -u origin master')
|
||||||
os.chdir(loc)
|
os.chdir(loc)
|
||||||
ass.remove('.git')
|
|
||||||
|
|
||||||
loc = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
repo = self.command('git config --get remote.origin.url')
|
|
||||||
os.chdir(loc)
|
|
||||||
|
|
||||||
#assignments
|
|
||||||
adict = []
|
|
||||||
#default files for classes
|
|
||||||
fdict=[]
|
|
||||||
#default files for assignments
|
|
||||||
afdict=[]
|
|
||||||
for a in ass:
|
|
||||||
aname=a
|
|
||||||
path = self.username + "/" + c + "/" + a
|
|
||||||
#need to add option
|
|
||||||
due_date= '2020-06-07T07:46:30.537197Z',
|
|
||||||
#check for default file
|
|
||||||
if(os.path.isfile(path)):
|
|
||||||
fdict.append({
|
|
||||||
'name':a,
|
|
||||||
'path':path
|
|
||||||
})
|
|
||||||
elif(os.path.isdir(path)):
|
|
||||||
for af in os.listdir(path):
|
|
||||||
path = path+ "/" + af
|
|
||||||
if(os.path.isfile(path)):
|
|
||||||
afdict.append({
|
|
||||||
'name':af,
|
|
||||||
'path':path
|
|
||||||
})
|
|
||||||
path = self.username + "/" + c + "/" + a
|
|
||||||
adict.append({
|
|
||||||
'name':aname,
|
|
||||||
'due_date': due_date[0],
|
|
||||||
'path':path,
|
|
||||||
'files':afdict
|
|
||||||
})
|
|
||||||
|
|
||||||
fdict=self.compareDB(fdict, "http://127.0.0.1:8000/files/")
|
|
||||||
afdict=self.compareDB(afdict,"http://127.0.0.1:8000/files/")
|
|
||||||
|
|
||||||
adict=self.compareDB(adict, 'http://127.0.0.1:8000/assignments/')
|
|
||||||
|
|
||||||
path = self.username + "/" + c
|
|
||||||
cdict.append({
|
|
||||||
'name':c,
|
|
||||||
'repo': repo,
|
|
||||||
'path':path,
|
|
||||||
'assignments':adict,
|
|
||||||
'default_file':fdict,
|
|
||||||
})
|
|
||||||
cdict=self.compareDB(cdict,'http://127.0.0.1:8000/classes/')
|
|
||||||
|
|
||||||
mdict= {
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'classes':cdict,
|
|
||||||
}
|
|
||||||
|
|
||||||
data = json.dumps(mdict)
|
|
||||||
# r = requests.put(url = 'http://127.0.0.1:8000/teachers/eharris1/', data=data, headers={'Content-type': 'application/json'} , auth=('raffukhondaker','hackgroup1'))
|
|
||||||
# print(print(r.json()))
|
|
||||||
|
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
|
@ -336,8 +149,11 @@ 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)):
|
||||||
|
print(path + " must be in a Class directory.")
|
||||||
|
return False
|
||||||
if(("_" + self.username) in cname) == False:
|
if(("_" + self.username) in cname) == False:
|
||||||
print("Incorrect class name: Must be in the format: <course-name>_<ion_user>")
|
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
|
||||||
|
@ -349,98 +165,199 @@ class Teacher:
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
if(os.path.isfile(d)):
|
if(os.path.isfile(d)):
|
||||||
deffile=True
|
deffile=True
|
||||||
if(os.path.isdir(d)) and d != '.git':
|
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(d)
|
asdir = os.listdir(path + "/" + d)
|
||||||
for a in asdir:
|
for a in asdir:
|
||||||
if(os.path.isfile(a)):
|
if(os.path.isfile(path + "/" + d + "/" +a)):
|
||||||
as_file=True
|
as_file=True
|
||||||
if(as_file==False):
|
if(as_file==False):
|
||||||
as_bad = a
|
as_bad = d
|
||||||
break
|
break
|
||||||
if(as_file==False):
|
if(as_file==False):
|
||||||
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):
|
if(deffile==False):
|
||||||
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
|
||||||
|
|
||||||
|
def checkInDB(self, path):
|
||||||
|
n = path.split("/")
|
||||||
|
n = n[len(n)-1]
|
||||||
|
for c in self.classes:
|
||||||
|
if(n == c['name']):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
#adds class to git, not API
|
#adds class to git, not API
|
||||||
|
#Assuming valid class name
|
||||||
def addClasstoGit(self, path):
|
def addClasstoGit(self, path):
|
||||||
cname = path.split("/")
|
cname = path.split("/")
|
||||||
cname = cname[len(cname)-1]
|
cname = cname[len(cname)-1]
|
||||||
#push to remote repo
|
#push to remote repo
|
||||||
if(self.checkClass(path)):
|
url='https://github.com/' + self.git + "/" + cname
|
||||||
|
if(requests.get(url).status_code != 200):
|
||||||
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
||||||
|
try:
|
||||||
|
pyperclip.copy(cname)
|
||||||
|
print(cname + " copied to clipboard.")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
time.sleep(2)
|
||||||
webbrowser.open('https://github.com/new')
|
webbrowser.open('https://github.com/new')
|
||||||
input("Repo created? (Press any key to continue)\n")
|
input("Repo created? (Press any key to continue)\n")
|
||||||
|
|
||||||
url='https://github.com/' + self.git + "/" + cname
|
|
||||||
print(url)
|
print(url)
|
||||||
while(requests.get(url).status_code != 200):
|
while(requests.get(url).status_code != 200):
|
||||||
print(requests.get(url))
|
|
||||||
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
||||||
if(r=="N" or r=="No"):
|
if(r=="N" or r=="No"):
|
||||||
return None
|
return None
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
self.command('git init')
|
command('git init')
|
||||||
self.command('git add .')
|
command('git add .')
|
||||||
self.command('git commit -m Hello_Class')
|
command('git commit -m Hello_Class')
|
||||||
self.command('git remote add origin ' + url + '.git')
|
command('git remote add origin ' + url + '.git')
|
||||||
self.command('git push -u origin master')
|
command('git push -u origin master')
|
||||||
|
else:
|
||||||
|
cdir = os.getcwd()
|
||||||
|
os.chdir(path)
|
||||||
|
print("Repo already exists. Cloning instead.")
|
||||||
|
command('git clone')
|
||||||
|
command('git fetch origin')
|
||||||
|
command('git pull')
|
||||||
|
command('git add .')
|
||||||
|
command('git commit -m Hello_Class')
|
||||||
|
command('git push -u origin master')
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
print(cdir)
|
||||||
|
data={
|
||||||
|
'name':cname,
|
||||||
|
'repo':url,
|
||||||
|
'path':path,
|
||||||
|
'teacher':self.username,
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|
||||||
|
#make class from existing directory, add to git and api
|
||||||
|
def addClass(self, path):
|
||||||
|
if (self.checkClass(path)):
|
||||||
|
data = self.addClasstoGit(path)
|
||||||
|
#make class instance in db
|
||||||
|
data = postDB(data, 'http://127.0.0.1:8000/classes/')
|
||||||
|
#add to instance
|
||||||
|
#upate self.classes
|
||||||
|
self.classes.append(data)
|
||||||
|
if(len(self.sclass)==0):
|
||||||
|
self.sclass = data['id']
|
||||||
|
else:
|
||||||
|
self.sclass = self.sclass + "," + str(data['id'])
|
||||||
|
|
||||||
|
#update teacher instance in db, classes field
|
||||||
|
data={
|
||||||
|
'first_name':self.first_name,
|
||||||
|
'last_name':self.last_name,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username,
|
||||||
|
'url':self.url,
|
||||||
|
'classes':self.sclass,
|
||||||
|
'email':self.email
|
||||||
|
}
|
||||||
|
putDB(data, self.url)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
#make a new class from scratch
|
||||||
def makeClass(self, subject):
|
#subject: string, assignments: list
|
||||||
cname = subject + "_" + self.username
|
#class name must be: <subject>_<ion_user>
|
||||||
os.chdir(self.username)
|
def makeClass(self, cname, assignments):
|
||||||
#check if class exists
|
#check if class exists
|
||||||
if(os.path.exists(cname)):
|
path = self.username + "/" + cname
|
||||||
print("Already synced to: " + str(self.username))
|
if(os.path.exists(path)):
|
||||||
|
print("Class already exists: " + cname)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
os.mkdir(cname)
|
if((("_" + self.username) in cname) == False):
|
||||||
f=open(cname + "/README.md", "w")
|
print("class name must be: "+ cname + "_" + self.username)
|
||||||
|
return
|
||||||
|
cdir = os.getcwd()
|
||||||
|
os.mkdir(path)
|
||||||
|
f=open(path + "/README.md", "w")
|
||||||
f.close()
|
f.close()
|
||||||
#push to remote repo
|
#push to remote repo
|
||||||
os.chdir(cname)
|
os.chdir(path)
|
||||||
command(self, 'git init')
|
for a in assignments:
|
||||||
command(self, 'git add .')
|
os.mkdir(a)
|
||||||
command(self, 'git commit -m "Hello Class!"')
|
f=open(a + "/instructions.txt", "w")
|
||||||
#git remote add origin git@github.com:alexpchin/<reponame>.git
|
f.close()
|
||||||
command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git")
|
os.chdir(cdir)
|
||||||
command(self, 'git push -u origin master')
|
|
||||||
|
|
||||||
cinfo=[
|
data = self.addClass(path)
|
||||||
{
|
return data
|
||||||
"name":cname,
|
|
||||||
"assignments":[],
|
|
||||||
"repo": "https://github.com:" + self.git + "/" + cname + ".git",
|
|
||||||
"default_file": [
|
|
||||||
{
|
|
||||||
"name":"README.md"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
#update rest API
|
def deleteClass(self, path):
|
||||||
self.classes.append(cinfo)
|
if(os.path.exists(path) == False):
|
||||||
update(self)
|
print(path + " does not exist locally.")
|
||||||
data = {
|
resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ")
|
||||||
"url": self.url,
|
if(resp != 'y'):
|
||||||
"first_name": self.first_name,
|
return
|
||||||
"last_name": self.first_name,
|
|
||||||
"classes": self.classes,
|
cname = path.split("/")
|
||||||
"git": self.git,
|
cname = cname[len(cname)-1]
|
||||||
"ion_user": self.username
|
cid = None
|
||||||
},
|
repo = ''
|
||||||
r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
for c in self.classes:
|
||||||
|
if cname == c['name']:
|
||||||
|
cid = str(c['id'])
|
||||||
|
repo = c['repo']
|
||||||
|
|
||||||
|
#remove from api
|
||||||
|
for i in range(len(self.classes)):
|
||||||
|
if(self.classes[i]['id'] == int(cid)):
|
||||||
|
print("DELETE: " + self.classes[i]['name'])
|
||||||
|
del self.classes[i]
|
||||||
|
s=""
|
||||||
|
#recreate sclass field, using ids
|
||||||
|
for c in self.classes:
|
||||||
|
s = s + str(c['id']) + ","
|
||||||
|
print(s)
|
||||||
|
s = s[:-1]
|
||||||
|
print(s)
|
||||||
|
data={
|
||||||
|
'first_name':self.first_name,
|
||||||
|
'last_name':self.last_name,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username,
|
||||||
|
'url':self.url,
|
||||||
|
'classes':s,
|
||||||
|
'email':self.email
|
||||||
|
}
|
||||||
|
print(putDB(data, self.url))
|
||||||
|
delDB("http://127.0.0.1:8000/classes/" + cid + "/")
|
||||||
|
break
|
||||||
|
|
||||||
|
#remove locally
|
||||||
|
try:
|
||||||
|
shutil.rmtree(path)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
#remove from git
|
||||||
|
input("Delete repository: " + cname + ". Scroll to the bottom of the page and press 'Delete this repository' (Press any key to continue) ")
|
||||||
|
print(repo)
|
||||||
|
time.sleep(2)
|
||||||
|
webbrowser.open(repo + "/settings")
|
||||||
|
input("Repo deleted? (Press any key to continue) ")
|
||||||
|
|
||||||
|
print(repo)
|
||||||
|
while(requests.get(repo).status_code == 200):
|
||||||
|
r = input("Repo still no deleted yet. (Press any key to continue after repo deleted, or 'N' to exit)\n")
|
||||||
|
if(r=="N" or r=="No" or r=='n'):
|
||||||
|
return None
|
||||||
|
|
||||||
#make student repo by student id
|
#make student repo by student id
|
||||||
def addStudent(self,stid):
|
def addStudent(self,stid):
|
||||||
|
@ -449,9 +366,7 @@ class Teacher:
|
||||||
def comment(self):
|
def comment(self):
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
# data = getData("eharris1")
|
data = getTeacher("eharris1")
|
||||||
data={'url': 'http://127.0.0.1:8000/teachers/eharris1/', 'first_name': 'Errin', 'last_name': 'Harris', 'git': 'therealraffi', 'ion_user': 'eharris1', 'classes': [{'url': 'http://127.0.0.1:8000/classes/1/', 'name': 'Math5_eharris1', 'repo': 'http://127.0.0.1:8000/assignments/3/', 'assignments': [{'name': 'Week1_HW', 'due_date': '2020-06-07T07:46:30.537197Z', 'url': 'http://127.0.0.1:8000/assignments/1/', 'files': [{'name': 'instructions.txt'}]}, {'name': 'Week2_HW', 'due_date': '2020-06-07T07:46:30.548596Z', 'url': 'http://127.0.0.1:8000/assignments/2/', 'files': [{'name': 'instructions.txt'}]}], 'default_file': [{'name': 'instructions.txt'}]}]}
|
|
||||||
t = Teacher(data)
|
t = Teacher(data)
|
||||||
|
t.makeClass('English11_eharris1', ["Essay1"])
|
||||||
t.update()
|
t.update()
|
||||||
|
|
||||||
|
|
||||||
|
|
366
CLI/t-git.py
366
CLI/t-git.py
|
@ -1,366 +0,0 @@
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
import requests
|
|
||||||
import webbrowser
|
|
||||||
import pprint
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
import time
|
|
||||||
import pyperclip
|
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
|
||||||
|
|
||||||
#get teacher info from api
|
|
||||||
def getTeacher(ion_user):
|
|
||||||
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
|
||||||
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
if(r.status_code == 200):
|
|
||||||
data = r.json()
|
|
||||||
return data
|
|
||||||
elif(r.status_code == 404):
|
|
||||||
return None
|
|
||||||
print("Make new account!")
|
|
||||||
elif(r.status_code == 403):
|
|
||||||
return None
|
|
||||||
print("Invalid username/password")
|
|
||||||
else:
|
|
||||||
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 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(" ")
|
|
||||||
for c in command:
|
|
||||||
ar.append(c)
|
|
||||||
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
p=process.poll()
|
|
||||||
output = process.communicate()[1]
|
|
||||||
#print(output.decode('utf-8'))
|
|
||||||
|
|
||||||
#public methods: deleteClass, makeClass, update
|
|
||||||
class Teacher:
|
|
||||||
def __init__(self, data):
|
|
||||||
# teacher info already stored in API
|
|
||||||
# intitialze fields after GET request
|
|
||||||
self.first_name=data['first_name']
|
|
||||||
self.last_name=data['last_name']
|
|
||||||
self.git=data['git']
|
|
||||||
self.username=data['ion_user']
|
|
||||||
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
|
||||||
#classes in id form (Example: 4,5)
|
|
||||||
|
|
||||||
cid=data['classes'].split(",")
|
|
||||||
try:
|
|
||||||
cid.remove('')
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
cid.remove("")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
classes=[]
|
|
||||||
for c in cid:
|
|
||||||
url = "http://127.0.0.1:8000/classes/" + str(c) + "/"
|
|
||||||
classes.append(getDB(url))
|
|
||||||
|
|
||||||
self.classes = classes
|
|
||||||
self.sclass=str(data['classes'])
|
|
||||||
if(os.path.isdir(self.username)):
|
|
||||||
print("Synced to " + self.username)
|
|
||||||
else:
|
|
||||||
os.mkdir(self.username)
|
|
||||||
|
|
||||||
#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>
|
|
||||||
|
|
||||||
#turn existing directory into class, Pre-condition: directory exists
|
|
||||||
#relative path to class: 2022rkhondak/Math4
|
|
||||||
def checkClass(self,path):
|
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
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)
|
|
||||||
return False
|
|
||||||
dirs = os.listdir(path)
|
|
||||||
#checks if there is a file (not within Assignments) in class, need at least 1
|
|
||||||
deffile = False
|
|
||||||
#checks if there is a file in an Assignment, need at least 1 (default True in case no assignments)
|
|
||||||
as_file = True
|
|
||||||
as_bad = ""
|
|
||||||
|
|
||||||
for d in dirs:
|
|
||||||
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)):
|
|
||||||
as_file=True
|
|
||||||
if(as_file==False):
|
|
||||||
as_bad = d
|
|
||||||
break
|
|
||||||
if(as_file==False):
|
|
||||||
print("Assignment '" + as_bad + "' does not have a default file!")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if(deffile==False):
|
|
||||||
print("Need a default file in the " + path + " Directory!")
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def checkInDB(self, path):
|
|
||||||
n = path.split("/")
|
|
||||||
n = n[len(n)-1]
|
|
||||||
for c in self.classes:
|
|
||||||
if(n == c['name']):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#adds class to git, not API
|
|
||||||
#Assuming valid class name
|
|
||||||
def addClasstoGit(self, path):
|
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
#push to remote repo
|
|
||||||
url='https://github.com/' + self.git + "/" + cname
|
|
||||||
if(requests.get(url).status_code != 200):
|
|
||||||
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
|
||||||
try:
|
|
||||||
pyperclip.copy(cname)
|
|
||||||
print(cname + " copied to clipboard.")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
time.sleep(2)
|
|
||||||
webbrowser.open('https://github.com/new')
|
|
||||||
input("Repo created? (Press any key to continue)\n")
|
|
||||||
|
|
||||||
print(url)
|
|
||||||
while(requests.get(url).status_code != 200):
|
|
||||||
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
|
||||||
if(r=="N" or r=="No"):
|
|
||||||
return None
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
command('git init')
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m Hello_Class')
|
|
||||||
command('git remote add origin ' + url + '.git')
|
|
||||||
command('git push -u origin master')
|
|
||||||
else:
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
print("Repo already exists. Cloning instead.")
|
|
||||||
command('git clone')
|
|
||||||
command('git fetch origin')
|
|
||||||
command('git pull')
|
|
||||||
command('git add .')
|
|
||||||
command('git commit -m Hello_Class')
|
|
||||||
command('git push -u origin master')
|
|
||||||
os.chdir(cdir)
|
|
||||||
print(cdir)
|
|
||||||
data={
|
|
||||||
'name':cname,
|
|
||||||
'repo':url,
|
|
||||||
'path':path,
|
|
||||||
'teacher':self.username
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
|
|
||||||
#make class from existing directory, add to git and api
|
|
||||||
def addClass(self, path):
|
|
||||||
if (self.checkClass(path)):
|
|
||||||
data = self.addClasstoGit(path)
|
|
||||||
#make class instance in db
|
|
||||||
data = postDB(data, 'http://127.0.0.1:8000/classes/')
|
|
||||||
#add to instance
|
|
||||||
#upate self.classes
|
|
||||||
self.classes.append(data)
|
|
||||||
if(len(self.sclass)==0):
|
|
||||||
self.sclass = data['id']
|
|
||||||
else:
|
|
||||||
self.sclass = self.sclass + "," + str(data['id'])
|
|
||||||
|
|
||||||
#update teacher instance in db, classes field
|
|
||||||
data={
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'url':self.url,
|
|
||||||
'classes':self.sclass
|
|
||||||
}
|
|
||||||
putDB(data, self.url)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
|
||||||
#subject: string, assignments: list
|
|
||||||
#class name must be: <subject>_<ion_user>
|
|
||||||
def makeClass(self, cname, assignments):
|
|
||||||
#check if class exists
|
|
||||||
path = self.username + "/" + cname
|
|
||||||
if(os.path.exists(path)):
|
|
||||||
print("Class already exists: " + cname)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if((("_" + self.username) in cname) == False):
|
|
||||||
print("class name must be: "+ cname + "_" + self.username)
|
|
||||||
return
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.mkdir(path)
|
|
||||||
f=open(path + "/README.md", "w")
|
|
||||||
f.close()
|
|
||||||
#push to remote repo
|
|
||||||
os.chdir(path)
|
|
||||||
for a in assignments:
|
|
||||||
os.mkdir(a)
|
|
||||||
f=open(a + "/instructions.txt", "w")
|
|
||||||
f.close()
|
|
||||||
os.chdir(cdir)
|
|
||||||
|
|
||||||
data = self.addClass(path)
|
|
||||||
return data
|
|
||||||
|
|
||||||
def deleteClass(self, path):
|
|
||||||
if(os.path.exists(path) == False):
|
|
||||||
print(path + " does not exist locally.")
|
|
||||||
resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ")
|
|
||||||
if(resp != 'y'):
|
|
||||||
return
|
|
||||||
|
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
cid = None
|
|
||||||
repo = ''
|
|
||||||
for c in self.classes:
|
|
||||||
if cname == c['name']:
|
|
||||||
cid = str(c['id'])
|
|
||||||
repo = c['repo']
|
|
||||||
|
|
||||||
#remove from api
|
|
||||||
for i in range(len(self.classes)):
|
|
||||||
if(self.classes[i]['id'] == int(cid)):
|
|
||||||
print("DELETE: " + self.classes[i]['name'])
|
|
||||||
del self.classes[i]
|
|
||||||
s=""
|
|
||||||
#recreate sclass field, using ids
|
|
||||||
for c in self.classes:
|
|
||||||
s = s + str(c['id']) + ","
|
|
||||||
print(s)
|
|
||||||
s = s[:-1]
|
|
||||||
print(s)
|
|
||||||
data={
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'url':self.url,
|
|
||||||
'classes':s
|
|
||||||
}
|
|
||||||
print(putDB(data, self.url))
|
|
||||||
delDB("http://127.0.0.1:8000/classes/" + cid + "/")
|
|
||||||
break
|
|
||||||
|
|
||||||
#remove locally
|
|
||||||
try:
|
|
||||||
shutil.rmtree(path)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
#remove from git
|
|
||||||
input("Delete repository: " + cname + ". Scroll to the bottom of the page and press 'Delete this repository' (Press any key to continue) ")
|
|
||||||
print(repo)
|
|
||||||
time.sleep(2)
|
|
||||||
webbrowser.open(repo + "/settings")
|
|
||||||
input("Repo deleted? (Press any key to continue) ")
|
|
||||||
|
|
||||||
print(repo)
|
|
||||||
while(requests.get(repo).status_code == 200):
|
|
||||||
r = input("Repo still no deleted yet. (Press any key to continue after repo deleted, or 'N' to exit)\n")
|
|
||||||
if(r=="N" or r=="No" or r=='n'):
|
|
||||||
return None
|
|
||||||
|
|
||||||
#make student repo by student id
|
|
||||||
def addStudent(self,stid):
|
|
||||||
print(stid)
|
|
||||||
|
|
||||||
def comment(self):
|
|
||||||
print("heheheh")
|
|
||||||
|
|
||||||
data = getTeacher("eharris1")
|
|
||||||
t = Teacher(data)
|
|
||||||
t.makeClass('English11_eharris1', ["Essay1"])
|
|
||||||
t.update()
|
|
40
Website/api/migrations/0003_auto_20200609_2206.py
Normal file
40
Website/api/migrations/0003_auto_20200609_2206.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-09 22:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0002_auto_20200609_0358'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='student',
|
||||||
|
name='repo',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='student',
|
||||||
|
name='webmail',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='student',
|
||||||
|
name='email',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=100),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='teacher',
|
||||||
|
name='email',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=100),
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='student',
|
||||||
|
name='classes',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='student',
|
||||||
|
name='classes',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=100),
|
||||||
|
),
|
||||||
|
]
|
18
Website/api/migrations/0004_student_added_to.py
Normal file
18
Website/api/migrations/0004_student_added_to.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-09 22:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0003_auto_20200609_2206'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='student',
|
||||||
|
name='added_to',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=100),
|
||||||
|
),
|
||||||
|
]
|
18
Website/api/migrations/0005_student_completed.py
Normal file
18
Website/api/migrations/0005_student_completed.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-10 01:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0004_student_added_to'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='student',
|
||||||
|
name='completed',
|
||||||
|
field=models.TextField(blank=True, default=''),
|
||||||
|
),
|
||||||
|
]
|
|
@ -39,6 +39,7 @@ class Teacher(models.Model):
|
||||||
classes=models.CharField(max_length=100, default="", blank=True)
|
classes=models.CharField(max_length=100, default="", blank=True)
|
||||||
ion_user=models.CharField(primary_key=True, max_length=100)
|
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||||
git=models.CharField(max_length=100)
|
git=models.CharField(max_length=100)
|
||||||
|
email=models.CharField(max_length=100, default="", blank=True)
|
||||||
|
|
||||||
class Student(models.Model):
|
class Student(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
@ -46,11 +47,12 @@ class Student(models.Model):
|
||||||
last_name = models.CharField(max_length=100)
|
last_name = models.CharField(max_length=100)
|
||||||
student_id = models.IntegerField()
|
student_id = models.IntegerField()
|
||||||
ion_user=models.CharField(primary_key=True, max_length=100)
|
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||||
webmail = models.EmailField(blank=True)
|
email=models.CharField(max_length=100, default="", blank=True)
|
||||||
grade = models.IntegerField()
|
grade = models.IntegerField()
|
||||||
git=models.CharField(max_length=100)
|
git=models.CharField(max_length=100)
|
||||||
classes = models.ManyToManyField(Classes, default="")
|
classes=models.CharField(max_length=100, default="", blank=True)
|
||||||
repo = models.URLField(default="")
|
added_to=models.CharField(max_length=100, default="", blank=True)
|
||||||
|
completed=models.TextField(default="", blank=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
return super(Student, self).save(*args, **kwargs)
|
return super(Student, self).save(*args, **kwargs)
|
||||||
|
|
|
@ -23,15 +23,15 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id']
|
fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id']
|
||||||
|
|
||||||
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)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Student
|
model = Student
|
||||||
fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id', 'git','repo','ion_user','classes']
|
fields = ['url', 'first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed']
|
||||||
|
|
||||||
class TeacherSerializer(serializers.ModelSerializer):
|
class TeacherSerializer(serializers.ModelSerializer):
|
||||||
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Teacher
|
model = Teacher
|
||||||
fields = ['url', 'first_name', 'last_name','git','ion_user','classes']
|
fields = ['url', 'first_name', 'last_name','git','ion_user', 'email','classes']
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user