This commit is contained in:
Raffu Khondaker 2020-06-11 00:58:47 -04:00
parent b8c033b71f
commit 14ddb22b2c
4 changed files with 62 additions and 37 deletions

View File

@ -120,8 +120,6 @@ class Student:
print(url) print(url)
os.system(url) os.system(url)
cdir = os.getcwd() 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) os.chdir(self.username)
command('git checkout master') command('git checkout master')
@ -148,32 +146,37 @@ class Student:
print(putDB(data, self.url)) print(putDB(data, self.url))
print("Synced to " + self.username) print("Synced to " + self.username)
#update API and Github, all assignments / classes #update API and Github, all assignments / classes
def update(self): def update(self):
cdir = os.getcwd()
os.chdir(self.username)
for c in self.classes: for c in self.classes:
data = getDB("http://127.0.0.1:8000/classes/" + str(c['id'])) data = getDB("http://127.0.0.1:8000/classes/" + str(c['id']))
os.chdir(self.username + "/" + data['name']) command("git checkout " + data['name'])
command("git checkout -b " + data['name'])
command("git add " + data['name']) command("git add " + data['name'])
command("git commit -m " + data['name']) command("git commit -m " + data['name'])
command("git push -u origin " + data['name'])
command("git pull origin " + data['name']) command("git pull origin " + data['name'])
command("git push -u origin " + data['name'])
os.chdir(cdir)
for c in self.new: for c in self.new:
self.addClass(str(c['id'])) self.addClass(str(c['id']))
command("git checkout master")
#class name format: <course-name>_<ion_user> #class name format: <course-name>_<ion_user>
#add classes from 'new' field #add classes from 'new' field
def addClass(self, cid): def addClass(self, cid):
if((cid in self.snew) == False): if((cid in self.snew) == False):
if((cid in self.sclass) == True): if((cid in self.sclass) == True):
print("Already enrolled in this class.") print("Already enrolled in this class.")
else: return None
if((cid in self.snew) == True):
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)) data = getDB('http://127.0.0.1:8000/classes/'+ str(cid))
print(os.getcwd())
pwd= input("Enter Github password: ") pwd= input("Enter Github password: ")
tgit = getDB("http://127.0.0.1:8000/teachers/" + data['teacher'] + "/")['git'] 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 + "'" url= "curl -i -u " + self.git + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + self.username + "/collaborators/" + tgit + "'"
@ -199,23 +202,22 @@ class Student:
self.sclass = self.sclass + "," + str(data['id']) self.sclass = self.sclass + "," + str(data['id'])
cdir = os.getcwd() cdir = os.getcwd()
path1 = self.username + "/" + self.username print(cdir)
path2 = self.username # path1 = self.username + "/" + self.username
if(os.path.isdir(path1)): # path2 = self.username
os.chdir(path1) # if(os.path.isdir(path1)):
else: # os.chdir(path1)
os.chdir(self.username) # else:
command("git clone " + self.repo) # os.chdir(self.username)
os.chdir(self.username) # command("git clone " + self.repo)
# os.chdir(self.username)
command("git checkout -b " + data['name']) os.chdir(self.username)
command("touch welcome.txt") command("git branch " + data['name'])
command("git add welcome.txt")
command("git commit -m initial") command("git commit -m initial")
command("git push origin " + data['name']) command("git push origin " + data['name'])
#git clone --single-branch --branch <branchname> <remote-repo> #git clone --single-branch --branch <branchname> <remote-repo>
os.chdir(cdir) os.chdir(cdir)
shutil.move(path1, self.username + "/" + data['name'])
#upddate self.new #upddate self.new
s="" s=""
nar = '' nar = ''
@ -289,6 +291,28 @@ 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("2022rkhondak") def viewClass(self, courses):
cdir = os.getcwd()
os.chdir(self.username)
for c in self.classes:
if c['name'] == courses:
print(courses)
command("git checkout " + courses)
print(os.listdir())
return
os.chdir(cdir)
print("Class not found")
return
def submit(self, courses):
command("git add .")
command("git commit -m submit")
command("git tag " + parts[1] + "-final")
command("git push -u origin " + self.username + " --tags")
data = getStudent("2023rumareti")
s = Student(data) s = Student(data)
s.update()
#s.update() #s.update()

View File

@ -372,23 +372,23 @@ class Teacher:
print(putDB(d, data1['url'])) print(putDB(d, data1['url']))
#confirmed students #confirmed students
def addStudent(self, student, classes): # pull student work and push updates
def updateStudent(self, student, classes):
for c in self.classes: for c in self.classes:
if(c['name'] == classes): if(c['name'] == classes):
cid = c['id'] cid = c['id']
data = getDB("http://127.0.0.1:8000/classes/" + str(cid)) data = getDB("http://127.0.0.1:8000/classes/" + str(cid))
if(student in data['confirmed']):
print("Student already added to " + classes)
return
if(student in data['unconfirmed']): if(student in data['unconfirmed']):
print("Student has been enrolled in " + classes) print(student + " has not accepted request to " + classes)
return return
cdir = os.getcwd() cdir = os.getcwd()
cpath = self.username + "/" + classes cpath = self.username + "/" + classes
path = self.username + "/Students/" + classes path = self.username + "/Students/" + classes
spath = self.username + "/Students/" + classes + "/" + student
if(os.path.isdir(path) == False): if(os.path.isdir(path) == False):
os.makedirs(path) os.makedirs(path)
if(os.path.isdir(spath) == False):
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'])
@ -396,8 +396,9 @@ class Teacher:
copy_tree(cpath, path + "/" + student['ion_user']) copy_tree(cpath, path + "/" + student['ion_user'])
os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user']) os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user'])
command('git checkout ' + classes)
command('git pull origin ' + classes)
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)
@ -412,7 +413,7 @@ class Teacher:
data = getTeacher("mlauerbach") data = getTeacher("mlauerbach")
t = Teacher(data) t = Teacher(data)
t.makeClass("Math5_mlauerbach", ["Week1_HW", "Test1"]) t.reqStudent("2023rumareti", 'Math5_mlauerbach')
input() t.updateStudent("2023rumareti", 'Math5_mlauerbach')
t.reqStudent("2022rkhondak", "Math5_mlauerbach")
t.addStudent("2022rkhondak", "Math5_mlauerbach")

View File