Exemplo n.º 1
0
    def start_server(self, port):
        """
        Start the server.
        """

        self.ws_server = WebSocketServer(port, self.version)
        self.ws_server.start()
class LiveReload(
        threading.Thread,
        SimpleCallbackServer,
        SimpleWSServer,
        SimpleResourceServer,
        LiveReloadAPI,
):
    """
    Start the LiveReload, which exposes public api.
    """
    def __init__(self):

        threading.Thread.__init__(self)
        SimpleCallbackServer.__init__(self)
        SimpleWSServer.__init__(self)
        SimpleResourceServer.__init__(self)
        LiveReloadAPI.__init__(self)

    def run(self):
        """
        Start LiveReload
        """

        path = os.path.join(sublime.packages_path(), "LiveReload", "web",
                            "dist", "livereloadjs-sm2.js")
        local = open(path, "rU")
        self.add_static_file("/livereload.js", local.read(), "text/javascript")

        settings = Settings()
        self.port = settings.get("port", 35729)
        self.version = settings.get("version", "2.0")

        try:
            self.start_server(self.port)
        except Exception:
            sublime.error_message("Port(" + str(self.port) +
                                  ") is already using, trying (" +
                                  str(self.port + 1) + ")")
            time.sleep(3)
            self.start_server(self.port + 1)

    def start_server(self, port):
        """
        Start the server.
        """

        self.ws_server = WebSocketServer(port, self.version)
        self.ws_server.start()

    @atexit.register
    def clean(self):
        """
        Stop the server.
        """

        self.ws_server.stop()
Exemplo n.º 3
0
class LiveReload(threading.Thread, SimpleCallbackServer,
    SimpleWSServer, SimpleResourceServer, LiveReloadAPI):

    """
    Start the LiveReload, which exposes public api.
    """

    def __init__(self):

        threading.Thread.__init__(self)
        SimpleCallbackServer.__init__(self)
        SimpleWSServer.__init__(self)
        SimpleResourceServer.__init__(self)
        LiveReloadAPI.__init__(self)

    def run(self):
        """
        Start LiveReload
        """

        path = os.path.join(sublime.packages_path(), 'LiveReload', 'web'
                            , 'dist', 'livereloadjs-sm2.js')
        local = open(path, 'rU')
        self.add_static_file('/livereload.js', local.read(),
                             'text/javascript')

        settings = Settings()
        self.port = settings.get('port', 35729)
        self.version = settings.get('version', '2.0')

        try:
            self.start_server(self.port)
        except Exception:
            sublime.error_message('Port(' + str(self.port)
                                  + ') is already using, trying ('
                                  + str(self.port + 1) + ')')
            time.sleep(3)
            self.start_server(self.port + 1)

    def start_server(self, port):
        """
        Start the server.
        """

        self.ws_server = WebSocketServer(port, self.version)
        self.ws_server.start()

    @atexit.register
    def clean(self):
        """
        Stop the server.
        """

        self.ws_server.stop()
Exemplo n.º 4
0
class LiveReload(threading.Thread, SimpleCallbackServer, SimpleWSServer,
                 SimpleResourceServer, LiveReloadAPI):
    """
    Start the LiveReload, which exposes public api.
    """
    def __init__(self):

        threading.Thread.__init__(self)
        SimpleCallbackServer.__init__(self)
        SimpleWSServer.__init__(self)
        SimpleResourceServer.__init__(self)
        LiveReloadAPI.__init__(self)

    def run(self):
        """
        Start LiveReload
        """

        path = os.path.join(sublime.packages_path(), 'LiveReload', 'web',
                            'dist', 'livereloadjs-sm2.js')
        local = open(path, 'rU')
        self.add_static_file('/livereload.js', local.read(), 'text/javascript')

        settings = Settings()
        self.port = settings.get('port', 35729)
        self.version = settings.get('version', '2.0')

        try:
            self.start_server(self.port)
        except Exception:
            sublime.error_message('Port(' + str(self.port) +
                                  ') is already using, trying (' +
                                  str(self.port + 1) + ')')
            time.sleep(3)
            self.start_server(self.port + 1)

    def start_server(self, port):
        """
        Start the server.
        """

        self.ws_server = WebSocketServer(port, self.version)
        self.ws_server.start()

    @atexit.register
    def clean(self):
        """
        Stop the server.
        """

        self.ws_server.stop()
Exemplo n.º 5
0
    def start_server(self, port):
        """
        Start the server.
        """

        self.ws_server = WebSocketServer(port, self.version)
        self.ws_server.start()