[go: up one dir, main page]

File: webmgr.py

package info (click to toggle)
comitup 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,252 kB
  • sloc: python: 3,093; javascript: 1,261; sh: 95; makefile: 34
file content (58 lines) | stat: -rw-r--r-- 1,451 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright (c) 2017-2019 David Steele <dsteele@gmail.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# License-Filename: LICENSE
#
# Copyright 2016-2017 David Steele <steele@debian.org>
# This file is part of comitup
# Available under the terms of the GNU General Public License version 2
# or later
#

import logging

from .sysd import sd_start_unit, sd_stop_unit

log: logging.Logger = logging.getLogger("comitup")

COMITUP_SERVICE: str = "comitup-web.service"

web_service: str = ""


def start_service(service: str) -> None:
    log.debug("starting %s web service", service)
    sd_start_unit(service, "replace")


def stop_service(service: str) -> None:
    log.debug("stopping %s web service", service)
    sd_stop_unit(service, "replace")


callmatrix = {
    ("HOTSPOT", "start"): (lambda: stop_service, lambda: web_service),
    ("HOTSPOT", "pass"): (lambda: start_service, lambda: COMITUP_SERVICE),
    ("CONNECTING", "start"): (lambda: stop_service, lambda: COMITUP_SERVICE),
    ("CONNECTED", "start"): (lambda: start_service, lambda: web_service),
}


def state_callback(state: str, action: str) -> None:
    try:
        (fn_fact, svc_fact) = callmatrix[(state, action)]
    except KeyError:
        return

    if svc_fact():
        fn_fact()(svc_fact())


def init_webmgr(web_svc: str) -> None:
    global web_service

    stop_service(COMITUP_SERVICE)

    web_service = web_svc

    log.debug("web service is %s" % web_service)