gmyth-stream/server/gms.py
branchtrunk
changeset 898 4fbbacbbca34
parent 815 7f290a3a34b1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/server/gms.py	Wed Jan 30 03:36:13 2008 +0000
     1.3 @@ -0,0 +1,74 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +__author__ = "Artur Duque de Souza"
     1.7 +__author_email__ = "artur.souza@indt.org.br"
     1.8 +__license__ = "GPL"
     1.9 +__version__ = "0.3"
    1.10 +__thanks__ = "Gustavo Sverzut Barbieri"
    1.11 +__GMS_DATA_DIR__ = "/usr/share/gms/"
    1.12 +
    1.13 +import sys
    1.14 +import os
    1.15 +import mimetypes
    1.16 +import logging as log
    1.17 +
    1.18 +if os.path.exists (__GMS_DATA_DIR__):
    1.19 +    sys.path.append(__GMS_DATA_DIR__)
    1.20 +
    1.21 +from lib.server import serve_forever, load_plugins_transcoders
    1.22 +from lib.utils import config
    1.23 +
    1.24 +mimetypes.init()
    1.25 +log_level = log.INFO
    1.26 +for p in sys.argv[1:]:
    1.27 +    if p == "-v" or p == "--verbose":
    1.28 +        log_level -= 10
    1.29 +
    1.30 +log.basicConfig(level=log_level,
    1.31 +                format=("### %(asctime)s %(name)-18s \t%(levelname)-8s "
    1.32 +                        "\t%(message)s"),
    1.33 +                datefmt="%Y-%m-%d %H:%M:%S")
    1.34 +
    1.35 +if config.get_transcoded_location () is None:
    1.36 +    print "Gms not configured"
    1.37 +    exit (0)
    1.38 +
    1.39 +if not os.path.exists(config.get_transcoded_location()):
    1.40 +    os.mkdir(config.get_transcoded_location())
    1.41 +
    1.42 +
    1.43 +if "-d" in sys.argv:
    1.44 +    #run with deamon
    1.45 +    try:
    1.46 +        pid = os.fork()
    1.47 +        if pid > 0:
    1.48 +             sys.exit(0)
    1.49 +    except OSError, e:
    1.50 +        print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) 
    1.51 +        sys.exit(1)
    1.52 +
    1.53 +    os.chdir("/")
    1.54 +    os.setsid()
    1.55 +    os.umask(0)
    1.56 +
    1.57 +    try:
    1.58 +        pid = os.fork()
    1.59 +        if pid > 0:
    1.60 +            fp = open ("/var/run/gms.pid", "w")
    1.61 +            fp.write ("%d" % pid)
    1.62 +            fp.close ()
    1.63 +            sys.exit(0)
    1.64 +    except OSError, e:
    1.65 +        print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) 
    1.66 +        sys.exit(1)
    1.67 +
    1.68 +# main deamon
    1.69 +pd = os.path.join(__GMS_DATA_DIR__, "plugins", "transcoders")
    1.70 +if os.path.exists (pd):
    1.71 +    load_plugins_transcoders(pd)
    1.72 +
    1.73 +pd = os.path.join("plugins", "transcoders");
    1.74 +if os.path.exists (pd):
    1.75 +    load_plugins_transcoders(pd)
    1.76 +
    1.77 +serve_forever()