Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
* Modified the behavior for hyberiactl
Browse files Browse the repository at this point in the history
* Added standalone mode and daemon mode
* Allow to load a custom config file from command line
  • Loading branch information
tx0dev committed Dec 19, 2010
1 parent 4389e54 commit 938c726
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 37 deletions.
3 changes: 3 additions & 0 deletions cfg/mplayer-config
Expand Up @@ -4,6 +4,9 @@
#vo=xv
zoom=1

# Use 2 threads for decoding
lavdopts=threads=2:skiploopfilter=nonkey

# Set audio driver
ao="alsa:device=ladcomp"

Expand Down
30 changes: 15 additions & 15 deletions hyberia/playlist.py
Expand Up @@ -76,21 +76,21 @@ def __createBlock(self, id = 0, runDate = 0, runTime = 0, name = "DefaultBlockNa

def __createPart(self, resource):
part = {}
if resource.startsWith('#'):
if resource.startsWith('#'):
#The video file name
part['file'] = resource['file']
part['name'] = resource['name']
else:
part['file'] = resource
part['name'] = resource

#Duration in seconds
part['duration'] = self.__videoInfoBackend.HVIB_RunningTime(part['file'])

#Will hold when to play the file as a datetime format (yyyymmddhhiiss)
part['playAt'] = 0
return part

def __parsePlayList(self):
#Verify that some data exists
for elem in ["blocks","resources"]:
Expand All @@ -112,7 +112,7 @@ def __parsePlayList(self):
if not os.path.exists(playListStruct['resources'][resource]['file']):
self.logger.critical("Resource %s file (%s) does not exists" % (resource,playListStruct['resources'][resource]['file']))
raise PlayListImportErrorException()

for dateBlock in playListStruct["blocks"]:

prev_block_id = 0
Expand Down Expand Up @@ -152,7 +152,7 @@ def __parsePlayList(self):
self.logger.critical("Part %s does not exists!" % part)
raise PlayListImportErrorException()
resource = part

part = self.__createPart(resource)

part['playAt'] = blockId + block['totalRunTime']
Expand All @@ -167,8 +167,8 @@ def __parsePlayList(self):
self._blocks[blockId] = block

self.logger.debug(" Loaded %s blocks." % len(self._playList))


def __loadCache(self, cacheFile):
import pickle
try:
Expand All @@ -179,15 +179,15 @@ def __loadCache(self, cacheFile):

def load(self, playListFile, cacheFile = None):
'''Load a playlist either from file or from cache
Generating a playlist will take time as mkv information needs to be gathered.
Using a binary cache speeds up starting Projektor again if no files are missing.
'''

if cacheFile != None and os.path.exists(cacheFile):
if self.__loadCache(cacheFile):
return True

'''Load the playlist file into memory'''
self.logger.debug("Loading playlist from %s ." % (playListFile,))

Expand All @@ -203,10 +203,10 @@ def load(self, playListFile, cacheFile = None):
self.logger.warning("This is a parsing error. Strings in json must be delimited with \" instead of ' .")
self.logger.critical(e)
raise PlayListImportErrorException()
self._parsePlaylist(playListStruct)

self.__parsePlayList(playListStruct)
self._playList.sort()

if cacheFile != None:
try:
import pickle
Expand All @@ -220,7 +220,7 @@ def getCurrentBlock(self):
for blockId in self._playList:
''' Loop through the blocks to find the one that should be playing
or will play next
if the blockId is greater than the curTimeId, it means we either
have found the currently playing block or the one that will be played.
'''
Expand All @@ -238,5 +238,5 @@ def getCurrentBlock(self):
''' We could fall here if we have reached the last playing block'''
if prevBlock:
if ( self._blocks[prevBlock]['totalRunTime'] + prevBlock ) > curTimeId:
return self._blocks[prevBlock]
return self._blocks[prevBlock]
return None
79 changes: 57 additions & 22 deletions hyberiactl
Expand Up @@ -42,46 +42,37 @@ CONFIG_FILE = "/etc/hyberia.conf"
import logging, logging.config
import ConfigParser
import time, os, sys, json
from optparse import OptionParser
# @TODO Something is fishy.
import hyberia
from hyberia import *


if __name__ == "__main__":
# Create the configParser instance
config = ConfigParser.SafeConfigParser(hyberia.CONFIG_DEFAULT_VALUE)
#print config
# 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()

def system_start(standalone, config):
# Create Logger
logger = logging.getLogger("hyberia")
logger.setLevel(config.getint('logs', 'debug_level'))

# Create file handler
fh = logging.FileHandler(config.get('logs','main_log'))
if not standalone:
fh = logging.FileHandler(config.get('logs','main_log'))

# Create the console logging if debug level is 10
if config.getint("logs", "debug_level") == 10:
if standalone:
ch = logging.StreamHandler()
cformatter = logging.Formatter("[%(levelname)s] %(name)s %(message)s")
ch.setFormatter(cformatter)
fh.setLevel(logging.INFO)
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")
fh.setFormatter(formatter)

# Add the handler to logger
logger.addHandler(fh)
if not standalone:
logger.addHandler(fh)

# Do some sanity check before starting the system
# @TODO There is no check for permission
Expand Down Expand Up @@ -129,16 +120,60 @@ if __name__ == "__main__":
mkv = mkvutils.MkvUtils(config)

# Create the Playlist instance
playlist = playlist.PlayList(mkv)
playlist.load(config.get("core", "playlist"))
pl = playlist.PlayList(mkv)
pl.load(config.get("core", "playlist"))

# Create the player instance
player = player.PlayerInterface(config.get("core", "slave_socket"))

# Call the daemon
daemon = daemon.HyberiaDaemon(playlist, player, config, mkv)
daemon = daemon.HyberiaDaemon(pl, player, config, mkv)
# Enter the loop
daemon.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)

0 comments on commit 938c726

Please sign in to comment.