def import_students(args): # TODO: This should probably move to another file email_re = re.compile(r'^(?P<user>[^@]+)') with open(args.file) as fh, config(args.config) as conf: reader = csv.reader(fh) if 'roster' not in conf: conf['roster'] = [] # Note: This is incredibly hardcoded. # However, peoplesoft never updates anything, so we're probably good. reader.__next__() # Skip the header count = 0 for row in reader: count += 1 match = email_re.match(row[4]) conf['roster'].append({ 'name': row[3], 'username': match.group("user"), 'section': args.section }) try: conf['roster'][-1]['id'] = Repo.get_user_id(match.group("user"), conf['gitlab-host'], conf['token']) except RepoError: logger.warning("Student %s does not have a Gitlab account.", row[3]) print("Imported ", count, " students.")
def open_assignment(conf, args): """Adds each student in the roster to their respective homework repositories as Developers so they can pull/commit/push their work. """ hw_name = args.name host = conf.gitlab_host namespace = conf.namespace token = conf.token semester = conf.semester roster = get_filtered_roster(conf.roster, args.section, args.student) count = 0 for student in roster: username = student["username"] student_section = student["section"] full_name = StudentRepo.name(semester, student_section, hw_name, username) try: repo = StudentRepo(host, namespace, full_name, token) if "id" not in student: student["id"] = Repo.get_user_id(username, host, token) repo.add_member(student["id"], Access.developer) count += 1 except RepoError: logging.warn("Could not add {} to {}.".format(username, full_name)) except HTTPError: raise print("Granted access to {} repositories.".format(count))
def new(args): with config(args.config) as conf: if args.dry_run: url = Repo.build_url(conf['gitlab-host'], conf['namespace'], args.name) print("Created repo at ", url) else: try: repo = BaseRepo.new(args.name, conf['namespace'], conf['gitlab-host'], conf['token']) print("Created repo at ", repo.url) except HTTPError as e: if e.response.status_code == 400: logger.warning("Repository %s already exists!", args.name) else: raise
def new(conf, args): """Creates a new base repository for an assignment so that you can add the instructions, sample code, etc. """ hw_name = args.name dry_run = args.dry_run host = conf.gitlab_host namespace = conf.namespace token = conf.token if dry_run: url = Repo.build_url(host, namespace, hw_name) print("Created repo at {}.".format(url)) else: try: repo = BaseRepo.new(hw_name, namespace, host, token) print("Created repo at {}.".format(repo.url)) except HTTPError as e: if e.response.status_code == 400: logger.warning("Repository {} already exists!".format(hw_name)) else: raise
def open_assignment(args): with config(args.config) as conf: count = 0 for student in conf['roster']: name = StudentRepo.name(conf['semester'], student['section'], args.name, student['username']) try: repo = StudentRepo(conf['gitlab-host'], conf['namespace'], name, conf['token']) if 'id' not in student: student['id'] = Repo.get_user_id(student['username'], conf['gitlab-host'], conf['token']) repo.add_member(student['id'], Access.developer) count += 1 except RepoError: logging.warn("Could not add %s to %s", student['username'], name) except HTTPError as e: raise if e.response.status_code == 404: logging.warn("Repository %s does not exist.", name) else: raise print("Granted access to ", count, " repositories")
def import_from_canvas(conf, args): """Imports students from a Canvas course to the roster. """ if 'canvas-token' not in conf: logging.error("canvas-token configuration is missing! Please set the Canvas API access " "token before attempting to import users from Canvas") print("Import from canvas failed: missing Canvas API access token.") return if "roster" not in conf: conf["roster"] = [] course_id = args.id section = args.section canvas = CanvasAPI(conf["canvas-token"]) students = canvas.get_course_students(course_id) for s in students: conf.roster.append({ "name": s['sortable_name'], "username": s['sis_user_id'], "section": section }) try: conf.roster[-1]["id"] = Repo.get_user_id( s['sis_user_id'], conf.gitlab_host, conf.token ) except RepoError: logger.warning( "Student {} does not have a Gitlab account.".format(s['name']) ) print("Imported {} students.".format(len(students)))
def import_students(conf, args): """Imports students from a CSV file to the roster. """ section = args.section # TODO: This should probably move to another file email_re = re.compile(r"^(?P<user>[^@]+)") with open(args.file) as fh: reader = csv.reader(fh) if "roster" not in conf: conf["roster"] = [] # Note: This is incredibly hardcoded. # However, peoplesoft never updates anything, so we're probably good. reader.__next__() # Skip the header count = 0 for row in reader: count += 1 match = email_re.match(row[4]) conf.roster.append({ "name": row[3], "username": match.group("user"), "section": section }) try: conf.roster[-1]["id"] = Repo.get_user_id( match.group("user"), conf.gitlab_host, conf.token ) except RepoError: logger.warning( "Student {} does not have a Gitlab account.".format(row[3]) ) print("Imported {} students.".format(count))