bug fix student

This commit is contained in:
Raffu Khondaker 2020-06-10 15:29:07 -04:00
parent 2b252b8f9d
commit 915becaaa3
6 changed files with 78 additions and 106 deletions

View File

@ -110,19 +110,27 @@ class Student:
self.new = nclasses self.new = nclasses
self.snew=str(data['added_to']) self.snew=str(data['added_to'])
self.repo = data['repo'] self.repo = data['repo']
if(self.repo == ""):
user= self.git if(os.path.isdir(self.username) == False):
pwd= input("Enter Github password: ") if(self.repo == ""):
#curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos user= self.git
url= "curl -i -u " + user + ":" + pwd + " -d '" + '{"name":"' + self.username + '"}' + "' " + "https://api.github.com/user/repos" pwd= input("Enter Github password: ")
os.system(url) #curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos
url= "curl -i -u " + user + ":" + pwd + " -d '" + '{"name":"' + self.username + '"}' + "' " + "https://api.github.com/user/repos"
print(url)
os.system(url)
cdir = os.getcwd()
os.mkdir(self.username)
os.chdir(self.username)
command('git clone https://github.com/' + self.git + '/' + self.username + '.git') command('git clone https://github.com/' + self.git + '/' + self.username + '.git')
os.chdir(self.username)
command('git checkout master')
command('touch README.md') command('touch README.md')
command('git add .') command('git add README.md')
command('git commit -m Hello') command('git commit -m "Hello"')
command('git push -u origin master') command('git push -u origin master')
os.chdir(cdir)
self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git' self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git'
print(url)
data={ data={
'first_name':self.first_name, 'first_name':self.first_name,
'last_name':self.last_name, 'last_name':self.last_name,
@ -142,38 +150,16 @@ class Student:
#update API and Github, all assignments / classes #update API and Github, all assignments / classes
def update(self): def update(self):
#lists all classes for c in self.classes:
ignore=['.DS_Store'] data = getDB("http://127.0.0.1:8000/classes/" + str(c['id']))
classes = os.listdir(self.username) os.chdir(self.username + "/" + data['name'])
for i in ignore: command("git checkout -b " + data['name'])
try: command("git add " + data['name'])
classes.remove(i) command("git commit -m " + data['name'])
except: command("git push -u origin " + data['name'])
pass command("git pull origin " + data['name'])
for c in self.new:
for i in range(len(classes)): self.addClass(str(c['id']))
c = classes[i]
path = self.username + "/" + c
#lists all assignments and default files
#push to git
isclass = False
for d in os.listdir(path):
if(d == '.git'):
isclass=True
break
if(isclass):
loc = os.getcwd()
os.chdir(path)
command('git fetch origin')
command('git checkout ' + self.username)
command('git add .')
command('git commit -m ' + self.username + '-update')
command('git push -u origin ' + self.username)
command('git merge master')
os.chdir(loc)
print("Updated: " + c)
else:
print(d + " is not a class")
#class name format: <course-name>_<ion_user> #class name format: <course-name>_<ion_user>
@ -187,29 +173,49 @@ class Student:
print("Not added by teacher yet.") print("Not added by teacher yet.")
return None return None
data = getDB('http://127.0.0.1:8000/classes/'+ str(cid))
pwd= input("Enter Github password: ") pwd= input("Enter Github password: ")
url= "curl -i -u " + user + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + data['name'] + "/collaborators/" + data['teacher'] + "'" tgit = getDB("http://127.0.0.1:8000/teachers/" + data['teacher'] + "/")['git']
url= "curl -i -u " + self.git + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + self.username + "/collaborators/" + tgit + "'"
print(url)
os.system(url)
data = getDB('http://127.0.0.1:8000/classes/'+cid)
data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "") data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "")
data['unconfirmed'] = data['unconfirmed'].replace(self.username, "") data['unconfirmed'] = data['unconfirmed'].replace(self.username, "")
data['confirmed'] = data['confirmed'] + "," + self.username data['confirmed'] = data['confirmed'] + "," + self.username
if(data['confirmed'][0] == ','): if(data['confirmed'][0] == ','):
data['confirmed'] = data['confirmed'][1:] data['confirmed'] = data['confirmed'][1:]
print(data['confirmed']) print(data['confirmed'])
print(putDB(data, 'http://127.0.0.1:8000/classes/'+cid + "/")) print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/"))
#add teacher as collaborator #add teacher as collaborator
#curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR' #curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR'
user = self.git user = self.git
print(url)
os.system(url)
self.classes.append(data) self.classes.append(data)
if(len(self.sclass)==0): if(len(self.sclass)==0):
self.sclass = data['id'] self.sclass = data['id']
else: else:
self.sclass = self.sclass + "," + str(data['id']) self.sclass = self.sclass + "," + str(data['id'])
cdir = os.getcwd()
path1 = self.username + "/" + self.username
path2 = self.username
if(os.path.isdir(path1)):
os.chdir(path1)
else:
os.chdir(self.username)
command("git clone " + self.repo)
os.chdir(self.username)
command("git checkout -b " + data['name'])
command("touch welcome.txt")
command("git add welcome.txt")
command("git commit -m initial")
command("git push origin " + data['name'])
#git clone --single-branch --branch <branchname> <remote-repo>
os.chdir(cdir)
shutil.move(path1, self.username + "/" + data['name'])
#upddate self.new #upddate self.new
s="" s=""
nar = '' nar = ''
@ -283,6 +289,6 @@ class Student:
} }
#print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/")) #print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/"))
data = getStudent("2022inafi") data = getStudent("2022rkhondak")
s = Student(data) s = Student(data)
s.addClass('57') s.update()

View File

@ -194,56 +194,6 @@ class Teacher:
return True return True
return False return False
#adds class to git, not API
#Assuming valid class name
def addClasstoGit(self, path):
cname = path.split("/")
cname = cname[len(cname)-1]
#push to remote repo
url='https://github.com/' + self.git + "/" + cname
if(requests.get(url).status_code != 200):
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
try:
pyperclip.copy(cname)
print(cname + " copied to clipboard.")
except:
pass
time.sleep(2)
webbrowser.open('https://github.com/new')
input("Repo created? (Press any key to continue)\n")
print(url)
while(requests.get(url).status_code != 200):
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 None
cdir = os.getcwd()
os.chdir(path)
command('git init')
command('git add .')
command('git commit -m Hello_Class')
command('git remote add origin ' + url + '.git')
command('git push -u origin master')
else:
cdir = os.getcwd()
os.chdir(path)
print("Repo already exists. Cloning instead.")
command('git clone')
command('git fetch origin')
command('git pull')
command('git add .')
command('git commit -m Hello_Class')
command('git push -u origin master')
os.chdir(cdir)
print(cdir)
data={
'name':cname,
'repo':url,
'path':path,
'teacher':self.username,
}
return data
#make class from existing directory, add to git and api #make class from existing directory, add to git and api
def addClass(self, path): def addClass(self, path):
if (self.checkClass(path)): if (self.checkClass(path)):
@ -369,6 +319,13 @@ class Teacher:
print(c['name']) print(c['name'])
if classes == c['name']: if classes == c['name']:
cid = str(c['id']) cid = str(c['id'])
data1 = getDB("http://127.0.0.1:8000/classes/" + cid)
if(student in data1['unconfirmed']):
print (student + " already requested.")
return
if(student in data1['confirmed']):
print (student + " alredy enrolled.")
break
if(cid==None): if(cid==None):
print(classes +" does not exist.") print(classes +" does not exist.")
return return
@ -409,7 +366,7 @@ class Teacher:
"teacher": self.username, "teacher": self.username,
"assignments": "", "assignments": "",
"default_file": "", "default_file": "",
"confirmed": "", "confirmed": data1["confirmed"],
"unconfirmed": data1['unconfirmed'] "unconfirmed": data1['unconfirmed']
} }
print(putDB(d, data1['url'])) print(putDB(d, data1['url']))
@ -418,23 +375,33 @@ class Teacher:
def addStudent(self, student, classes): def addStudent(self, student, classes):
cdir = os.getcwd() cdir = os.getcwd()
cpath = self.username + "/" + classes cpath = self.username + "/" + classes
path = "Students/" + classes path = self.username + "/Students/" + classes
if(os.path.isdir(path) == False): if(os.path.isdir(path) == False):
os.mkdir(path) os.makedirs(path)
os.chdir(path) os.chdir(path)
student = getDB("http://127.0.0.1:8000/students/" + student) student = getDB("http://127.0.0.1:8000/students/" + student)
command("git clone " + student['repo']) command("git clone " + student['repo'])
os.chdir(cdir) os.chdir(cdir)
copy_tree(cpath, path + "/" + student['ion_user']) copy_tree(cpath, path + "/" + student['ion_user'])
os.chdir("Students/" + classes + "/" + student['ion_user']) os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user'])
command('git add .') command('git add .')
command('git checkout -b ' + classes)
command('git commit -m Hello') command('git commit -m Hello')
command('git push -u origin ' + classes) command('git push -u origin ' + classes)
def comment(self): def comment(self):
print("heheheh") print("heheheh")
data = getTeacher("eharris1") def addAssignment():
print()
def updateAssignnment():
print()
data = getTeacher("mlauerbach")
t = Teacher(data) t = Teacher(data)
t.addStudent('2022rkhondak','English11_eharris1') t.makeClass("Math5_mlauerbach", ["Week1_HW", "Test1"])
input()
t.reqStudent()
t.addStudent("2022rkhondak", "Math5_mlauerbach")

@ -1 +0,0 @@
Subproject commit e863f414aed9de267ac442752c5585ead0536246

View File