-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
executable file
·95 lines (82 loc) · 3.13 KB
/
app.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Main signage client script
Created by: Rui Carmo
License: MIT (see LICENSE for details)
"""
import os, sys, re, stat, glob, time, json, logging, logging.config, threading, random
import socket, urllib, urllib2, urlparse, commands, functools, subprocess
sys.path.insert(0,'lib') # prefer bundled libraries to local installs
import bottle, utils
# read configuration file and setup various globals
config = utils.get_config(os.path.join(utils.path_for('data'),'config.json'))
# Set up logging
logging.config.dictConfig(dict(config.logging))
log = logging.getLogger()
# validate framebuffer settings
config = utils.validate_resolution(config)
# setup static file root
staticroot = utils.path_for('static')
# check if we have a valid IP address
ip_address = utils.get_ip_address(config.interface)
# Shared data used by other modules
version = '0.13.02.27.6'
# Flag for controlled thread termination
running = True
# Screen state sent from server
screen = {}
# Local URI Prefix
local_uri = 'http://%s:%s' % (config.http.bind_address, config.http.port)
# Defaults sent to templates
template_vars = {
'version' : version,
'ip_address': ip_address,
'width' : config.screen.width,
'height' : config.screen.height,
'debug' : config.debug
}
if __name__=='__main__':
if config.debug:
if 'BOTTLE_CHILD' not in os.environ:
log.debug('Using reloader, spawning first child.')
else:
log.debug('Child spawned.')
if not config.debug or ('BOTTLE_CHILD' in os.environ):
log.info("Setting up application.")
import routes, playlist, browser, beacon, video
# Check if another instance is still running
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((config.http.bind_address,config.http.port))
print "Server already running, exiting."
sys.exit(2)
except socket.error, msg:
pass
log.info("Socket free.")
if ip_address or config.staging:
uzbl = None
if not config.staging:
# Get the browser going
uzbl = browser.Browser(config)
p = playlist.Player(config, uzbl, 'playlist.json')
log.info("Starting player thread")
p.start()
if hasattr(config, 'server_url'):
b = beacon.Beacon(config, utils.get_mac_address(config.interface), ip_address, uzbl)
log.info("Starting beacon thread")
b.start()
else:
log.info("No server configured, operating in standalone mode.")
else:
# Signal for help and stay put. There's no point in debugging the LAN ourselves.
uzbl = browser.Browser(config)
uzbl.do(config.uzbl.uri % (local_uri + '/nonet'))
log.error("Failsafe mode")
log.info("Serving requests.")
bottle.run(
port = config.http.port,
host = config.http.bind_address,
debug = config.debug,
reloader = config.debug
)