Fixup: Do not create project if unable to transfer
This commit is contained in:
parent
3f937b132e
commit
239e4417f3
2 changed files with 57 additions and 5 deletions
|
@ -7,6 +7,7 @@ import datetime
|
||||||
import logging as log
|
import logging as log
|
||||||
import csv
|
import csv
|
||||||
import secrets
|
import secrets
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class Deadline(yaml.YAMLObject):
|
class Deadline(yaml.YAMLObject):
|
||||||
|
@ -37,9 +38,10 @@ class Course(yaml.YAMLObject):
|
||||||
|
|
||||||
yaml_tag = 'Course'
|
yaml_tag = 'Course'
|
||||||
|
|
||||||
def __init__(self, name, base, deadlines, studentsfile):
|
def __init__(self, name, base, plagiates, deadlines, studentsfile):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.base = base
|
self.base = base
|
||||||
|
self.plagiates = plagiates
|
||||||
self.deadlines = deadlines
|
self.deadlines = deadlines
|
||||||
self.students = studentsfile
|
self.students = studentsfile
|
||||||
|
|
||||||
|
@ -62,10 +64,10 @@ class Course(yaml.YAMLObject):
|
||||||
})
|
})
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def sync_projects(self, gl):
|
def sync_base(self, gl):
|
||||||
found = self.group.projects.list(search=self.base)
|
found = self.group.projects.list(search=self.base)
|
||||||
if len(found) == 0:
|
if len(found) == 0:
|
||||||
project = gl.projects.create({
|
self.base = gl.projects.create({
|
||||||
'name': self.base,
|
'name': self.base,
|
||||||
'namespace_id': self.group.id,
|
'namespace_id': self.group.id,
|
||||||
'visibility': 'internal'
|
'visibility': 'internal'
|
||||||
|
@ -82,7 +84,45 @@ class Course(yaml.YAMLObject):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
project.commits.create(data)
|
self.base.commits.create(data)
|
||||||
|
|
||||||
|
def sync_plagiates(self, gl):
|
||||||
|
found = self.group.projects.list(search=self.plagiates)
|
||||||
|
if len(found) == 0:
|
||||||
|
self.base = gl.projects.create({
|
||||||
|
'name': self.base,
|
||||||
|
'namespace_id': self.group.id,
|
||||||
|
'visibility': 'private'
|
||||||
|
})
|
||||||
|
log.info('%s: Created project plagiates repo' % self.name)
|
||||||
|
|
||||||
|
projects = self.group.projects.list()
|
||||||
|
"""
|
||||||
|
add all projects in group as submodules
|
||||||
|
except plagiates itself
|
||||||
|
"""
|
||||||
|
projects_list = ""
|
||||||
|
|
||||||
|
for project in projects:
|
||||||
|
if project.name != self.plagiates:
|
||||||
|
projects_list += '../%s\n' % project.name
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'branch': 'master',
|
||||||
|
'commit_message': 'Add submodules',
|
||||||
|
'actions': [
|
||||||
|
{
|
||||||
|
'action': 'create',
|
||||||
|
'file_path': '.gitmodules',
|
||||||
|
'content': projects_list
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
self.plagiates.commits.create(data)
|
||||||
|
|
||||||
|
def sync_projects(self, gl):
|
||||||
|
self.sync_base(gl)
|
||||||
|
self.sync_plagiates(gl)
|
||||||
|
|
||||||
|
|
||||||
class Student():
|
class Student():
|
||||||
|
@ -120,6 +160,7 @@ class Student():
|
||||||
'extern_uid': 'uid=%s,%s' % (self.user, ldap['basedn']),
|
'extern_uid': 'uid=%s,%s' % (self.user, ldap['basedn']),
|
||||||
'password': secrets.token_urlsafe(nbytes=32)
|
'password': secrets.token_urlsafe(nbytes=32)
|
||||||
})
|
})
|
||||||
|
# TODO create groups for abgabegruppen
|
||||||
# group is stored in custom attribute
|
# group is stored in custom attribute
|
||||||
# https://docs.gitlab.com/ee/api/custom_attributes.html
|
# https://docs.gitlab.com/ee/api/custom_attributes.html
|
||||||
user.customattributes.set('group', self.group)
|
user.customattributes.set('group', self.group)
|
||||||
|
@ -137,6 +178,12 @@ def sync_project(gl, course, student):
|
||||||
#for project in student.user.projects.list():
|
#for project in student.user.projects.list():
|
||||||
# gl.projects.delete(project.id)
|
# gl.projects.delete(project.id)
|
||||||
|
|
||||||
|
print(student.user.name)
|
||||||
|
projects = course.group.projects.list(search=student.user.name)
|
||||||
|
if len(projects) > 0:
|
||||||
|
print('found')
|
||||||
|
return projects[0]
|
||||||
|
|
||||||
base = course.group.projects.list(search=course.base)[0]
|
base = course.group.projects.list(search=course.base)[0]
|
||||||
base = gl.projects.get(base.id)
|
base = gl.projects.get(base.id)
|
||||||
|
|
||||||
|
@ -179,7 +226,7 @@ def sync(gl, conf, args):
|
||||||
|
|
||||||
for course in conf['courses']:
|
for course in conf['courses']:
|
||||||
course.group = course.sync_group(gl)
|
course.group = course.sync_group(gl)
|
||||||
course.sync_projects(gl)
|
course.sync_base(gl)
|
||||||
|
|
||||||
with open(course.students, encoding='latin1') as csvfile:
|
with open(course.students, encoding='latin1') as csvfile:
|
||||||
for student in Student.from_csv(csvfile):
|
for student in Student.from_csv(csvfile):
|
||||||
|
@ -191,6 +238,8 @@ def sync(gl, conf, args):
|
||||||
except gitlab.exceptions.GitlabCreateError as e:
|
except gitlab.exceptions.GitlabCreateError as e:
|
||||||
log.warn(e)
|
log.warn(e)
|
||||||
|
|
||||||
|
course.sync_plagiates(gl)
|
||||||
|
|
||||||
|
|
||||||
def parseconf(conf):
|
def parseconf(conf):
|
||||||
"""Reads courses from config file"""
|
"""Reads courses from config file"""
|
||||||
|
|
|
@ -5,6 +5,7 @@ courses:
|
||||||
- !!python/object:abgabesystem.Course
|
- !!python/object:abgabesystem.Course
|
||||||
name: Programmieren 1
|
name: Programmieren 1
|
||||||
base: programmieren_1_solutions
|
base: programmieren_1_solutions
|
||||||
|
plagiates: programmieren_1_abgabesystem
|
||||||
students: List_of_groups_Lecture_Programmieren_1.csv
|
students: List_of_groups_Lecture_Programmieren_1.csv
|
||||||
deadlines:
|
deadlines:
|
||||||
# - !!python/object:abgabesystem.Deadline
|
# - !!python/object:abgabesystem.Deadline
|
||||||
|
@ -14,6 +15,8 @@ courses:
|
||||||
- !!python/object:abgabesystem.Course
|
- !!python/object:abgabesystem.Course
|
||||||
name: Programmieren 2
|
name: Programmieren 2
|
||||||
base: programmieren_2_solutions
|
base: programmieren_2_solutions
|
||||||
|
plagiates: programmieren_2_abgabesystem
|
||||||
|
|
||||||
students: List_of_groups_Lecture_Programmieren_2.csv
|
students: List_of_groups_Lecture_Programmieren_2.csv
|
||||||
deadlines:
|
deadlines:
|
||||||
# - !!python/object:abgabesystem.Deadline
|
# - !!python/object:abgabesystem.Deadline
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue