Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/check_file_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def main() -> int:
allowed = allowlist()
problems = []
for path in tracked_sources():
lines = Path(path).read_text(encoding="utf-8", errors="replace").count("\n")
text = Path(path).read_text(encoding="utf-8", errors="replace")
lines = len(text.splitlines())
ceiling = allowed.pop(path, None)
if ceiling is None and lines > LIMIT:
problems.append(f"{path}: {lines} lines, limit {LIMIT}. Split it by concern.")
Expand Down
17 changes: 16 additions & 1 deletion systemgate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@ def _value(name: str, default: str = "") -> str:
return os.environ.get(name, default).strip()


class ConfigError(ValueError):
pass


def _port(name: str, default: str) -> int:
raw = _value(name, default)
try:
port = int(raw)
except ValueError:
raise ConfigError(f"invalid {name}: {raw!r} (expected integer 1-65535)") from None
if not 1 <= port <= 65535:
raise ConfigError(f"{name} out of range: {port} (expected 1-65535)")
return port


def get_settings() -> Settings:
root = Path(__file__).resolve().parents[1]
data_dir = Path(_value("SYSTEMGATE_DATA_DIR", str(root / "data"))).expanduser().resolve()
backup_root = Path(_value("SYSTEMGATE_BACKUP_ROOT", "/backups")).expanduser().resolve()
return Settings(
host=_value("SYSTEMGATE_HOST", "127.0.0.1"),
port=int(_value("SYSTEMGATE_PORT", "8040")),
port=_port("SYSTEMGATE_PORT", "8040"),
data_dir=data_dir,
admin_key=_value("SYSTEMGATE_ADMIN_KEY"),
backup_root=backup_root,
Expand Down
Loading