File: timekprd.py

package info (click to toggle)
timekpr-next 0.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,440 kB
  • sloc: python: 7,938; sh: 98; xml: 39; makefile: 6
file content (68 lines) | stat: -rw-r--r-- 1,984 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
59
60
61
62
63
64
65
66
67
68
"""
Created on Aug 28, 2018

@author: mjasnik
"""

# imports
import os
import sys
import dbus
# distro detection
try:
    # try to load distro module
    import distro
    # if successful, mark it so
    _DISTRO_AVAILABLE = True
except (ImportError, ValueError):
    # if successful, mark it so
    _DISTRO_AVAILABLE = False

# set up our python path
if "/usr/lib/python3/dist-packages" not in sys.path:
    sys.path.append("/usr/lib/python3/dist-packages")

# imports
import signal

# timekpr imports
from timekpr.common.constants import constants as cons
from timekpr.common.log import log
from timekpr.server.interface.dbus.daemon import timekprDaemon
from timekpr.common.utils import misc
from timekpr.server.config.userhelper import timekprUserStore


# main start
if __name__ == "__main__":
    # simple self-running check
    if misc.checkAndSetRunning(os.path.splitext(os.path.basename(__file__))[0]):
        # get out
        sys.exit(0)

    log.log(cons.TK_LOG_LEVEL_INFO, "--- initiating timekpr v. %s ---" % (cons.TK_VERSION))
    # get uname
    uname = os.uname()
    log.log(cons.TK_LOG_LEVEL_INFO, "running on: %s, %s, %s, %s" % (uname[0], uname[2], uname[3], uname[4]))
    # distro
    if _DISTRO_AVAILABLE:
        log.log(cons.TK_LOG_LEVEL_INFO, "distribution: %s, %s, %s" % (distro.id(), distro.name(), distro.version()))
    log.log(cons.TK_LOG_LEVEL_INFO, "using python: %s" % (sys.version))
    log.log(cons.TK_LOG_LEVEL_INFO, "dbus python: %s" % (dbus.__version__))
    log.log(cons.TK_LOG_LEVEL_INFO, "---")

    # get daemon class
    _timekprDaemon = timekprDaemon()

    # this is needed for appindicator to react to ctrl+c
    signal.signal(signal.SIGINT, _timekprDaemon.finishTimekpr)
    signal.signal(signal.SIGTERM, _timekprDaemon.finishTimekpr)

    # prepare all users in the system
    timekprUserStore().checkAndInitUsers()

    # init daemon
    _timekprDaemon.initTimekpr()

    # start daemon threads
    _timekprDaemon.startTimekprDaemon()