integrations.web.config

integrations/web/config.py

 1"""
 2integrations/web/config.py
 3"""
 4
 5import logging
 6import os
 7from dataclasses import dataclass, field
 8from typing import TYPE_CHECKING, Literal
 9
10import libs.global_value as g
11from integrations.base.interface import IntegrationsConfig
12from libs.bootstrap.section import BaseSection
13
14if TYPE_CHECKING:
15    from pathlib import Path  # noqa: F401
16
17
18@dataclass
19class SvcConfig(BaseSection, IntegrationsConfig):
20    """WebUI用個別設定値"""
21
22    host: str = field(default="")
23    """起動アドレス(未指定はコマンドライン引数デフォルト値)"""
24    port: int = field(default=0)
25    """起動ポート(未指定はコマンドライン引数デフォルト値)"""
26
27    # 認証
28    require_auth: bool = field(default=False)
29    """BASIC認証を利用するか"""
30    username: str = field(default="")
31    """認証ユーザ名"""
32    password: str = field(default="")
33    """認証パスワード"""
34
35    # 暗号
36    use_ssl: bool = field(default=False)
37    """HTTPSを有効にするか"""
38    certificate: str = field(default="")
39    """サーバー証明書パス"""
40    private_key: str = field(default="")
41    """秘密鍵パス"""
42
43    # 表示オプション
44    view_summary: bool = field(default=True)
45    """成績サマリ/個人成績の表示"""
46    view_graph: bool = field(default=True)
47    """グラフの表示"""
48    view_ranking: bool = field(default=True)
49    """ランキングの表示"""
50    view_report: bool = field(default=True)
51    """レポートの表示"""
52    management_member: bool = field(default=False)
53    """メンバー/チーム編集メニューの表示"""
54    management_score: bool = field(default=False)
55    """成績管理メニューの表示"""
56    theme: str = field(default="")
57    """テーマ指定"""
58    custom_css: str = field(default="")
59    """ユーザー指定CSSファイル"""
60
61    plotting_backend: Literal["matplotlib", "plotly"] = field(default="plotly")
62
63    def __post_init__(self) -> None:
64        assert self.main_conf
65        self.main_parser = self.main_conf
66        self.section = "web"
67        super().__init__(self)
68        logging.debug("web: %s", self)
69
70        if not self.host:
71            self.host = g.args.host
72
73        if not self.port:
74            self.port = g.args.port
75
76        if not all([self.username, self.password]):
77            self.require_auth = False
78
79        if not all([self.private_key, self.certificate]):
80            self.use_ssl = False
81
82        if not os.path.isfile(os.path.join(g.cfg.config_dir, self.custom_css)):
83            self.custom_css = ""
84
85        if self.theme:
86            theme_file = f"files/html/static/theme_{self.theme}.css"
87            if not all([os.path.exists(theme_file), os.path.isfile(theme_file)]):
88                self.theme = ""
19@dataclass
20class SvcConfig(BaseSection, IntegrationsConfig):
21    """WebUI用個別設定値"""
22
23    host: str = field(default="")
24    """起動アドレス(未指定はコマンドライン引数デフォルト値)"""
25    port: int = field(default=0)
26    """起動ポート(未指定はコマンドライン引数デフォルト値)"""
27
28    # 認証
29    require_auth: bool = field(default=False)
30    """BASIC認証を利用するか"""
31    username: str = field(default="")
32    """認証ユーザ名"""
33    password: str = field(default="")
34    """認証パスワード"""
35
36    # 暗号
37    use_ssl: bool = field(default=False)
38    """HTTPSを有効にするか"""
39    certificate: str = field(default="")
40    """サーバー証明書パス"""
41    private_key: str = field(default="")
42    """秘密鍵パス"""
43
44    # 表示オプション
45    view_summary: bool = field(default=True)
46    """成績サマリ/個人成績の表示"""
47    view_graph: bool = field(default=True)
48    """グラフの表示"""
49    view_ranking: bool = field(default=True)
50    """ランキングの表示"""
51    view_report: bool = field(default=True)
52    """レポートの表示"""
53    management_member: bool = field(default=False)
54    """メンバー/チーム編集メニューの表示"""
55    management_score: bool = field(default=False)
56    """成績管理メニューの表示"""
57    theme: str = field(default="")
58    """テーマ指定"""
59    custom_css: str = field(default="")
60    """ユーザー指定CSSファイル"""
61
62    plotting_backend: Literal["matplotlib", "plotly"] = field(default="plotly")
63
64    def __post_init__(self) -> None:
65        assert self.main_conf
66        self.main_parser = self.main_conf
67        self.section = "web"
68        super().__init__(self)
69        logging.debug("web: %s", self)
70
71        if not self.host:
72            self.host = g.args.host
73
74        if not self.port:
75            self.port = g.args.port
76
77        if not all([self.username, self.password]):
78            self.require_auth = False
79
80        if not all([self.private_key, self.certificate]):
81            self.use_ssl = False
82
83        if not os.path.isfile(os.path.join(g.cfg.config_dir, self.custom_css)):
84            self.custom_css = ""
85
86        if self.theme:
87            theme_file = f"files/html/static/theme_{self.theme}.css"
88            if not all([os.path.exists(theme_file), os.path.isfile(theme_file)]):
89                self.theme = ""

WebUI用個別設定値

SvcConfig( _parser: configparser.ConfigParser | None = None, _command_dispatcher: dict[str, typing.Any] = <factory>, _keyword_dispatcher: dict[str, typing.Any] = <factory>, main_conf: configparser.ConfigParser | None = None, channel_config: pathlib.Path | None = None, slash_command: str = '', badge_degree: bool = False, badge_status: bool = False, badge_grade: bool = False, separate: bool = False, channel_id: str | None = None, plotting_backend: Literal['matplotlib', 'plotly'] = 'plotly', host: str = '', port: int = 0, require_auth: bool = False, username: str = '', password: str = '', use_ssl: bool = False, certificate: str = '', private_key: str = '', view_summary: bool = True, view_graph: bool = True, view_ranking: bool = True, view_report: bool = True, management_member: bool = False, management_score: bool = False, theme: str = '', custom_css: str = '')
host: str = ''

起動アドレス(未指定はコマンドライン引数デフォルト値)

port: int = 0

起動ポート(未指定はコマンドライン引数デフォルト値)

require_auth: bool = False

BASIC認証を利用するか

username: str = ''

認証ユーザ名

password: str = ''

認証パスワード

use_ssl: bool = False

HTTPSを有効にするか

certificate: str = ''

サーバー証明書パス

private_key: str = ''

秘密鍵パス

view_summary: bool = True

成績サマリ/個人成績の表示

view_graph: bool = True

グラフの表示

view_ranking: bool = True

ランキングの表示

view_report: bool = True

レポートの表示

management_member: bool = False

メンバー/チーム編集メニューの表示

management_score: bool = False

成績管理メニューの表示

theme: str = ''

テーマ指定

custom_css: str = ''

ユーザー指定CSSファイル

plotting_backend: Literal['matplotlib', 'plotly'] = 'plotly'

グラフ描写ライブラリ