File: testserver

package info (click to toggle)
deejayd 0.9.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 2,596 kB
  • ctags: 2,514
  • sloc: python: 11,904; xml: 594; sh: 338; makefile: 42
file content (118 lines) | stat: -rwxr-xr-x 3,865 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python

# Deejayd, a media player daemon
# Copyright (C) 2007-2009 Mickael Royer <mickael.royer@gmail.com>
#                         Alexandre Rossi <alexandre.rossi@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
This is a deejayd test server executable
"""

import sys, os, traceback

from twisted.python import log
import twisted.internet.error


# argv[1] should be configuration files
if len(sys.argv) != 2:
    sys.exit('Incorrect invocation')

log.startLogging(open('/tmp/testdeejayd.log', 'a'))

from deejayd.ui.config import DeejaydConfig
conf_file = sys.argv[1]
if os.path.isfile(conf_file):
    DeejaydConfig.custom_conf = conf_file
else:
    os.write(2, 'stopped\n')
    sys.exit()
config = DeejaydConfig()

# init translation
from deejayd.ui.i18n import DeejaydTranslations
t = DeejaydTranslations()
t.install()

# instanciate reactor
media_backend = config.get("general", "media_backend")
if media_backend == "gstreamer":
    # Install glib2 reactor
    from twisted.internet import glib2reactor
    glib2reactor.install()
from twisted.internet import reactor
# use twisted loop for kaa
import kaa
kaa.main.select_notifier('twisted')

# start core
from deejayd.core import DeejayDaemonCore
try:
    deejayd_core = DeejayDaemonCore(config)
    deejayd_core.update_audio_library(sync = True, objanswer = False)

    activated_sources = config.getlist('general', "activated_modes")
    if "video" in activated_sources: # video library activated
        deejayd_core.update_video_library(sync = True, objanswer = False)
except Exception, ex:
    try: deejayd_core.close()
    except:
        pass
    from deejayd.utils import str_encode
    err = "Unable to launch deejayd core, see traceback for more details"
    log.msg(err)
    log.msg(str_encode(traceback.format_exc()))
    os.write(2, 'stopped\n')
    sys.exit()

# net protocol
if config.getboolean("net","enabled"):
    from deejayd.net.protocol import DeejaydFactory
    factory = DeejaydFactory(deejayd_core)
    try:
        reactor.listenTCP(config.getint("net","port"), factory)
    except twisted.internet.error.CannotListenError:
        # This is to avoid locking the test suite when the server used in the
        # previous test has not stopped listenning.
        deejayd_core.close()
        os.write(2, 'stopped\n')
        sys.exit()
# http protocol
if config.getboolean("webui","enabled"):
    from deejayd import webui
    htdocs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),\
            '..', 'data', 'htdocs'))
    site = webui.init(deejayd_core, config,
                '/tmp/testdeejayd-webui.log', htdocs_dir)
    try:
        reactor.listenTCP(config.getint("webui","port"), site)
    except twisted.internet.error.CannotListenError:
        # This is to avoid locking the test suite when the server used in the
        # previous test has not stopped listenning.
        deejayd_core.close()
        os.write(2, 'stopped\n')
        sys.exit()

def printReady():
    os.write(2, 'ready\n')

reactor.addSystemEventTrigger('after', 'startup', printReady)
reactor.addSystemEventTrigger('after', 'shutdown', deejayd_core.close)
reactor.run()


# vim: ts=4 sw=4 expandtab