当前位置: 首页>>代码示例>>Python>>正文


Python Hook.load方法代码示例

本文整理汇总了Python中dNG.plugins.hook.Hook.load方法的典型用法代码示例。如果您正苦于以下问题:Python Hook.load方法的具体用法?Python Hook.load怎么用?Python Hook.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dNG.plugins.hook.Hook的用法示例。


在下文中一共展示了Hook.load方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _on_run

# 需要导入模块: from dNG.plugins.hook import Hook [as 别名]
# 或者: from dNG.plugins.hook.Hook import load [as 别名]
    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)
开发者ID:dNG-git,项目名称:pas_tasks_loader,代码行数:56,代码来源:tasks_daemon.py

示例2: _on_run

# 需要导入模块: from dNG.plugins.hook import Hook [as 别名]
# 或者: from dNG.plugins.hook.Hook import load [as 别名]
    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)
开发者ID:dNG-git,项目名称:pas_http_loader,代码行数:55,代码来源:http_server.py

示例3: _on_run

# 需要导入模块: from dNG.plugins.hook import Hook [as 别名]
# 或者: from dNG.plugins.hook.Hook import load [as 别名]
    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)
开发者ID:dNG-git,项目名称:pas_database,代码行数:26,代码来源:db_tool.py

示例4: start

# 需要导入模块: from dNG.plugins.hook import Hook [as 别名]
# 或者: from dNG.plugins.hook.Hook import load [as 别名]
    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
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:101,代码来源:control_point.py


注:本文中的dNG.plugins.hook.Hook.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。