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), "
+ "read the first line as grade, the rest as comments",
)
def upload_assignment_grades(dir: Path, assignment_name: str) -> None:
tea.pot.canvas.upload_assignment_grades(str(dir), assignment_name)
def upload_assignment_grades(dir_or_zip_file: Path, assignment_name: str) -> None:
tea.pot.canvas.upload_assignment_grades(str(dir_or_zip_file), assignment_name)
if __name__ == "__main__":

View File

@ -30,11 +30,11 @@ class Canvas:
raise Exception(
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()
logger.debug(f"Canvas assignments loaded")
logger.debug("Canvas assignments loaded")
self.groups = self.course.get_groups()
logger.debug(f"Canvas groups loaded")
logger.debug("Canvas groups loaded")
self.grade_filename = grade_filename
logger.debug("Canvas initialized")
@ -42,16 +42,18 @@ class Canvas:
self, dir_or_zip_file: str, create_grade_file: bool = True
) -> None:
if os.path.isdir(dir_or_zip_file):
dir = dir_or_zip_file
assignments_dir = dir_or_zip_file
else:
dir = os.path.splitext(dir_or_zip_file)[0]
if os.path.exists(dir):
logger.error(f"{dir} exists, can not unzip submissions file")
assignments_dir = os.path.splitext(dir_or_zip_file)[0]
if os.path.exists(assignments_dir):
logger.error(
f"{assignments_dir} exists, can not unzip submissions file"
)
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}
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):
os.mkdir(new_path)
if create_grade_file:
@ -60,7 +62,7 @@ class Canvas:
open(grade_file_path, mode="w")
late_students = 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)
if "_" not in filename:
continue
@ -70,7 +72,7 @@ class Canvas:
else:
file_id = int(segments[1])
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":
# TODO: check the delay time of late submission
if create_grade_file:

View File

@ -76,7 +76,7 @@ class Git:
while retry_interval and auto_retry:
try:
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.checkout(checkout_dest)
retry_interval = 0

View File

@ -21,11 +21,11 @@ class PermissionEnum(Enum):
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 = eng.replace(",", "")
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:
@ -121,9 +121,7 @@ class Gitea:
}
try:
try:
repo = self.organization_api.create_org_repo(
self.org_name, body=body
)
self.organization_api.create_org_repo(self.org_name, body=body)
logger.info(
f"Personal repo {self.org_name}/{repo_name} for {student} created"
)