mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-20 20:30:18 -04:00
api bug
This commit is contained in:
parent
d04897f0a9
commit
8060fad3ec
106
CLI/t-git.py
106
CLI/t-git.py
|
@ -2,6 +2,8 @@ import subprocess
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
import pprint
|
||||||
|
import json
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
'''
|
'''
|
||||||
|
@ -131,6 +133,11 @@ class Teacher:
|
||||||
self.command('git commit -m Hello_Class')
|
self.command('git commit -m Hello_Class')
|
||||||
self.command('git push -u origin master')
|
self.command('git push -u origin master')
|
||||||
|
|
||||||
|
def checkGit(self, ass):
|
||||||
|
for a in ass:
|
||||||
|
if a =='.git':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
#update API and Github, all assignments / classes
|
#update API and Github, all assignments / classes
|
||||||
def update(self):
|
def update(self):
|
||||||
|
@ -139,24 +146,32 @@ class Teacher:
|
||||||
|
|
||||||
#checks all class directories first
|
#checks all class directories first
|
||||||
for c in classes:
|
for c in classes:
|
||||||
if(checkClass(self, c) == False):
|
path = self.username + "/" + c
|
||||||
|
if(self.checkClass(path) == False):
|
||||||
|
print(path)
|
||||||
return
|
return
|
||||||
cdict = []
|
cdict = []
|
||||||
for c in classes:
|
for c in classes:
|
||||||
|
path = self.username + "/" + c
|
||||||
#lists all assignments and default files
|
#lists all assignments and default files
|
||||||
ass = os.listdir(c)
|
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 '.git' in ass == False:
|
if (self.checkGit(ass)==False):
|
||||||
addClass(self, c)
|
print(path)
|
||||||
|
self.addClass(path)
|
||||||
else:
|
else:
|
||||||
#push to git
|
#push to git
|
||||||
loc = os.getcwd()
|
loc = os.getcwd()
|
||||||
os.chdir(c)
|
os.chdir(path)
|
||||||
command(self, 'git init')
|
print(path)
|
||||||
command(self, 'git add .')
|
print(ass)
|
||||||
command(self, 'git commit -m "Update"')
|
self.command('git add .')
|
||||||
command(self, 'git push -u origin master')
|
self.command('git commit -m "Update"')
|
||||||
|
self.command('git push -u origin master')
|
||||||
os.chdir(loc)
|
os.chdir(loc)
|
||||||
|
ass.remove('.git')
|
||||||
|
print(ass)
|
||||||
|
|
||||||
#assignments
|
#assignments
|
||||||
adict = []
|
adict = []
|
||||||
#default files for classes
|
#default files for classes
|
||||||
|
@ -165,31 +180,46 @@ class Teacher:
|
||||||
afdict=[]
|
afdict=[]
|
||||||
for a in ass:
|
for a in ass:
|
||||||
aname=a
|
aname=a
|
||||||
|
path = self.username + "/" + c + "/" + a
|
||||||
#need to add option
|
#need to add option
|
||||||
due_date="2020-06-07T07:46:30.537197Z",
|
due_date= '2020-06-07T07:46:30.537197Z',
|
||||||
if(os.path.isfile(a)):
|
#check for default file
|
||||||
|
if(os.path.isfile(path)):
|
||||||
fdict.append({
|
fdict.append({
|
||||||
'name':a
|
'name':a
|
||||||
})
|
})
|
||||||
elif(os.path.isdir(a)):
|
elif(os.path.isdir(path)):
|
||||||
for af in a:
|
for af in os.listdir(path):
|
||||||
if(os.path.isfile(af)):
|
path = path+ "/" + af
|
||||||
|
if(os.path.isfile(path)):
|
||||||
afdict.append({
|
afdict.append({
|
||||||
'name':af
|
'name':af
|
||||||
})
|
})
|
||||||
adict.append({
|
adict.append({
|
||||||
'name':aname,
|
'name':aname,
|
||||||
'due_date':due_date,
|
'due_date': due_date[0],
|
||||||
'files':fdict
|
'files':afdict
|
||||||
})
|
})
|
||||||
|
|
||||||
cdict.append({
|
cdict.append({
|
||||||
'name':c,
|
'name':c,
|
||||||
'repo': 'https://github.com:"' + self.git + "/" + c + ".git",
|
'repo': 'https://github.com:' + self.git + "/" + c + ".git",
|
||||||
'assignments':adict,
|
'assignments':adict,
|
||||||
'default_file':fdict
|
'default_file':fdict
|
||||||
})
|
})
|
||||||
r = requests.put(url = self.url, data= cdict, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
|
||||||
|
mdict= {
|
||||||
|
'first_name':self.first_name,
|
||||||
|
'last_name':self.last_name,
|
||||||
|
'classes':cdict,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username
|
||||||
|
}
|
||||||
|
data = json.dumps(mdict)
|
||||||
|
print(pprint.pprint(mdict))
|
||||||
|
|
||||||
|
r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
||||||
|
print(pprint.pprint(r.json()))
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
|
@ -210,8 +240,8 @@ class Teacher:
|
||||||
|
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
if(os.path.isfile(d)):
|
if(os.path.isfile(d)):
|
||||||
count=count+1
|
deffile=True
|
||||||
if(os.path.isdir(d)):
|
if(os.path.isdir(d)) and d != '.git':
|
||||||
#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(d)
|
||||||
|
@ -225,26 +255,37 @@ class Teacher:
|
||||||
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(count == 0):
|
if(deffile):
|
||||||
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
|
||||||
|
|
||||||
|
#adds class to git, not API
|
||||||
def addClass(self, path):
|
def addClass(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(os.path.exists(path)):
|
if(self.checkClass(path)):
|
||||||
print("Already synced")
|
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
|
return
|
||||||
if(checkClass(self, path)):
|
cdir = os.getcwd()
|
||||||
os.chdir(cname)
|
os.chdir(path)
|
||||||
command(self, 'git init')
|
self.command('git init')
|
||||||
command(self, 'git add .')
|
self.command('git add .')
|
||||||
command(self, 'git commit -m "Hello Class!"')
|
self.command('git commit -m Hello_Class')
|
||||||
#git remote add origin git@github.com:alexpchin/<reponame>.git
|
self.command('git remote add origin ' + url + '.git')
|
||||||
command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git")
|
self.command('git push -u origin master')
|
||||||
command(self, 'git push -u origin master')
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
#make a new class from scratch
|
||||||
|
@ -302,8 +343,7 @@ class Teacher:
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
data = getData("eharris1")
|
data = getData("eharris1")
|
||||||
print(data)
|
|
||||||
t = Teacher(data)
|
t = Teacher(data)
|
||||||
t.initTeacher()
|
t.update()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user