def make_app(no_player=False, fork=None): import web import signal from zicbee_lib.debug import debug_enabled from zicbee_lib.resources import resource_filename from zicbee.core.httpdb import web_db_index # Handle ^C keystroke (try atexit if any problem...) signal.signal(signal.SIGINT, abort) if not no_player: # let's do webplayer try: from zicbee.core.httpplayer import webplayer except (ImportError, RuntimeError): print "Can't load webplayer, falling-back to pure db mode" DEBUG() no_player = True try: # chdir to serve files at the right place p = os.path.dirname(resource_filename('zicbee.ui.web', 'static')) os.chdir( p ) except Exception: DEBUG() pid = 0 # if not forking, still execute children commands do_detach = False # do not try to detach by default if config.fork and not debug_enabled or fork is True: try: pid = os.fork() do_detach = True # fork succeded, try to detach except Exception, e: print "Can't fork: %s."%e
import pygtk pygtk.require('2.0') import gtk icons = 'connect refresh convert dialog-info dialog-error find media-pause media-next-ltr media-play-ltr media-next-rtl'.split() shortnames = { 'info': 'dialog-info', 'error': 'dialog-error', 'play': 'media-play-ltr', 'pause': 'media-pause', 'next': 'media-next-ltr', 'prev': 'media-next-rtl', 'previous': 'media-next-rtl', 'shuffle': 'refresh', # can't find better... } bee_icon = resource_filename('zicbee.ui.notify', 'bee_icon.png') def notify(title, description=None, icon=None, timeout=750): if icon in shortnames: icon = shortnames[icon] if icon in icons: iname = "gtk-"+icon else: iname = 'file://%s'%bee_icon pynotify.init("SimpleNotifier") n = pynotify.Notification(title, description, iname) n.set_urgency(pynotify.URGENCY_LOW) n.set_timeout=(timeout) n.show()
addr = web.ctx.env['REMOTE_ADDR'] admins = config.allow_remote_admin allowed = ['127.0.0.1'] if admins: if len(admins) == 1 and admins[0].lower() in ('yes', 'true', 'on'): return True allowed.extend(admins) return addr in allowed # Set default headers & go to templates directory web.ctx.headers = [('Content-Type', 'text/html; charset=utf-8'), ('Expires', 'Thu, 01 Dec 1994 16:00:00 GMT')] from zicbee_lib.resources import resource_filename try: render = web.template.render(resource_filename('zicbee.ui.web', 'templates')) except Exception, e: DEBUG() class FakeRender(object): def __getattr__(self, name): return self def __call__(self, *args, **kw): return 'Unable to load templates' render = FakeRender() # DB part available_formats = [ ('html', 'WWW Browser'), ('txt', 'Text'), ('json', 'JSON'),