This repository was archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhyberiactl
executable file
·180 lines (150 loc) · 6.13 KB
/
hyberiactl
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Eiffel Forum License, version 2
#
# 1. Permission is hereby granted to use, copy, modify and/or
# distribute this package, provided that:
# * copyright notices are retained unchanged,
# * any distribution of this package, whether modified or not,
# includes this license text.
# 2. Permission is hereby also granted to distribute binary programs
# which depend on this package. If the binary program depends on a
# modified version of this package, you are encouraged to publicly
# release the modified version of this package.
#
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS PACKAGE.
"""
Control script for HYBERIA projection system. Need the hyberia modules.
"""
__author__ = "G-Anime"
__license__ = "Eiffel Version 2"
__version__ = "0.3.2"
__contributors__= "Mathieu Charron, Martin Samson"
# default is /etc/hyberia.conf
CONFIG_FILE = "/etc/hyberia.conf"
# ALL OTHER CONFIGURATION ARE DONE IN THIS FILE.
###
# Do not change anything below this!
###
# Importation!
import logging, logging.config
import ConfigParser
import time, os, sys, json
from optparse import OptionParser
# @TODO Something is fishy.
import hyberia
from hyberia import *
def system_start(standalone, config):
# Create Logger
logger = logging.getLogger("hyberia")
logger.setLevel(config.getint('logs', 'debug_level'))
# Create file handler
if not standalone:
fh = logging.FileHandler(config.get('logs','main_log'))
# Create the console logging if debug level is 10
if standalone:
ch = logging.StreamHandler()
cformatter = logging.Formatter("[%(levelname)s] %(name)s %(message)s")
ch.setFormatter(cformatter)
if not standalone:
# since it's not initialize previously
fh.setLevel(logging.INFO)
logger.addHandler(ch)
# Set formating
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
if not standalone:
fh.setFormatter(formatter)
# Add the handler to logger
if not standalone:
logger.addHandler(fh)
# Do some sanity check before starting the system
# @TODO There is no check for permission
logger.info("======= NEW INSTANCE =======")
if config.getint("logs", "debug_level") == 10:
logger.debug("RUNNING IN DEBUG")
logger.info("Begin sanity check")
# Check: video, location
if not os.path.isdir(config.get('video', 'location')):
logger.critical("Can't open video location at %s" % (config.get('video', 'location'), ))
exit(1)
# Check: core, slave_socket
if not os.path.exists(config.get("core", "slave_socket")):
logger.warn("Can't open the slave socket at %s" % (config.get("core", "slave_socket"), ))
# Create the socket
try:
os.mkfifo(config.get("core", "slave_socket"))
except OSError:
logger.critical("Can't create socket file, dying")
exit(1)
else:
logger.debug("FIFO file exist at %s" % (config.get("core", "slave_socket") ,))
# Check for the temporary folder
if not os.path.isdir(config.get("video","tmp-location")):
logger.warn("Temporary location inexistant at %s" % (config.get("video", "tmp-location"), ))
# Try creating the folders
try:
os.mkdir(config.get("video", "tmp-location"))
os.mkdir(config.get("video", "tmp-location")+"/intro")
os.mkdir(config.get("video", "tmp-location")+"/ass")
except OSError:
logger.critical("Could not create all the folder")
exit(1)
finally:
logger.info("Folders structure created")
else:
logger.debug("Tempoary folder exist at %s" % (config.get("video", "tmp-location"), ))
logger.info("Sanity check complete")
# Create the mkvutils instance
mkv = mkvutils.MkvUtils(config)
# Create the Playlist instance
pl = playlist.PlayList(mkv)
pl.load(config.get("core", "playlist"), config.get("core","cache"))
# Create the player instance
playerObj = player.PlayerInterface(config.get("core", "slave_socket"))
# Call the daemon
daemonObj = daemon.HyberiaDaemon(pl, playerObj, config, mkv)
# Enter the loop
daemonObj.run()
# We're done
logger.info("Application run complete")
if __name__ == "__main__":
# Create the parser
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-c", "--config", dest="configfile",
help="Supply a config file manually", metavar="FILE")
parser.add_option("-s", "--standalone", action="store_true", default=False,
help="Run on the foreground with verbose enable")
parser.add_option("-t", "--test", action="store_true", default=False,
help="Run video playlist test routine")
parser.add_option("-f", "--force", action="store_true", default=False,
help="force and/or reset the video cache")
# Parse the argument
(options, args) = parser.parse_args()
if options.standalone and options.test:
parser.error("Options -s and -t are mutually exclusive")
# Create the configParser instance
config = ConfigParser.SafeConfigParser(hyberia.CONFIG_DEFAULT_VALUE)
if options.configfile:
# Use the config file passed via the command line
CONFIG_FILE = options.configfile
# Check if the config file exists:
if os.path.exists(CONFIG_FILE):
#print "Loading config"
config.read(CONFIG_FILE)
else:
print "Cannot load config",
# Fatal error, no config file
# @FIX: There must be a more elegant way of doing this.
exit(1)
# run the server
if options.test:
check_start()
else:
system_start(options.standalone, config)