def _on_run(self, args): """ Callback for execution. :param args: Parsed command line arguments :since: v0.2.00 """ # pylint: disable=attribute-defined-outside-init Settings.read_file("{0}/settings/pas_global.json".format(Settings.get("path_data"))) Settings.read_file("{0}/settings/pas_core.json".format(Settings.get("path_data")), True) Settings.read_file("{0}/settings/pas_tasks_daemon.json".format(Settings.get("path_data")), True) if (args.additional_settings is not None): Settings.read_file(args.additional_settings, True) if (not Settings.is_defined("pas_tasks_daemon_listener_address")): raise IOException("No listener address defined for the TasksDaemon") if (args.reload_plugins): client = BusClient("pas_tasks_daemon") client.request("dNG.pas.Plugins.reload") elif (args.stop): client = BusClient("pas_tasks_daemon") pid = client.request("dNG.pas.Status.getOSPid") client.request("dNG.pas.Status.stop") self._wait_for_os_pid(pid) else: self.cache_instance = NamedLoader.get_singleton("dNG.data.cache.Content", False) if (self.cache_instance is not None): Settings.set_cache_instance(self.cache_instance) self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False) if (self.log_handler is not None): Hook.set_log_handler(self.log_handler) NamedLoader.set_log_handler(self.log_handler) # Hook.load("tasks") Hook.register("dNG.pas.Status.getOSPid", self.get_os_pid) Hook.register("dNG.pas.Status.getTimeStarted", self.get_time_started) Hook.register("dNG.pas.Status.getUptime", self.get_uptime) Hook.register("dNG.pas.Status.stop", self.stop) self.server = BusServer("pas_tasks_daemon") self._set_time_started(time()) if (self.log_handler is not None): self.log_handler.info("TasksDaemon starts listening", context = "pas_tasks") Hook.call("dNG.pas.Status.onStartup") Hook.call("dNG.pas.tasks.Daemon.onStartup") self.set_mainloop(self.server.run)
def _on_run(self, args): """ Callback for execution. :param args: Parsed command line arguments :since: v0.2.00 """ Settings.read_file("{0}/settings/pas_global.json".format(Settings.get("path_data"))) Settings.read_file("{0}/settings/pas_core.json".format(Settings.get("path_data")), True) Settings.read_file("{0}/settings/pas_http.json".format(Settings.get("path_data")), True) if (args.additional_settings is not None): Settings.read_file(args.additional_settings, True) if (args.reload_plugins): client = BusClient("pas_http_bus") client.request("dNG.pas.Plugins.reload") elif (args.stop): client = BusClient("pas_http_bus") pid = client.request("dNG.pas.Status.getOSPid") client.request("dNG.pas.Status.stop") self._wait_for_os_pid(pid) else: self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False) if (self.log_handler is not None): Hook.set_log_handler(self.log_handler) NamedLoader.set_log_handler(self.log_handler) # self.cache_instance = NamedLoader.get_singleton("dNG.data.cache.Content", False) if (self.cache_instance is not None): Settings.set_cache_instance(self.cache_instance) Hook.load("http") Hook.register("dNG.pas.Status.getOSPid", self.get_os_pid) Hook.register("dNG.pas.Status.getTimeStarted", self.get_time_started) Hook.register("dNG.pas.Status.getUptime", self.get_uptime) Hook.register("dNG.pas.Status.stop", self.stop) self._set_time_started(time()) http_server = _HttpServer.get_instance() self.server = BusServer("pas_http_bus") if (http_server is not None): Hook.register("dNG.pas.Status.onStartup", http_server.start) Hook.register("dNG.pas.Status.onShutdown", http_server.stop) if (self.log_handler is not None): self.log_handler.info("pas.http starts listening", context = "pas_http_site") Hook.call("dNG.pas.Status.onStartup") self.set_mainloop(self.server.run)
def _on_run(self, args): """ Callback for execution. :since: v1.0.0 """ # pylint: disable=attribute-defined-outside-init Settings.read_file("{0}/settings/pas_core.json".format(Settings.get("path_data")), True) Settings.read_file("{0}/settings/pas_database.json".format(Settings.get("path_data")), True) log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False) if (log_handler is not None): self.log_handler = log_handler log_handler.debug("#echo(__FILEPATH__)# -{0!r}._on_run()- (#echo(__LINE__)#)", self, context = "pas_database") # self.cli_setup = args.cli_setup Hook.load("database") if (args.apply_schema): self.run_apply_schema(args)
def start(self, params = None, last_return = None): """ Starts all UPnP listeners and announces itself. :param params: Parameter specified :param last_return: The return value from the last hook called. :since: v0.2.00 """ # pylint: disable=broad-except if (self.log_handler is not None): self.log_handler.debug("#echo(__FILEPATH__)# -{0!r}.start()- (#echo(__LINE__)#)", self, context = "pas_upnp") # Set bootid and configid to a value between 0 and 16777215 startupid = int(time()) % 16777216 self.bootid = startupid self.configid = startupid preferred_host = Settings.get("pas_upnp_server_preferred_host") preferred_port = Settings.get("pas_upnp_server_preferred_port") upnp_http_host = (Hook.call("dNG.pas.http.Server.getHost") if (preferred_host is None) else preferred_host ) if (Settings.get("pas_upnp_server_bind_host_to_ipv4", False)): try: upnp_http_host = socket.gethostbyname(upnp_http_host) except socket.error as handled_exception: if (self.log_handler is not None): self.log_handler.debug(handled_exception) # # self.http_host = upnp_http_host self.http_port = (Hook.call("dNG.pas.http.Server.getPort") if (preferred_port is None) else preferred_port ) if (self.http_host is None or self.http_port is None): raise ValueException("HTTP server must provide the hostname and port for the UPnP ControlPoint") if (not Settings.is_defined("pas_http_site_preferred_url_base_upnp")): Settings.set("pas_http_site_preferred_url_base_upnp", "http://{0}:{1:d}".format(self.http_host, self.http_port) ) # Hook.load("upnp") is_ipv6_supported = getattr(socket, "has_ipv6", False) with self.lock: self.bootid += 1 ip_addresses = Settings.get("pas_upnp_bind_network_addresses", [ ]) if (type(ip_addresses) is not list): ip_addresses = [ ] listener_addresses = 0 if (len(ip_addresses) < 1 and Settings.get("pas_upnp_bind_network_addresses_detect", True)): ip_address_list = socket.getaddrinfo(None, self.listener_port, socket.AF_UNSPEC, 0, socket.IPPROTO_UDP) ip_address_list += socket.getaddrinfo(self.http_host, self.http_port, socket.AF_UNSPEC, 0, socket.IPPROTO_TCP) for ip_address_data in ip_address_list: if ((ip_address_data[0] == socket.AF_INET or (is_ipv6_supported and ip_address_data[0] == socket.AF_INET6) ) and ip_address_data[4][0] not in ip_addresses ): ip_addresses.append(ip_address_data[4][0]) # if (self.log_handler is not None and len(ip_addresses) < 1): self.log_handler.warning("pas.upnp.ControlPoint was unable to find available networks", context = "pas_upnp") # for ip_address in ip_addresses: if (ip_address[:4] != "127." and ip_address != "::1"): # Accept user defined or discovered list of IP addresses to listen on to fail on startup try: self._activate_multicast_listener(ip_address) listener_addresses += 1 except Exception: pass # # if (listener_addresses < 1): if (self.log_handler is not None): self.log_handler.debug("{0!r} will bind to all interfaces", self, context = "pas_upnp") self._activate_multicast_listener("0.0.0.0") if (is_ipv6_supported): self._activate_multicast_listener("::0") # # AbstractTimed.start(self) Hook.call("dNG.pas.upnp.ControlPoint.onStartup") if (self.log_handler is not None): self.log_handler.info("pas.upnp.ControlPoint starts with bootId '{0:d}' and configId '{1:d}'", self.bootid, self.configid, context = "pas_upnp") return last_return