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
|
222
CLI/t-git.py
222
CLI/t-git.py
|
@ -1,7 +1,7 @@
|
|||
import subprocess
|
||||
import os
|
||||
import requests
|
||||
|
||||
import webbrowser
|
||||
|
||||
#git clone student directory ==> <student-id>/classes/assignments
|
||||
'''
|
||||
|
@ -44,8 +44,8 @@ import requests
|
|||
'''
|
||||
#get teacher info from api
|
||||
def getData(ion_user):
|
||||
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
||||
r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr'))
|
||||
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
|
||||
|
@ -71,6 +71,17 @@ class Teacher:
|
|||
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
||||
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 )):
|
||||
print("Already synced to: " + str(self.username))
|
||||
return
|
||||
|
@ -78,72 +89,162 @@ class Teacher:
|
|||
classes = self.classes
|
||||
# make classes directory
|
||||
for c in classes:
|
||||
cname= c['name'] + "_" + self.username
|
||||
cname= c['name']
|
||||
cpath = self.username + "/" + cname
|
||||
if(os.path.exists(cpath)):
|
||||
print(cpath + " already exists...")
|
||||
else:
|
||||
|
||||
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
|
||||
os.mkdir(cpath)
|
||||
#make default files for each class
|
||||
for filename in c['default_file']:
|
||||
f=open(cpath+"/"+filename, "w")
|
||||
f=open(cpath+"/"+filename['name'], "w")
|
||||
f.close()
|
||||
|
||||
#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=open(path + "/instructions.txt", "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()
|
||||
print(cpath)
|
||||
self.command('git add .')
|
||||
self.command('git commit -m Hello_Class')
|
||||
self.command('git push -u origin master')
|
||||
|
||||
#update API and Github
|
||||
|
||||
#update API and Github, all assignments / classes
|
||||
def update(self):
|
||||
data = {
|
||||
"url": self.url,
|
||||
"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'))
|
||||
#lists all classes
|
||||
classes = os.listdir(self.username)
|
||||
|
||||
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)
|
||||
process.wait()
|
||||
#checks all class directories first
|
||||
for c in classes:
|
||||
if(checkClass(self, c) == False):
|
||||
return
|
||||
cdict = []
|
||||
for c in classes:
|
||||
#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>
|
||||
|
||||
#turn existing directory into class
|
||||
def addClas(self, path):
|
||||
#turn existing directory into class, Pre-condition: directory exists
|
||||
#relative path to class: 2022rkhondak/Math4
|
||||
def checkClass(self,path):
|
||||
cname = path.split("/")
|
||||
if(os.path.exists(cname)):
|
||||
print("Already synced to: " + str(self.username))
|
||||
cname = cname[len(cname)-1]
|
||||
if(("_" + self.username) in cname) == False:
|
||||
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
|
||||
|
@ -169,7 +270,7 @@ class Teacher:
|
|||
|
||||
cinfo=[
|
||||
{
|
||||
"name":subject,
|
||||
"name":cname,
|
||||
"assignments":[],
|
||||
"repo": "https://github.com:" + self.git + "/" + cname + ".git",
|
||||
"default_file": [
|
||||
|
@ -183,25 +284,26 @@ class Teacher:
|
|||
#update rest API
|
||||
self.classes.append(cinfo)
|
||||
update(self)
|
||||
|
||||
def addAsignment(self, class_name, name):
|
||||
os.chdir(self.username+"/")
|
||||
data = {
|
||||
"url": self.url,
|
||||
"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
|
||||
def addStudent(stid, teacher):
|
||||
os.mkdir(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 addStudent(self,stid):
|
||||
print(stid)
|
||||
|
||||
def updateAssignment(name):
|
||||
print(name)
|
||||
def comment(self):
|
||||
print("heheheh")
|
||||
|
||||
def comment(filename, text):
|
||||
print(text)
|
||||
data = getData("eharris1")
|
||||
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
|
||||
import django.db.models.deletion
|
||||
|
@ -14,6 +14,6 @@ class Migration(migrations.Migration):
|
|||
migrations.AddField(
|
||||
model_name='classes',
|
||||
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):
|
||||
assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
||||
default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
||||
class Meta:
|
||||
model = Classes
|
||||
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