def main(): ### Options management parser = OptionParser() parser.add_option( "-V", "--version", action="store_true", dest="display_version", default=False, help="Display the xPL hub version.", ) parser.add_option( "-f", action="store_true", dest="run_in_foreground", default=False, help="Run the xPL hub in foreground, default to background.", ) (options, args) = parser.parse_args() if options.display_version: print(VERSION) sys.exit(0) if not options.run_in_foreground: daemon = True daemonize.createDaemon() # from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor # from twisted.python import log else: daemon = False # from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor # from twisted.python import log ### Launch the hub from domogik.xpl.lib.hub import Hub Hub(daemon)
def main(): ### Options management parser = OptionParser() parser.add_option("-V", "--version", action="store_true", dest="display_version", default=False, help="Display the xPL hub version.") parser.add_option("-f", action="store_true", dest="run_in_foreground", default=False, help="Run the xPL hub in foreground, default to background.") (options, args) = parser.parse_args() if options.display_version: print(VERSION) sys.exit(0) if not options.run_in_foreground: daemon = True daemonize.createDaemon() #from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor #from twisted.python import log else: daemon = False #from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor #from twisted.python import log ### Launch the hub from domogik.xpl.lib.hub import Hub Hub(daemon)
def __init__(self, name, stop_cb = None, p = None, daemonize = True): ''' @param p : An instance of OptionParser. If you want to add extra options to the generic option parser, create your own optionparser instance, use parser.addoption and then pass your parser instance as parameter. Your options/params will then be available on self.options and self.args @param daemonize : If set to False, force the instance *not* to daemonize, even if '-f' is not passed on the command line. If set to True (default), will check if -f was added. ''' # First, check if the user is allowed to launch the plugin. The user must be the same as the one defined # in the file /etc/default/domogik : DOMOGIK_USER Default = DefaultLoader() dmg_user = Default.get("DOMOGIK_USER") logname = pwd.getpwuid(os.getuid())[0] if dmg_user != logname: print("ERROR : this Domogik part must be run with the user defined in /etc/default/domogik as DOMOGIK_USER : %s" % dmg_user) sys.exit(1) # Then, start the plugin... self._threads = [] self._timers = [] if name is not None: self._plugin_name = name self._stop = threading.Event() self._lock_add_thread = threading.Semaphore() self._lock_add_timer = threading.Semaphore() self._lock_add_cb = threading.Semaphore() if stop_cb is not None: self._stop_cb = [stop_cb] else: self._stop_cb = [] # options management if p is not None and isinstance(p, OptionParser): parser = p else: parser = OptionParser() parser.add_option("-V", "--version", action="store_true", dest="display_version", default=False, help="Display Domogik version.") parser.add_option("-f", action="store_true", dest="run_in_foreground", default=False, help="Run the plugin in foreground, default to background.") (self.options, self.args) = parser.parse_args() if self.options.display_version: __import__("domogik") global_release = sys.modules["domogik"].__version__ print global_release sys.exit(0) elif not self.options.run_in_foreground and daemonize: createDaemon() l = logger.Logger(name) self.log = l.get_logger() self.log.info("Daemonize plugin %s" % name) self.is_daemon = True else: l = logger.Logger(name) self.log = l.get_logger() self.is_daemon = False