fix: support set settings
This commit is contained in:
parent
6303d31b1b
commit
cdc86c5457
|
@ -15,12 +15,16 @@ from joint_teapot.utils.main import first, percentile
|
||||||
class Canvas:
|
class Canvas:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
domain_name: str = settings.canvas_domain_name,
|
domain_name: str = "",
|
||||||
suffix: str = settings.canvas_suffix,
|
suffix: str = "",
|
||||||
access_token: str = settings.canvas_access_token,
|
access_token: str = "", # nosec
|
||||||
course_id: int = settings.canvas_course_id,
|
course_id: int = 0,
|
||||||
grade_filename: str = "GRADE.txt",
|
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.canvas = PyCanvas(f"https://{domain_name}{suffix}", access_token)
|
||||||
self.course = self.canvas.get_course(course_id)
|
self.course = self.canvas.get_course(course_id)
|
||||||
logger.info(f"Canvas course loaded. {self.course}")
|
logger.info(f"Canvas course loaded. {self.course}")
|
||||||
|
|
|
@ -18,16 +18,20 @@ from joint_teapot.config import settings
|
||||||
class Git:
|
class Git:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
git_host: str = settings.git_host,
|
git_host: str = "",
|
||||||
org_name: str = settings.gitea_org_name,
|
org_name: str = "",
|
||||||
repos_dir: str = settings.repos_dir,
|
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.git_host = git_host
|
||||||
self.org_name = org_name
|
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
|
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.debug("Git initialized")
|
||||||
|
logger.info(f"repos dir: {self.repos_dir}")
|
||||||
|
|
||||||
def clone_repo(
|
def clone_repo(
|
||||||
self, repo_name: str, branch: str = "master", auto_retry: bool = True
|
self, repo_name: str, branch: str = "master", auto_retry: bool = True
|
||||||
|
|
|
@ -40,11 +40,15 @@ def list_all(method: Callable[..., Iterable[T]], *args: Any, **kwargs: Any) -> L
|
||||||
class Gitea:
|
class Gitea:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
access_token: str = settings.gitea_access_token,
|
access_token: str = "", # nosec
|
||||||
org_name: str = settings.gitea_org_name,
|
org_name: str = "",
|
||||||
domain_name: str = settings.gitea_domain_name,
|
domain_name: str = "",
|
||||||
suffix: str = settings.gitea_suffix,
|
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
|
self.org_name = org_name
|
||||||
configuration = focs_gitea.Configuration()
|
configuration = focs_gitea.Configuration()
|
||||||
configuration.api_key["access_token"] = access_token
|
configuration.api_key["access_token"] = access_token
|
||||||
|
@ -64,7 +68,9 @@ class Gitea:
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def _get_team_id_by_name(self, name: str) -> int:
|
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:
|
if len(res["data"] or []) == 0:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"{name} not found by name in Gitea. Possible reason: you did not join this team."
|
f"{name} not found by name in Gitea. Possible reason: you did not join this team."
|
||||||
|
|
|
@ -11,7 +11,8 @@ from joint_teapot.utils.logger import logger
|
||||||
|
|
||||||
|
|
||||||
class JOJ:
|
class JOJ:
|
||||||
def __init__(self, sid: str = settings.joj_sid):
|
def __init__(self, sid: str = ""):
|
||||||
|
sid = sid or settings.joj_sid
|
||||||
init()
|
init()
|
||||||
self.submitter = JOJSubmitter(sid, logger)
|
self.submitter = JOJSubmitter(sid, logger)
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,15 @@ from joint_teapot.workers.gitea import Gitea
|
||||||
class Mattermost:
|
class Mattermost:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
access_token: str = settings.mattermost_access_token,
|
access_token: str = "", # nosec
|
||||||
team_name: str = settings.mattermost_team,
|
team_name: str = "",
|
||||||
domain_name: str = settings.mattermost_domain_name,
|
domain_name: str = "",
|
||||||
suffix: str = settings.mattermost_suffix,
|
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 = domain_name
|
||||||
self.url_suffix = suffix
|
self.url_suffix = suffix
|
||||||
self.endpoint = Driver(
|
self.endpoint = Driver(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user