style: fix codacy

This commit is contained in:
张泊明518370910136 2021-11-04 01:42:08 +08:00
parent a399a07533
commit 40703f2126
No known key found for this signature in database
GPG Key ID: FBEF5DE8B9F4C629
4 changed files with 19 additions and 19 deletions

View File

@ -122,8 +122,8 @@ def prepare_assignment_dir(dir_or_zip_file: Path) -> None:
help="upload assignment grades to canvas from grade file (GRADE.txt by default), " help="upload assignment grades to canvas from grade file (GRADE.txt by default), "
+ "read the first line as grade, the rest as comments", + "read the first line as grade, the rest as comments",
) )
def upload_assignment_grades(dir: Path, assignment_name: str) -> None: def upload_assignment_grades(dir_or_zip_file: Path, assignment_name: str) -> None:
tea.pot.canvas.upload_assignment_grades(str(dir), assignment_name) tea.pot.canvas.upload_assignment_grades(str(dir_or_zip_file), assignment_name)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -30,11 +30,11 @@ class Canvas:
raise Exception( raise Exception(
f"Unable to gather students' {attr}, please contact the Canvas site admin" f"Unable to gather students' {attr}, please contact the Canvas site admin"
) )
logger.debug(f"Canvas students loaded") logger.debug("Canvas students loaded")
self.assignments = self.course.get_assignments() self.assignments = self.course.get_assignments()
logger.debug(f"Canvas assignments loaded") logger.debug("Canvas assignments loaded")
self.groups = self.course.get_groups() self.groups = self.course.get_groups()
logger.debug(f"Canvas groups loaded") logger.debug("Canvas groups loaded")
self.grade_filename = grade_filename self.grade_filename = grade_filename
logger.debug("Canvas initialized") logger.debug("Canvas initialized")
@ -42,16 +42,18 @@ class Canvas:
self, dir_or_zip_file: str, create_grade_file: bool = True self, dir_or_zip_file: str, create_grade_file: bool = True
) -> None: ) -> None:
if os.path.isdir(dir_or_zip_file): if os.path.isdir(dir_or_zip_file):
dir = dir_or_zip_file assignments_dir = dir_or_zip_file
else: else:
dir = os.path.splitext(dir_or_zip_file)[0] assignments_dir = os.path.splitext(dir_or_zip_file)[0]
if os.path.exists(dir): if os.path.exists(assignments_dir):
logger.error(f"{dir} exists, can not unzip submissions file") logger.error(
f"{assignments_dir} exists, can not unzip submissions file"
)
return return
extract_archive(dir_or_zip_file, outdir=dir, verbosity=-1) extract_archive(dir_or_zip_file, outdir=assignments_dir, verbosity=-1)
login_ids = {stu.id: stu.login_id for stu in self.students} login_ids = {stu.id: stu.login_id for stu in self.students}
for v in login_ids.values(): for v in login_ids.values():
new_path = os.path.join(dir, v) new_path = os.path.join(assignments_dir, v)
if not os.path.exists(new_path): if not os.path.exists(new_path):
os.mkdir(new_path) os.mkdir(new_path)
if create_grade_file: if create_grade_file:
@ -60,7 +62,7 @@ class Canvas:
open(grade_file_path, mode="w") open(grade_file_path, mode="w")
late_students = set() late_students = set()
submitted_ids = set() submitted_ids = set()
for path in glob(os.path.join(dir, "*")): for path in glob(os.path.join(assignments_dir, "*")):
filename = os.path.basename(path) filename = os.path.basename(path)
if "_" not in filename: if "_" not in filename:
continue continue
@ -70,7 +72,7 @@ class Canvas:
else: else:
file_id = int(segments[1]) file_id = int(segments[1])
login_id = login_ids[file_id] login_id = login_ids[file_id]
target_dir = os.path.join(dir, login_id) target_dir = os.path.join(assignments_dir, login_id)
if segments[1] == "late": if segments[1] == "late":
# TODO: check the delay time of late submission # TODO: check the delay time of late submission
if create_grade_file: if create_grade_file:

View File

@ -76,7 +76,7 @@ class Git:
while retry_interval and auto_retry: while retry_interval and auto_retry:
try: try:
repo.git.fetch("--tags", "--all", "-f") repo.git.fetch("--tags", "--all", "-f")
repo.git.reset("--hard", f"origin/master") repo.git.reset("--hard", "origin/master")
repo.git.clean("-d", "-f", "-x") repo.git.clean("-d", "-f", "-x")
repo.git.checkout(checkout_dest) repo.git.checkout(checkout_dest)
retry_interval = 0 retry_interval = 0

View File

@ -21,11 +21,11 @@ class PermissionEnum(Enum):
def default_repo_name_convertor(user: User) -> Optional[str]: def default_repo_name_convertor(user: User) -> Optional[str]:
id, name = user.sis_login_id, user.name sis_login_id, name = user.sis_login_id, user.name
eng = re.sub("[\u4e00-\u9fa5]", "", name) eng = re.sub("[\u4e00-\u9fa5]", "", name)
eng = eng.replace(",", "") eng = eng.replace(",", "")
eng = "".join([word[0].capitalize() + word[1:] for word in eng.split()]) eng = "".join([word[0].capitalize() + word[1:] for word in eng.split()])
return f"{eng}{id}" return f"{eng}{sis_login_id}"
def list_all(method: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: def list_all(method: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
@ -121,9 +121,7 @@ class Gitea:
} }
try: try:
try: try:
repo = self.organization_api.create_org_repo( self.organization_api.create_org_repo(self.org_name, body=body)
self.org_name, body=body
)
logger.info( logger.info(
f"Personal repo {self.org_name}/{repo_name} for {student} created" f"Personal repo {self.org_name}/{repo_name} for {student} created"
) )