-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenetv.py
executable file
·84 lines (71 loc) · 2.95 KB
/
openetv.py
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
#!/usr/bin/env python
#
# OpenETV - Copyright (C) 2014 Joey Loman ([email protected]).
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# See files COPYING.GPL2 and COPYING.GPL3 for License information.
#
import os
import sys
import logging
from openetv_libs import app, config, vlc
#from openetv_libs.log import log
if __name__ == "__main__":
# get the configuration
openetv_config = config.get_config('config.ini')
# check if the logo image file can be found
if not os.path.isfile(openetv_config['openetv']['openetv_dir'] + "/openetv_images/logo-app.png"):
print "error: logo image file not found at \"" + openetv_config['openetv']['openetv_dir'] + "/openetv_images/logo-app.png" + "\""
print " maybe the openetv_dir variable isn't configured correctly?"
sys.exit(2)
# check if we can write the OpenETV logfile
try:
f = open(openetv_config['openetv']['openetv_logfile'],'a')
except IOError:
print "error: cannot write to logfile \"" + openetv_config['openetv']['openetv_logfile'] + "\""
sys.exit(2)
f.close
if openetv_config['openetv']['debug'] == "true":
logging.basicConfig(filename=openetv_config['openetv']['openetv_logfile'], level=logging.DEBUG)
else:
logging.basicConfig(filename=openetv_config['openetv']['openetv_logfile'], level=logging.INFO)
# check if we can write the OpenETV pidfile
try:
f = open(openetv_config['openetv']['openetv_pidfile'],'a')
except IOError:
print "error: cannot write to pidfile \"" + openetv_config['openetv']['openetv_pidfile'] + "\""
sys.exit(2)
f.close
# check if we can write the VLC pidfile
try:
f = open(openetv_config['vlc']['vlc_pidfile'],'a')
except IOError:
print "error: cannot write to pidfile \"" + openetv_config['vlc']['vlc_pidfile'] + "\""
sys.exit(2)
f.close
vlc.remove_vlc_pid(openetv_config['vlc']['vlc_pidfile'])
# check if the vlc executable exists
if not os.path.isfile(openetv_config['vlc']['vlc_exe']):
print "error: vlc executable not found at \"" + openetv_config['vlc']['vlc_exe'] + "\""
sys.exit(2)
openetv = app.App(openetv_config, logging)
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
logging.info("[Main] OpenETV started.")
openetv.start()
elif 'stop' == sys.argv[1]:
logging.info("[Main] OpenETV stopped.")
openetv.stop()
elif 'restart' == sys.argv[1]:
logging.info("[Main] OpenETV restarted.")
openetv.restart()
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)