gmyth-stream/server/gms.py
author morphbr
Fri Aug 31 18:31:09 2007 +0100 (2007-08-31)
branchtrunk
changeset 837 6b3c7c0b32ad
parent 815 7f290a3a34b1
permissions -rw-r--r--
[svn r843] - Updated "chunked" bug on gmencoder
- Updated "poll" bug on gmencoder
- Updated wrong method name on transcoder
- Updated request_handler error message
- New version of gmyth_cat
morphbr@718
     1
#!/usr/bin/env python
morphbr@718
     2
morphbr@718
     3
__author__ = "Artur Duque de Souza"
morphbr@718
     4
__author_email__ = "artur.souza@indt.org.br"
morphbr@718
     5
__license__ = "GPL"
morphbr@718
     6
__version__ = "0.3"
morphbr@718
     7
__thanks__ = "Gustavo Sverzut Barbieri"
renatofilho@815
     8
__GMS_DATA_DIR__ = "/usr/share/gms/"
morphbr@718
     9
morphbr@718
    10
import sys
morphbr@718
    11
import os
renatofilho@800
    12
import mimetypes
morphbr@718
    13
import logging as log
renatofilho@815
    14
renatofilho@815
    15
if os.path.exists (__GMS_DATA_DIR__):
renatofilho@815
    16
    sys.path.append(__GMS_DATA_DIR__)
renatofilho@815
    17
morphbr@718
    18
from lib.server import serve_forever, load_plugins_transcoders
renatofilho@815
    19
from lib.utils import config
morphbr@718
    20
renatofilho@800
    21
mimetypes.init()
morphbr@718
    22
log_level = log.INFO
morphbr@718
    23
for p in sys.argv[1:]:
morphbr@718
    24
    if p == "-v" or p == "--verbose":
morphbr@718
    25
        log_level -= 10
morphbr@718
    26
morphbr@718
    27
log.basicConfig(level=log_level,
morphbr@718
    28
                format=("### %(asctime)s %(name)-18s \t%(levelname)-8s "
morphbr@718
    29
                        "\t%(message)s"),
morphbr@718
    30
                datefmt="%Y-%m-%d %H:%M:%S")
morphbr@718
    31
renatofilho@815
    32
if config.get_transcoded_location () is None:
renatofilho@815
    33
    print "Gms not configured"
renatofilho@815
    34
    exit (0)
morphbr@723
    35
renatofilho@815
    36
if not os.path.exists(config.get_transcoded_location()):
renatofilho@815
    37
    os.mkdir(config.get_transcoded_location())
renatofilho@815
    38
renatofilho@815
    39
renatofilho@815
    40
if "-d" in sys.argv:
renatofilho@815
    41
    #run with deamon
renatofilho@815
    42
    try:
renatofilho@815
    43
        pid = os.fork()
renatofilho@815
    44
        if pid > 0:
renatofilho@815
    45
             sys.exit(0)
renatofilho@815
    46
    except OSError, e:
renatofilho@815
    47
        print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) 
renatofilho@815
    48
        sys.exit(1)
renatofilho@815
    49
renatofilho@815
    50
    os.chdir("/")
renatofilho@815
    51
    os.setsid()
renatofilho@815
    52
    os.umask(0)
renatofilho@815
    53
renatofilho@815
    54
    try:
renatofilho@815
    55
        pid = os.fork()
renatofilho@815
    56
        if pid > 0:
renatofilho@815
    57
            fp = open ("/var/run/gms.pid", "w")
renatofilho@815
    58
            fp.write ("%d" % pid)
renatofilho@815
    59
            fp.close ()
renatofilho@815
    60
            sys.exit(0)
renatofilho@815
    61
    except OSError, e:
renatofilho@815
    62
        print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) 
renatofilho@815
    63
        sys.exit(1)
renatofilho@815
    64
renatofilho@815
    65
# main deamon
renatofilho@815
    66
pd = os.path.join(__GMS_DATA_DIR__, "plugins", "transcoders")
renatofilho@815
    67
if os.path.exists (pd):
renatofilho@815
    68
    load_plugins_transcoders(pd)
renatofilho@815
    69
renatofilho@815
    70
pd = os.path.join("plugins", "transcoders");
renatofilho@815
    71
if os.path.exists (pd):
renatofilho@815
    72
    load_plugins_transcoders(pd)
renatofilho@815
    73
morphbr@718
    74
serve_forever()