def run(self): """ Deferred application loading & running """ from phidgetsdbus.logger import log log.path=self.BASEPATH log.name=self.APPNAME try: import dbus.glib import gobject #@UnresolvedImport gobject.threads_init() dbus.glib.init_threads() from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) #glib.threads_init() import phidgetsdbus.api #@UnusedImport log("Starting - pid: %s" % os.getpid()) loop = gobject.MainLoop() gobject.timeout_add(1000, self.setup) loop.run() except Exception,e: log("error", "exception: %s" % e)
def errorMsg(msg, exitCode=1): from phidgetsdbus.terminal import render print render("%(BOLD)s %(RED)s Error:%(NORMAL)s "+msg) sys.exit(exitCode) try: from phidgetsdbus.app import app dr=DaemonRunner(app) dr.parse_args(sys.argv) except IOError,e: errorMsg("Permission error (%s)" % e) except Exception,e: errorMsg("Unexpected error (%s)" % e) try: dr.do_action() except DaemonRunnerStopFailureError,e: errorMsg( "! Can't stop daemon - is one actually running? (%s)" % e ) except DaemonRunnerStartFailureError,e: errorMsg( "! Can't start daemon - is one actually running? (%s)" % e ) except Exception,e: errorMsg( "unexpected error: %s" % e ) ## Will be executed in the daemon context ## Must initialize the logger from phidgetsdbus.logger import log log.path="~/.phidgetsdbus" log.name="phidgetsdbus" log("Ending")