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