mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-20 12:20:18 -04:00
git updates
This commit is contained in:
parent
a12185aa2e
commit
c39a012fed
148
CLI/run.py
148
CLI/run.py
|
@ -1,148 +0,0 @@
|
||||||
from __future__ import print_function, unicode_literals
|
|
||||||
from PyInquirer import prompt, print_json
|
|
||||||
import argparse
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
def yesorno(question):
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'response',
|
|
||||||
'message': question,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
answers = prompt(questions)
|
|
||||||
if(answers["response"] == "y"):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#already ccrerrated account through website, has to login
|
|
||||||
def login():
|
|
||||||
#enter username
|
|
||||||
#enter password
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'webmail',
|
|
||||||
'message': 'What\'s TJ Webmail',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'password',
|
|
||||||
'name': 'password',
|
|
||||||
'message': 'Password?',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
user = prompt(questions)
|
|
||||||
#reading from json of users (replace w GET to database) to check if user is registered
|
|
||||||
with open('users.json', 'r') as json_file:
|
|
||||||
data = json.load(json_file)
|
|
||||||
for i in range(len(data)):
|
|
||||||
if user["webmail"] == data[i]["webmail"]:
|
|
||||||
if(user["password"] == data[i]["password"]):
|
|
||||||
print("Logged in!")
|
|
||||||
return data[i]
|
|
||||||
else:
|
|
||||||
print("Password incorrect. Try again.")
|
|
||||||
return None
|
|
||||||
print("User not found. Please Try again")
|
|
||||||
return None
|
|
||||||
|
|
||||||
#did not create account through website, has to signup/login
|
|
||||||
def update():
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'first-name',
|
|
||||||
'message': 'What\'s your first name',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'last-name',
|
|
||||||
'message': 'What\'s your last name?',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'list',
|
|
||||||
'name': 'grade',
|
|
||||||
'message': 'Grade?',
|
|
||||||
'choices':["9","10","11","12"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'webmail',
|
|
||||||
'message': 'What\'s your TJ Webmail?',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'password',
|
|
||||||
'name': 'password',
|
|
||||||
'message': 'Password?',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
user = prompt(questions)
|
|
||||||
for i in user:
|
|
||||||
if user[i] == "":
|
|
||||||
print("Some forms were left blank. Try again.\n")
|
|
||||||
return None
|
|
||||||
if len(user["password"]) < 6:
|
|
||||||
print("Password is too short. Try again.")
|
|
||||||
return None
|
|
||||||
if (("@tjhsst.edu" in user['webmail']) == False):
|
|
||||||
print("Webmail entered was not a @tjhhsst.edu. Try again.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
#post user to json, replace w POST to db
|
|
||||||
user["classes"] = []
|
|
||||||
with open('users.json', 'r') as json_file:
|
|
||||||
data = json.load(json_file)
|
|
||||||
data.append(user)
|
|
||||||
open("users.json", "w").write(str(json.dumps(data)))
|
|
||||||
return user
|
|
||||||
|
|
||||||
def relogin():
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'list',
|
|
||||||
'name': 'choice',
|
|
||||||
'message': '',
|
|
||||||
'choices':["Continue as current user","Login into new user","Sign up into new account"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
answer = prompt(questions)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(user):
|
|
||||||
#Read classes/assignenments and setup directory:
|
|
||||||
#SkoolOS/Math/Week1
|
|
||||||
for c in user["classes"]:
|
|
||||||
os.makedirs("../" + c)
|
|
||||||
for a in user["classes"][c]:
|
|
||||||
os.makedirs("../" + c + "/" + a)
|
|
||||||
|
|
||||||
def start():
|
|
||||||
if(os.path.exists(".login.txt") == False):
|
|
||||||
b = yesorno("Do you have a SkoolOS account?(y/N)")
|
|
||||||
if(b):
|
|
||||||
user = login()
|
|
||||||
if(user != None):
|
|
||||||
setup(user)
|
|
||||||
open(".login.txt", "w").write(str(user))
|
|
||||||
else:
|
|
||||||
user = update()
|
|
||||||
if(user != None):
|
|
||||||
open(".login.txt").write(str(user))
|
|
||||||
|
|
||||||
my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS control your system', epilog="Try again")
|
|
||||||
my_parser.add_argument('--init', action="store_true") #returns true if run argument
|
|
||||||
args = my_parser.parse_args()
|
|
||||||
|
|
||||||
update()
|
|
||||||
outputs = vars(args)
|
|
||||||
if(outputs['init']):
|
|
||||||
start()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
30
CLI/s-git.py
30
CLI/s-git.py
|
@ -1,7 +1,8 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import pprint
|
||||||
|
import json
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
def initStudent(ion_user):
|
def initStudent(ion_user):
|
||||||
|
@ -57,6 +58,8 @@ def initStudent(ion_user):
|
||||||
else:
|
else:
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Teachers
|
#Teachers
|
||||||
|
|
||||||
#make student repo by student id
|
#make student repo by student id
|
||||||
|
@ -82,14 +85,17 @@ def updateAssignment(name):
|
||||||
def comment(filename, text):
|
def comment(filename, text):
|
||||||
print(text)
|
print(text)
|
||||||
|
|
||||||
initStudent("2022rkhondak")
|
#initStudent("2022rkhondak")
|
||||||
|
ion_user = "2022rkhondak"
|
||||||
os.chdir("2022rkhondak")
|
headers = {'Content-type': 'application/json'}
|
||||||
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
data = {'first_name': 'Jeff',
|
||||||
process.wait()
|
'git': 'https://github.com/',
|
||||||
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
'grade': 10,
|
||||||
process.wait()
|
'ion_user': '2022jlol1',
|
||||||
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
'last_name': 'lol.',
|
||||||
process.wait()
|
'student_id': 11111
|
||||||
process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
}
|
||||||
process.wait()
|
data = json.dumps(data)
|
||||||
|
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
|
||||||
|
r = requests.put(url = URL, data= data, headers=headers ,auth=('raffukhondaker','hackgroup1'))
|
||||||
|
pprint.pprint(r.json())
|
42
CLI/t-git.py
42
CLI/t-git.py
|
@ -4,41 +4,60 @@ import requests
|
||||||
|
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
def initTeacher(student_id):
|
def initTeacher(ion_user):
|
||||||
#check if git has already been initialized
|
#check if git has already been initialized
|
||||||
if(os.path.exists(str(student_id) +"/" + ".git")):
|
if(os.path.exists(str(ion_user) +"/" + ".git")):
|
||||||
print("Already synced to: " + str(student_id))
|
print("Already synced to: " + str(ion_user))
|
||||||
return
|
return
|
||||||
|
|
||||||
#get student repo from API
|
#get student repo from API
|
||||||
URL = "http://127.0.0.1:8000/students/" + str(student_id) + "/"
|
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=('student','_$YFE#34.9_37jr'))
|
||||||
|
if(r.status_code == 200):
|
||||||
data = r.json()
|
data = r.json()
|
||||||
repo = data['repo']
|
repo = data['repo']
|
||||||
classes = data['classes']
|
classes = data['classes']
|
||||||
print(classes)
|
print(data)
|
||||||
#git clone repo
|
#git clone repo
|
||||||
process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
process.communicate()
|
process.wait()
|
||||||
|
|
||||||
# make classes directory
|
# make classes directory
|
||||||
for c in classes:
|
for c in classes:
|
||||||
cpath = str(student_id) + "/" + c['name']
|
cpath = str(ion_user) + "/" + c['name']
|
||||||
if(os.path.exists(cpath)):
|
if(os.path.exists(cpath)):
|
||||||
print(cpath + " already exists...")
|
print(cpath + " already exists...")
|
||||||
else:
|
else:
|
||||||
os.mkdir(str(student_id) + "/" + c['name'])
|
os.mkdir(str(ion_user) + "/" + c['name'])
|
||||||
|
|
||||||
#make assignments directory
|
#make assignments directory
|
||||||
for a in c['assignments']:
|
for a in c['assignments']:
|
||||||
path = str(student_id) + "/" + c['name'] + "/" + a['name']
|
path = str(ion_user) + "/" + c['name'] + "/" + a['name']
|
||||||
print(path)
|
print(path)
|
||||||
if(os.path.exists("/" +path)):
|
if(os.path.exists("/" +path)):
|
||||||
print(path + " already exists...")
|
print(path + " already exists...")
|
||||||
else:
|
else:
|
||||||
os.mkdir(str(student_id) + "/" + c['name'] + "/" + a['name'])
|
os.mkdir(str(ion_user) + "/" + c['name'] + "/" + a['name'])
|
||||||
|
|
||||||
#Teachers
|
#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):
|
||||||
|
print("Make new account!")
|
||||||
|
elif(r.status_code == 403):
|
||||||
|
print("Invalid username/password")
|
||||||
|
else:
|
||||||
|
print(r.status_code)
|
||||||
|
|
||||||
|
def addClass(Name)
|
||||||
|
|
||||||
#make student repo by student id
|
#make student repo by student id
|
||||||
def addStudent(stid, teacher):
|
def addStudent(stid, teacher):
|
||||||
|
@ -64,4 +83,3 @@ def comment(filename, text):
|
||||||
print(text)
|
print(text)
|
||||||
|
|
||||||
|
|
||||||
initStudent(1579460)
|
|
|
@ -1,4 +1,3 @@
|
||||||
from api.models import Assignment, Student, Classes, Teacher, DefFiles
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
f1 = DefFiles(
|
f1 = DefFiles(
|
||||||
|
|
23
Website/api/migrations/0003_auto_20200607_1519.py
Normal file
23
Website/api/migrations/0003_auto_20200607_1519.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-06-07 15:19
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0002_auto_20200607_0751'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='classes',
|
||||||
|
name='repo',
|
||||||
|
field=models.URLField(default=''),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='assignment',
|
||||||
|
name='files',
|
||||||
|
field=models.ManyToManyField(default='', to='api.DefFiles'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,6 +13,7 @@ class Assignment(models.Model):
|
||||||
class Classes(models.Model):
|
class Classes(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
assignments = models.ManyToManyField(Assignment, default="")
|
assignments = models.ManyToManyField(Assignment, default="")
|
||||||
|
repo=models.URLField(default="")
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
return super(Classes, self).save(*args, **kwargs)
|
return super(Classes, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Classes
|
model = Classes
|
||||||
fields = ['url', 'name','assignments']
|
fields = ['url', 'name','assignments', 'repo']
|
||||||
|
|
||||||
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)
|
||||||
|
|
131
Website/api/views-back.py
Normal file
131
Website/api/views-back.py
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
# class StudentList(APIView):
|
||||||
|
# """
|
||||||
|
# List all snippets, or create a new snippet.
|
||||||
|
# """
|
||||||
|
# def get(self, request, format=None):
|
||||||
|
# snippets = Student.objects.all()
|
||||||
|
# serializer = StudentSerializer(snippets, many=True)
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
|
||||||
|
# def post(self, request, format=None):
|
||||||
|
# serializer = StudentSerializer(data=request.data)
|
||||||
|
# if serializer.is_valid():
|
||||||
|
# serializer.save()
|
||||||
|
# return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# class StudentDetail(APIView):
|
||||||
|
# """
|
||||||
|
# Retrieve, update or delete a snippet instance.
|
||||||
|
# """
|
||||||
|
# def get_object(self, pk):
|
||||||
|
# try:
|
||||||
|
# return Student.objects.get(pk=pk)
|
||||||
|
# except Student.DoesNotExist:
|
||||||
|
# raise Http404
|
||||||
|
|
||||||
|
# def get(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# serializer = StudentSerializer(snippet)
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
|
||||||
|
# def put(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# serializer = StudentSerializer(snippet, data=request.data)
|
||||||
|
# if serializer.is_valid():
|
||||||
|
# serializer.save()
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# def delete(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# snippet.delete()
|
||||||
|
# return response.Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
# class TeacherList(APIView):
|
||||||
|
# """
|
||||||
|
# List all snippets, or create a new snippet.
|
||||||
|
# """
|
||||||
|
# def get(self, request, format=None):
|
||||||
|
# snippets = Teacher.objects.all()
|
||||||
|
# serializer = TeacherSerializer(snippets, many=True)
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
|
||||||
|
# def post(self, request, format=None):
|
||||||
|
# serializer = TeacherSerializer(data=request.data)
|
||||||
|
# if serializer.is_valid():
|
||||||
|
# serializer.save()
|
||||||
|
# return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# class TeacherDetail(APIView):
|
||||||
|
# """
|
||||||
|
# Retrieve, update or delete a snippet instance.
|
||||||
|
# """
|
||||||
|
# def get_object(self, pk):
|
||||||
|
# try:
|
||||||
|
# return Teacher.objects.get(pk=pk)
|
||||||
|
# except Teacher.DoesNotExist:
|
||||||
|
# raise Http404
|
||||||
|
|
||||||
|
# def get(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# serializer = TeacherSerializer(snippet)
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
|
||||||
|
# def put(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# serializer = TeacherSerializer(snippet, data=request.data)
|
||||||
|
# if serializer.is_valid():
|
||||||
|
# serializer.save()
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# def delete(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# snippet.delete()
|
||||||
|
# return response.Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
# class ClassesList(APIView):
|
||||||
|
# """
|
||||||
|
# List all snippets, or create a new snippet.
|
||||||
|
# """
|
||||||
|
# def get(self, request, format=None):
|
||||||
|
# snippets = Classes.objects.all()
|
||||||
|
# serializer = ClassesSerializer(snippets, many=True)
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
|
||||||
|
# def post(self, request, format=None):
|
||||||
|
# serializer = ClassesSerializer(data=request.data)
|
||||||
|
# if serializer.is_valid():
|
||||||
|
# serializer.save()
|
||||||
|
# return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# class ClassesDetail(APIView):
|
||||||
|
# """
|
||||||
|
# Retrieve, update or delete a snippet instance.
|
||||||
|
# """
|
||||||
|
# def get_object(self, pk):
|
||||||
|
# try:
|
||||||
|
# return Classes.objects.get(pk=pk)
|
||||||
|
# except Classes.DoesNotExist:
|
||||||
|
# raise Http404
|
||||||
|
|
||||||
|
# def get(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# serializer = ClassesSerializer(snippet)
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
|
||||||
|
# def put(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# serializer = ClassesSerializer(snippet, data=request.data)
|
||||||
|
# if serializer.is_valid():
|
||||||
|
# serializer.save()
|
||||||
|
# return response.Response(serializer.data)
|
||||||
|
# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# def delete(self, request, pk, format=None):
|
||||||
|
# snippet = self.get_object(pk)
|
||||||
|
# snippet.delete()
|
||||||
|
# return response.Response(status=status.HTTP_204_NO_CONTENT)
|
|
@ -1,6 +1,8 @@
|
||||||
from .models import Student, Teacher, Classes, Assignment, DefFiles
|
from .models import Student, Teacher, Classes, Assignment, DefFiles
|
||||||
from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, DefFilesSerializer
|
from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, DefFilesSerializer
|
||||||
from rest_framework import generics, viewsets, permissions
|
from rest_framework import generics, viewsets, permissions, response, status
|
||||||
|
from django.http import Http404
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
class StudentViewSet(viewsets.ModelViewSet):
|
class StudentViewSet(viewsets.ModelViewSet):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user