mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
initialize teacher repo
This commit is contained in:
parent
ddea6db3ff
commit
4c8602ed4f
1
2022rkhondak
Submodule
1
2022rkhondak
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 8dca8b78c03fab721e9976a4675e2996802328a7
|
252
CLI/t-git.py
252
CLI/t-git.py
|
@ -1,7 +1,7 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
'''
|
'''
|
||||||
|
@ -44,8 +44,8 @@ import requests
|
||||||
'''
|
'''
|
||||||
#get teacher info from api
|
#get teacher info from api
|
||||||
def getData(ion_user):
|
def getData(ion_user):
|
||||||
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/teachers/" + 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()
|
||||||
return data
|
return data
|
||||||
|
@ -71,6 +71,17 @@ class Teacher:
|
||||||
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
||||||
self.data=data
|
self.data=data
|
||||||
|
|
||||||
|
def command(self,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()[0]
|
||||||
|
print(output.decode('utf-8'))
|
||||||
|
|
||||||
|
def initTeacher(self):
|
||||||
if(os.path.exists(self.username )):
|
if(os.path.exists(self.username )):
|
||||||
print("Already synced to: " + str(self.username))
|
print("Already synced to: " + str(self.username))
|
||||||
return
|
return
|
||||||
|
@ -78,72 +89,162 @@ class Teacher:
|
||||||
classes = self.classes
|
classes = self.classes
|
||||||
# make classes directory
|
# make classes directory
|
||||||
for c in classes:
|
for c in classes:
|
||||||
cname= c['name'] + "_" + self.username
|
cname= c['name']
|
||||||
cpath = self.username + "/" + cname
|
cpath = self.username + "/" + cname
|
||||||
if(os.path.exists(cpath)):
|
|
||||||
print(cpath + " already exists...")
|
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
||||||
else:
|
webbrowser.open('https://github.com/new')
|
||||||
#make class directory
|
input("Repo created? (Press any key to continue)\n")
|
||||||
os.mkdir(cpath)
|
|
||||||
#make default files for each class
|
url='https://github.com/' + self.git + "/" + cname
|
||||||
for filename in c['default_file']:
|
print(url)
|
||||||
f=open(cpath+"/"+filename, "w")
|
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()
|
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')
|
||||||
|
|
||||||
#make assignments directory
|
|
||||||
for a in c['assignments']:
|
|
||||||
path = cpath + "/" + a['name']
|
|
||||||
print(path)
|
|
||||||
if(os.path.exists(path)):
|
|
||||||
print(path + " already exists...")
|
|
||||||
else:
|
|
||||||
os.mkdir(path)
|
|
||||||
f=open(path + "/README.md", "w")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
#push to remote repo
|
|
||||||
os.chdir(cpath)
|
|
||||||
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', "Hello Class!"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
#git remote add origin git@github.com:alexpchin/<reponame>.git
|
|
||||||
process = subprocess.Popen(['git', 'remote', 'add', "origin", "git@github.com:" + self.git + "/" + cname + ".git"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.wait()
|
|
||||||
|
|
||||||
#update API and Github
|
#update API and Github, all assignments / classes
|
||||||
def update(self):
|
def update(self):
|
||||||
data = {
|
#lists all classes
|
||||||
"url": self.url,
|
classes = os.listdir(self.username)
|
||||||
"first_name": self.first_name,
|
|
||||||
"last_name": self.first_name,
|
|
||||||
"classes": self.classes,
|
|
||||||
"git": self.git,
|
|
||||||
"ion_user": self.username
|
|
||||||
},
|
|
||||||
r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
|
||||||
|
|
||||||
def command(self, command):
|
#checks all class directories first
|
||||||
ar = []
|
for c in classes:
|
||||||
command = command.split(" ")
|
if(checkClass(self, c) == False):
|
||||||
for c in command:
|
return
|
||||||
ar.append(c)
|
cdict = []
|
||||||
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
for c in classes:
|
||||||
process.wait()
|
#lists all assignments and default files
|
||||||
|
ass = os.listdir(c)
|
||||||
|
#if no .git, directory not synced to git or API
|
||||||
|
if '.git' in ass == False:
|
||||||
|
addClass(self, c)
|
||||||
|
else:
|
||||||
|
#push to git
|
||||||
|
loc = os.getcwd()
|
||||||
|
os.chdir(c)
|
||||||
|
command(self, 'git init')
|
||||||
|
command(self, 'git add .')
|
||||||
|
command(self, 'git commit -m "Update"')
|
||||||
|
command(self, 'git push -u origin master')
|
||||||
|
os.chdir(loc)
|
||||||
|
#assignments
|
||||||
|
adict = []
|
||||||
|
#default files for classes
|
||||||
|
fdict=[]
|
||||||
|
#default files for assignments
|
||||||
|
afdict=[]
|
||||||
|
for a in ass:
|
||||||
|
aname=a
|
||||||
|
#need to add option
|
||||||
|
due_date="2020-06-07T07:46:30.537197Z",
|
||||||
|
if(os.path.isfile(a)):
|
||||||
|
fdict.append({
|
||||||
|
'name':a
|
||||||
|
})
|
||||||
|
elif(os.path.isdir(a)):
|
||||||
|
for af in a:
|
||||||
|
if(os.path.isfile(af)):
|
||||||
|
afdict.append({
|
||||||
|
'name':af
|
||||||
|
})
|
||||||
|
adict.append({
|
||||||
|
'name':aname,
|
||||||
|
'due_date':due_date,
|
||||||
|
'files':fdict
|
||||||
|
})
|
||||||
|
|
||||||
|
cdict.append({
|
||||||
|
'name':c,
|
||||||
|
'repo': 'https://github.com:"' + self.git + "/" + c + ".git",
|
||||||
|
'assignments':adict,
|
||||||
|
'default_file':fdict
|
||||||
|
})
|
||||||
|
r = requests.put(url = self.url, data= cdict, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
#turn existing directory into class
|
#turn existing directory into class, Pre-condition: directory exists
|
||||||
def addClas(self, path):
|
#relative path to class: 2022rkhondak/Math4
|
||||||
|
def checkClass(self,path):
|
||||||
cname = path.split("/")
|
cname = path.split("/")
|
||||||
if(os.path.exists(cname)):
|
cname = cname[len(cname)-1]
|
||||||
print("Already synced to: " + str(self.username))
|
if(("_" + self.username) in cname) == False:
|
||||||
return
|
print("Incorrect class name: Must be in the format: <course-name>_<ion_user>")
|
||||||
|
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)):
|
||||||
|
count=count+1
|
||||||
|
if(os.path.isdir(d)):
|
||||||
|
#checks if there is a file in an Assignment, need at least 1
|
||||||
|
as_file = False
|
||||||
|
asdir = os.listdir(d)
|
||||||
|
for a in asdir:
|
||||||
|
if(os.path.isfile(a)):
|
||||||
|
as_file=True
|
||||||
|
if(as_file==False):
|
||||||
|
as_bad = a
|
||||||
|
break
|
||||||
|
if(as_file==False):
|
||||||
|
print("Assignment '" + as_bad + "' does not have a default file!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if(count == 0):
|
||||||
|
print("Need a default file in the " + path + " Directory!")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def addClass(self, path):
|
||||||
|
cname = path.split("/")
|
||||||
|
cname = cname[len(cname)-1]
|
||||||
|
#push to remote repo
|
||||||
|
if(os.path.exists(path)):
|
||||||
|
print("Already synced")
|
||||||
|
return
|
||||||
|
if(checkClass(self, path)):
|
||||||
|
os.chdir(cname)
|
||||||
|
command(self, 'git init')
|
||||||
|
command(self, 'git add .')
|
||||||
|
command(self, 'git commit -m "Hello Class!"')
|
||||||
|
#git remote add origin git@github.com:alexpchin/<reponame>.git
|
||||||
|
command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git")
|
||||||
|
command(self, 'git push -u origin master')
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
#make a new class from scratch
|
||||||
|
@ -169,7 +270,7 @@ class Teacher:
|
||||||
|
|
||||||
cinfo=[
|
cinfo=[
|
||||||
{
|
{
|
||||||
"name":subject,
|
"name":cname,
|
||||||
"assignments":[],
|
"assignments":[],
|
||||||
"repo": "https://github.com:" + self.git + "/" + cname + ".git",
|
"repo": "https://github.com:" + self.git + "/" + cname + ".git",
|
||||||
"default_file": [
|
"default_file": [
|
||||||
|
@ -183,25 +284,26 @@ class Teacher:
|
||||||
#update rest API
|
#update rest API
|
||||||
self.classes.append(cinfo)
|
self.classes.append(cinfo)
|
||||||
update(self)
|
update(self)
|
||||||
|
data = {
|
||||||
def addAsignment(self, class_name, name):
|
"url": self.url,
|
||||||
os.chdir(self.username+"/")
|
"first_name": self.first_name,
|
||||||
|
"last_name": self.first_name,
|
||||||
|
"classes": self.classes,
|
||||||
|
"git": self.git,
|
||||||
|
"ion_user": self.username
|
||||||
|
},
|
||||||
|
r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
||||||
|
|
||||||
#make student repo by student id
|
#make student repo by student id
|
||||||
def addStudent(stid, teacher):
|
def addStudent(self,stid):
|
||||||
os.mkdir(stid)
|
print(stid)
|
||||||
os.chdir(os.getcwd() + "/" + stid)
|
|
||||||
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.communicate()
|
|
||||||
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.communicate()
|
|
||||||
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
def updateAssignment(name):
|
def comment(self):
|
||||||
print(name)
|
print("heheheh")
|
||||||
|
|
||||||
def comment(filename, text):
|
data = getData("eharris1")
|
||||||
print(text)
|
print(data)
|
||||||
|
t = Teacher(data)
|
||||||
|
t.initTeacher()
|
||||||
|
|
||||||
|
|
||||||
|
|
16
CLI/test.py
Normal file
16
CLI/test.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
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()[0]
|
||||||
|
print(output)
|
||||||
|
|
||||||
|
command('echo hello')
|
||||||
|
command('python runtest.py')
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 03:21
|
# Generated by Django 3.0.7 on 2020-06-08 03:18
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -14,6 +14,6 @@ class Migration(migrations.Migration):
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='classes',
|
model_name='classes',
|
||||||
name='default_file',
|
name='default_file',
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.DefFiles'),
|
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.DefFiles'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
18
Website/api/migrations/0009_auto_20200608_0502.py
Normal file
18
Website/api/migrations/0009_auto_20200608_0502.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-08 05:02
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0008_auto_20200608_0341'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='classes',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=100, primary_key=False, serialize=False),
|
||||||
|
),
|
||||||
|
]
|
18
Website/api/migrations/0010_auto_20200608_0510.py
Normal file
18
Website/api/migrations/0010_auto_20200608_0510.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-08 05:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0009_auto_20200608_0502'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='classes',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=100),
|
||||||
|
),
|
||||||
|
]
|
|
@ -17,6 +17,7 @@ class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
assignments = AssignmentSerializer(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','assignments', 'repo',"default_file"]
|
fields = ['url', 'name','assignments', 'repo',"default_file"]
|
||||||
|
|
0
eharris1/Math5_eharris1/Week1_HW/instructions.txt
Normal file
0
eharris1/Math5_eharris1/Week1_HW/instructions.txt
Normal file
0
eharris1/Math5_eharris1/Week2_HW/instructions.txt
Normal file
0
eharris1/Math5_eharris1/Week2_HW/instructions.txt
Normal file
0
eharris1/Math5_eharris1/instructions.txt
Normal file
0
eharris1/Math5_eharris1/instructions.txt
Normal file
2
runtest.py
Normal file
2
runtest.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
for i in range(0, 100000):
|
||||||
|
print(i)
|
Loading…
Reference in New Issue
Block a user