-
Notifications
You must be signed in to change notification settings - Fork 1
/
ltmt
executable file
·85 lines (73 loc) · 3.03 KB
/
ltmt
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
#
#
# Copyright (C) 2010 - Librix Dev Team
#
# This file is part of librix-thinclient.
#
# librix-thinclient is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# librix-thinclient is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with librix-thinclient. If not, see <http://www.gnu.org/licenses/>.
import sys
from os.path import isfile,abspath,isdir
from os import remove, devnull
from argparse import ArgumentParser
if isdir("./build/lib/ltmt"):
sys.path.append("./build/lib")
from ltmt.defs import pidfile,version,logfile
if __name__ == "__main__":
description = "Librix ThinClient Management Tool (LTMT)"
parser = ArgumentParser(description=description)
mgroup = parser.add_argument_group(title="Init method")
mode_group = mgroup.add_mutually_exclusive_group(required=True)
mode_group.add_argument("-c", "--client", dest="mode", action="store_const",
const=0, help="Executes LTMT GUI Interface")
mode_group.add_argument("-d", "--daemon", dest="mode", action="store_const",
const=1, help="Executes LTMT Daemon")
mode_group.add_argument("-k", "--kill-daemon", dest="mode",
action="store_const", const=2, help="Kill LTMT Daemon")
group = parser.add_argument_group(title="Debug Options")
dbg_group = group.add_mutually_exclusive_group()
dbg_group.add_argument("-q", "--quiet", dest="verbose", default=0,
action="store_const", const=0, help="Suppress debug informations")
dbg_group.add_argument("-v", "--verbose", dest="verbose",
action="store_const", const=1, help="Show debug informations")
dbg_group.add_argument("-l", "--log", dest="verbose",
action="store_const", const=2, help="Log to /var/log/thinclient.log")
parser.add_argument("-f", "--configfile", default="/etc/thinclient.conf",
nargs=1, help="Configuration File", metavar="FILE")
parser.add_argument("-V", "--version", action="version",
version="Librix ThinClient Management Tool v{0}".format(version))
options = parser.parse_args()
if options.verbose == 0:
sys.stdout = open(devnull, "w")
sys.stderr = open(devnull, "w")
elif options.verbose == 2:
sys.stdout = open(logfile, "a")
sys.stderr = open(logfile, "a")
configfile = None
if isfile(options.configfile[0]):
configfile = abspath(options.configfile[0])
if options.mode == 0: # if 0, client mode
from ltmt.ui.main import main
main(configfile)
elif options.mode == 1: # elif 1, daemon mode
from ltmt.daemon.tcd import main
main(configfile)
elif options.mode == 2: # elif 2, kill daemon
if isfile(pidfile):
with open(pidfile, 'r') as P:
print("Stopping daemon PID", P.read().strip())
remove(pidfile)
else:
print("Daemon not running!!!")