diff -r 7f290a3a34b1 -r 0cc42675b88d gmyth-stream/server/gms.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/server/gms.py Wed Jan 23 20:04:59 2008 +0000 @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +__author__ = "Artur Duque de Souza" +__author_email__ = "artur.souza@indt.org.br" +__license__ = "GPL" +__version__ = "0.3" +__thanks__ = "Gustavo Sverzut Barbieri" +__GMS_DATA_DIR__ = "/usr/share/gms/" + +import sys +import os +import mimetypes +import logging as log + +if os.path.exists (__GMS_DATA_DIR__): + sys.path.append(__GMS_DATA_DIR__) + +from lib.server import serve_forever, load_plugins_transcoders +from lib.utils import config + +mimetypes.init() +log_level = log.INFO +for p in sys.argv[1:]: + if p == "-v" or p == "--verbose": + log_level -= 10 + +log.basicConfig(level=log_level, + format=("### %(asctime)s %(name)-18s \t%(levelname)-8s " + "\t%(message)s"), + datefmt="%Y-%m-%d %H:%M:%S") + +if config.get_transcoded_location () is None: + print "Gms not configured" + exit (0) + +if not os.path.exists(config.get_transcoded_location()): + os.mkdir(config.get_transcoded_location()) + + +if "-d" in sys.argv: + #run with deamon + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + + os.chdir("/") + os.setsid() + os.umask(0) + + try: + pid = os.fork() + if pid > 0: + fp = open ("/var/run/gms.pid", "w") + fp.write ("%d" % pid) + fp.close () + sys.exit(0) + except OSError, e: + print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + +# main deamon +pd = os.path.join(__GMS_DATA_DIR__, "plugins", "transcoders") +if os.path.exists (pd): + load_plugins_transcoders(pd) + +pd = os.path.join("plugins", "transcoders"); +if os.path.exists (pd): + load_plugins_transcoders(pd) + +serve_forever()