Skip to content
Snippets Groups Projects
Commit a118a07c authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Initialization script now writes CSV file

parent b45c688d
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ class CompositeUser:
graylist: Set[str]
blacklist: Set[str]
candidate_teammates: Set[str]
assignments: ClassVar[List[str]] = []
instances: ClassVar[Dict[str, "CompositeUser"]] = {}
def __init__(self, student_dictionary: Dict[str, str], graylist: Collection[str], blacklist: Collection[str]):
......@@ -114,6 +115,31 @@ class CompositeUser:
def get_user(cls, username_or_email: str) -> "CompositeUser":
return cls.instances[username_or_email]
@staticmethod
def set_to_string(the_set: Set[str]) -> str:
the_string = ''
for word in the_set:
the_string += ' ' + word
return the_string.strip()
@staticmethod
def string_to_set(the_string: str) -> Set[str]:
return set(the_string.split())
def to_dict(self) -> Dict[str, str]:
student_dictionary = {'SortableName': self.sortable_name.strip(),
'ReadableName': self.readable_name.strip(),
'NUID': self.NUID,
'CanvasUsername': self.canvas_username,
'CanvasEmail': self.canvas_email,
'GitlabUsername': self.gitlab_username,
'GitlabEmail': self.gitlab_email,
'Blacklist': CompositeUser.set_to_string(self.blacklist)}
# TODO: add assignments
return student_dictionary
# TODO: add CompositeUser.from_dict(Dict[str, str]) -> CompositeUser
# TODO: Will want to re-visit these based on tracking graylist by project...
@staticmethod
def read_student_csv(filename: str) -> Set["CompositeUser"]:
......@@ -138,6 +164,7 @@ class CompositeUser:
composite_student.canvas_user = canvas_student
return students
"""
@staticmethod
def write_student_csv(students: Set["CompositeUser"], filename: str) -> None:
with open(filename, mode='w') as csv_file:
......@@ -173,3 +200,16 @@ class CompositeUser:
# student_dictionary.update({f'Blacklist{count}': ''})
# count += 1
writer.writerow(student_dictionary)
"""
@staticmethod
def write_student_csv(students: Set["CompositeUser"], filename: str) -> None:
with open(filename, mode='w') as csv_file:
fieldnames = ['SortableName', 'ReadableName', 'NUID',
'CanvasUsername', 'CanvasEmail',
'GitlabUsername', 'GitlabEmail', 'Blacklist']
fieldnames.extend(CompositeUser.assignments)
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
for student in students:
writer.writerow(student.to_dict())
......@@ -109,7 +109,7 @@ def add_gitlab_email(user_repos: Dict[CompositeUser, Optional[GitlabProject]]) -
try:
commits: List[GitlabCommit] = project.get_commits()
except GitlabListError:
print(f'*** NOTE *** Could not retrieve gitlab email for {student.get_canvas_user().get_name()}. '
print(f'*** NOTE *** Could not access commits for {project}. '
f'This probably indicates Guest permissions.')
commits = []
if len(commits) > 0:
......@@ -119,8 +119,7 @@ def add_gitlab_email(user_repos: Dict[CompositeUser, Optional[GitlabProject]]) -
def create_cloning_script(user_repos: Dict[CompositeUser, Optional[GitlabProject]],
no_username: Set[CanvasUser]) -> None:
filename = f'{semester_stamp()}-homework.sh'
no_username: Set[CanvasUser], filename: str) -> None:
file = open(filename, 'x')
file.write('#!/bin/bash\n\n')
file.write('# Auto-generated clone script.\n')
......@@ -183,5 +182,6 @@ if __name__ == '__main__':
homework_repos = retrieve_homework_repos(composite_users, choice)
add_gitlab_email(homework_repos)
print('\nCreating cloning script for homework repositories.')
create_cloning_script(homework_repos, skipped_users)
# create_csv(homework_repos)
create_cloning_script(homework_repos, skipped_users, f'{semester_stamp()}-homework.sh')
CompositeUser.write_student_csv(set(homework_repos.keys()), f'{semester_stamp()}-students.csv')
print('\tCreated student csv file.')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment