From cdc86c545736f5d3aa1fe3b200adc50665e02a3b Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Sat, 14 Sep 2024 19:31:02 -0400 Subject: [PATCH] fix: support set settings --- joint_teapot/workers/canvas.py | 12 ++++++++---- joint_teapot/workers/git.py | 14 +++++++++----- joint_teapot/workers/gitea.py | 16 +++++++++++----- joint_teapot/workers/joj.py | 3 ++- joint_teapot/workers/mattermost.py | 12 ++++++++---- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/joint_teapot/workers/canvas.py b/joint_teapot/workers/canvas.py index 1696d1d..9cf7936 100644 --- a/joint_teapot/workers/canvas.py +++ b/joint_teapot/workers/canvas.py @@ -15,12 +15,16 @@ class Canvas: def __init__( self, - domain_name: str = settings.canvas_domain_name, - suffix: str = settings.canvas_suffix, - access_token: str = settings.canvas_access_token, - course_id: int = settings.canvas_course_id, + domain_name: str = "", + suffix: str = "", + access_token: str = "", # nosec + course_id: int = 0, grade_filename: str = "GRADE.txt", ): + domain_name = domain_name or settings.canvas_domain_name + suffix = suffix or settings.canvas_suffix + access_token = access_token or settings.canvas_access_token + course_id = course_id or settings.canvas_course_id self.canvas = PyCanvas(f"https://{domain_name}{suffix}", access_token) self.course = self.canvas.get_course(course_id) logger.info(f"Canvas course loaded. {self.course}") diff --git a/joint_teapot/workers/git.py b/joint_teapot/workers/git.py index ced1b72..bc04004 100644 --- a/joint_teapot/workers/git.py +++ b/joint_teapot/workers/git.py @@ -18,16 +18,20 @@ class Git: def __init__( self, - git_host: str = settings.git_host, - org_name: str = settings.gitea_org_name, - repos_dir: str = settings.repos_dir, + git_host: str = "", + org_name: str = "", + repos_dir: str = "", ): + git_host = git_host or settings.git_host + org_name = org_name or settings.gitea_org_name + repos_dir = repos_dir or settings.repos_dir self.git_host = git_host self.org_name = org_name - if not os.path.isdir(repos_dir): - raise Exception(f"{repos_dir} does not exist! Create it first.") self.repos_dir = repos_dir + if not os.path.isdir(self.repos_dir): + raise Exception(f"{self.repos_dir} does not exist! Create it first.") logger.debug("Git initialized") + logger.info(f"repos dir: {self.repos_dir}") def clone_repo( self, repo_name: str, branch: str = "master", auto_retry: bool = True diff --git a/joint_teapot/workers/gitea.py b/joint_teapot/workers/gitea.py index 91e9de5..114a0ff 100644 --- a/joint_teapot/workers/gitea.py +++ b/joint_teapot/workers/gitea.py @@ -40,11 +40,15 @@ def list_all(method: Callable[..., Iterable[T]], *args: Any, **kwargs: Any) -> L class Gitea: def __init__( self, - access_token: str = settings.gitea_access_token, - org_name: str = settings.gitea_org_name, - domain_name: str = settings.gitea_domain_name, - suffix: str = settings.gitea_suffix, + access_token: str = "", # nosec + org_name: str = "", + domain_name: str = "", + suffix: str = "", ): + access_token = access_token or settings.gitea_access_token + org_name = org_name or settings.gitea_org_name + domain_name = domain_name or settings.gitea_domain_name + suffix = suffix or settings.gitea_suffix self.org_name = org_name configuration = focs_gitea.Configuration() configuration.api_key["access_token"] = access_token @@ -64,7 +68,9 @@ def __init__( @lru_cache() def _get_team_id_by_name(self, name: str) -> int: - res = self.organization_api.team_search(self.org_name, q=str(name), limit=1).to_dict() + res = self.organization_api.team_search( + self.org_name, q=str(name), limit=1 + ).to_dict() if len(res["data"] or []) == 0: raise Exception( f"{name} not found by name in Gitea. Possible reason: you did not join this team." diff --git a/joint_teapot/workers/joj.py b/joint_teapot/workers/joj.py index 6d74e6e..2bfdbdb 100644 --- a/joint_teapot/workers/joj.py +++ b/joint_teapot/workers/joj.py @@ -11,7 +11,8 @@ class JOJ: - def __init__(self, sid: str = settings.joj_sid): + def __init__(self, sid: str = ""): + sid = sid or settings.joj_sid init() self.submitter = JOJSubmitter(sid, logger) diff --git a/joint_teapot/workers/mattermost.py b/joint_teapot/workers/mattermost.py index ab9e0a9..260a640 100644 --- a/joint_teapot/workers/mattermost.py +++ b/joint_teapot/workers/mattermost.py @@ -11,11 +11,15 @@ class Mattermost: def __init__( self, - access_token: str = settings.mattermost_access_token, - team_name: str = settings.mattermost_team, - domain_name: str = settings.mattermost_domain_name, - suffix: str = settings.mattermost_suffix, + access_token: str = "", # nosec + team_name: str = "", + domain_name: str = "", + suffix: str = "", ): + access_token = access_token or settings.mattermost_access_token + team_name = team_name or settings.mattermost_team + domain_name = domain_name or settings.mattermost_domain_name + suffix = suffix or settings.mattermost_suffix self.url = domain_name self.url_suffix = suffix self.endpoint = Driver(