mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-18 19:30:19 -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 os
|
||||
import requests
|
||||
|
||||
import pprint
|
||||
import json
|
||||
|
||||
#git clone student directory ==> <student-id>/classes/assignments
|
||||
def initStudent(ion_user):
|
||||
|
@ -57,6 +58,8 @@ def initStudent(ion_user):
|
|||
else:
|
||||
print(r.status_code)
|
||||
|
||||
|
||||
|
||||
#Teachers
|
||||
|
||||
#make student repo by student id
|
||||
|
@ -82,14 +85,17 @@ def updateAssignment(name):
|
|||
def comment(filename, text):
|
||||
print(text)
|
||||
|
||||
initStudent("2022rkhondak")
|
||||
|
||||
os.chdir("2022rkhondak")
|
||||
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()
|
||||
#initStudent("2022rkhondak")
|
||||
ion_user = "2022rkhondak"
|
||||
headers = {'Content-type': 'application/json'}
|
||||
data = {'first_name': 'Jeff',
|
||||
'git': 'https://github.com/',
|
||||
'grade': 10,
|
||||
'ion_user': '2022jlol1',
|
||||
'last_name': 'lol.',
|
||||
'student_id': 11111
|
||||
}
|
||||
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())
|
44
CLI/t-git.py
44
CLI/t-git.py
|
@ -4,41 +4,60 @@ import requests
|
|||
|
||||
|
||||
#git clone student directory ==> <student-id>/classes/assignments
|
||||
def initTeacher(student_id):
|
||||
def initTeacher(ion_user):
|
||||
#check if git has already been initialized
|
||||
if(os.path.exists(str(student_id) +"/" + ".git")):
|
||||
print("Already synced to: " + str(student_id))
|
||||
if(os.path.exists(str(ion_user) +"/" + ".git")):
|
||||
print("Already synced to: " + str(ion_user))
|
||||
return
|
||||
|
||||
#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'))
|
||||
if(r.status_code == 200):
|
||||
data = r.json()
|
||||
repo = data['repo']
|
||||
classes = data['classes']
|
||||
print(classes)
|
||||
print(data)
|
||||
#git clone repo
|
||||
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:
|
||||
cpath = str(student_id) + "/" + c['name']
|
||||
cpath = str(ion_user) + "/" + c['name']
|
||||
if(os.path.exists(cpath)):
|
||||
print(cpath + " already exists...")
|
||||
else:
|
||||
os.mkdir(str(student_id) + "/" + c['name'])
|
||||
os.mkdir(str(ion_user) + "/" + c['name'])
|
||||
|
||||
#make assignments directory
|
||||
for a in c['assignments']:
|
||||
path = str(student_id) + "/" + c['name'] + "/" + a['name']
|
||||
path = str(ion_user) + "/" + c['name'] + "/" + a['name']
|
||||
print(path)
|
||||
if(os.path.exists("/" +path)):
|
||||
print(path + " already exists...")
|
||||
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
|
||||
def addStudent(stid, teacher):
|
||||
|
@ -64,4 +83,3 @@ def comment(filename, text):
|
|||
print(text)
|
||||
|
||||
|
||||
initStudent(1579460)
|
|
@ -1,4 +1,3 @@
|
|||
from api.models import Assignment, Student, Classes, Teacher, DefFiles
|
||||
from datetime import datetime
|
||||
|
||||
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):
|
||||
name = models.CharField(max_length=100)
|
||||
assignments = models.ManyToManyField(Assignment, default="")
|
||||
repo=models.URLField(default="")
|
||||
def save(self, *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)
|
||||
class Meta:
|
||||
model = Classes
|
||||
fields = ['url', 'name','assignments']
|
||||
fields = ['url', 'name','assignments', 'repo']
|
||||
|
||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
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 .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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user