예제 #1
0
파일: run.py 프로젝트: mjd515/docker-ubnt
def main():
    def run_with_reloader(main_func, extra_files=None, interval=3):
        """Run the given function in an independent python interpreter."""
        def find_files(directory="./"):
            for root, dirs, files in os.walk(directory):
                for basename in files:
                    if basename.endswith('.py'):
                        filename = os.path.join(root, basename)
                        yield filename

        if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
            try:
                main_func()
            except KeyboardInterrupt:
                pass
            return

        proc = None
        try:
            while True:
                log.info('Restarting with reloader {} {}'.format(
                    sys.executable,
                    ' '.join(sys.argv))
                )
                args = [sys.executable] + sys.argv
                new_environ = os.environ.copy()
                new_environ['WERKZEUG_RUN_MAIN'] = 'true'

                proc = subprocess.Popen(
                    args,
                    env=new_environ,
                    close_fds=True,
                    preexec_fn=os.setsid
                )
                mtimes = {}
                restart = False
                while not restart:
                    for filename in find_files():
                        try:
                            mtime = os.stat(filename).st_mtime
                        except OSError:
                            continue

                        old_time = mtimes.get(filename)
                        if old_time is None:
                            mtimes[filename] = mtime
                            continue
                        elif mtime > old_time:
                            log.info(
                                'Detected change in {}, reloading'.format(
                                    filename
                                )
                            )
                            restart = True
                            proc.terminate()
                            break
                    time.sleep(interval)
        except KeyboardInterrupt:
            pass
        finally:
            with ignored(Exception):
                proc.terminate()

    def run_server():
        import socket
        from gevent.pywsgi import WSGIServer
        from vnc.app import app

        # websocket conflict: WebSocketHandler
        if DEBUG:
            # from werkzeug.debug import DebuggedApplication
            app.debug = True
            # app = DebuggedApplication(app, evalex=True)

        try:
            log.info('Listening on http://localhost:{}'.format(PORT))
            http_server = WSGIServer(('localhost', PORT), app)
            http_server.serve_forever()
            # app.run(host='localhost', port=PORT)
        except socket.error as e:
            log.exception(e)
        except KeyboardInterrupt:
            pass
        finally:
            http_server.stop(timeout=10)
            log.info('shutdown gracefully')

    PORT = 6079
    DEBUG = False
    os.environ['CONFIG'] = 'config.Production'
    entrypoint = run_server
    if '--debug' in sys.argv:
        DEBUG = True
        os.environ['CONFIG'] = 'config.Development'
        entrypoint = lambda: run_with_reloader(run_server)

    # logging
    import logging
    from log.config import LoggingConfiguration
    LoggingConfiguration.set(
        logging.DEBUG if DEBUG else logging.INFO,
        '/var/log/web.log'
    )
    logging.getLogger("werkzeug").setLevel(logging.WARNING)
    log = logging.getLogger('novnc2')

    entrypoint()
예제 #2
0
import time

# Flask app
app = Flask(__name__,
            static_folder='static',
            static_url_path='',
            instance_relative_config=True)
CONFIG = os.environ.get('CONFIG') or 'config.Development'
app.config.from_object('config.Default')
app.config.from_object(CONFIG)
FIRST = 'RESOLUTION' not in os.environ

# logging
import logging
from log.config import LoggingConfiguration
LoggingConfiguration.set(logging.DEBUG if os.getenv('DEBUG') else logging.INFO,
                         '/var/log/web.log')


def exception_to_json(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
            return result
        except (
                BadRequest,
                KeyError,
                ValueError,
        ) as e:
            result = {'error': {'code': 400, 'message': str(e)}}
        except PermissionDenied as e:
예제 #3
0
import os

# Flask app
app = Flask(__name__,
            static_folder='static',
            static_url_path='',
            instance_relative_config=True)
CONFIG = os.environ.get('CONFIG') or 'config.Development'
app.config.from_object('config.Default')
app.config.from_object(CONFIG)

# logging
import logging
from log.config import LoggingConfiguration
LoggingConfiguration.set(logging.DEBUG if os.getenv('DEBUG') else logging.INFO,
                         'lightop.log',
                         name='Web')

import json
from functools import wraps
import subprocess
import time

FIRST = True


def exception_to_json(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)

# Flask app
app = Flask(__name__,
            static_folder='static', static_url_path='',
            instance_relative_config=True)
CONFIG = os.environ.get('CONFIG') or 'config.Development'
app.config.from_object('config.Default')
app.config.from_object(CONFIG)
app.config.from_pyfile('application.cfg')

# logging
import logging
from log.config import LoggingConfiguration
LoggingConfiguration.set(
    logging.DEBUG if os.getenv('DEBUG') else logging.INFO,
    'lightop.log', name='Web')


import json
from functools import wraps
import subprocess
import time


FIRST = True


def exception_to_json(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
예제 #5
0
def main():
    def run_with_reloader(main_func, extra_files=None, interval=3):
        """Run the given function in an independent python interpreter."""
        def find_files(directory="./"):
            for root, dirs, files in os.walk(directory):
                for basename in files:
                    if basename.endswith('.py'):
                        filename = os.path.join(root, basename)
                        yield filename

        if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
            try:
                main_func()
            except KeyboardInterrupt:
                pass
            return

        proc = None
        try:
            while True:
                log.info('Restarting with reloader {} {}'.format(
                    sys.executable,
                    ' '.join(sys.argv))
                )
                args = [sys.executable] + sys.argv
                new_environ = os.environ.copy()
                new_environ['WERKZEUG_RUN_MAIN'] = 'true'

                proc = subprocess.Popen(
                    args,
                    env=new_environ,
                    close_fds=True,
                    preexec_fn=os.setsid
                )
                mtimes = {}
                restart = False
                while not restart:
                    for filename in find_files():
                        try:
                            mtime = os.stat(filename).st_mtime
                        except OSError:
                            continue

                        old_time = mtimes.get(filename)
                        if old_time is None:
                            mtimes[filename] = mtime
                            continue
                        elif mtime > old_time:
                            log.info(
                                'Detected change in {}, reloading'.format(
                                    filename
                                )
                            )
                            restart = True
                            proc.terminate()
                            break
                    time.sleep(interval)
        except KeyboardInterrupt:
            pass
        finally:
            with ignored(Exception):
                proc.terminate()

    def run_server():
        import socket
        from gevent.wsgi import WSGIServer
        from vnc.app import app

        # websocket conflict: WebSocketHandler
        if DEBUG:
            # from werkzeug.debug import DebuggedApplication
            app.debug = True
            # app = DebuggedApplication(app, evalex=True)

        try:
            log.info('Listening on http://localhost:{}'.format(PORT))
            http_server = WSGIServer(('localhost', PORT), app)
            http_server.serve_forever()
            # app.run(host='localhost', port=PORT)
        except socket.error as e:
            log.exception(e)
        except KeyboardInterrupt:
            pass
        finally:
            http_server.stop(timeout=10)
            log.info('shutdown gracefully')

    PORT = 6079
    DEBUG = False
    os.environ['CONFIG'] = 'config.Production'
    entrypoint = run_server
    if '--debug' in sys.argv:
        DEBUG = True
        os.environ['CONFIG'] = 'config.Development'
        entrypoint = lambda: run_with_reloader(run_server)

    # logging
    import logging
    from log.config import LoggingConfiguration
    LoggingConfiguration.set(
        logging.DEBUG if DEBUG else logging.INFO,
        '/var/log/web.log'
    )
    logging.getLogger("werkzeug").setLevel(logging.WARNING)
    log = logging.getLogger('novnc2')
    entrypoint()
# Flask app
app = Flask(__name__,
            static_folder="static",
            static_url_path="",
            instance_relative_config=True)
CONFIG = os.environ.get("CONFIG") or "config.Development"
app.config.from_object("config.Default")
app.config.from_object(CONFIG)
app.config.from_pyfile("application.cfg")

# logging
import logging
from log.config import LoggingConfiguration

LoggingConfiguration.set(logging.DEBUG if os.getenv("DEBUG") else logging.INFO,
                         "lightop.log",
                         name="Web")

import json
from functools import wraps
import subprocess
import time

FIRST = True


def exception_to_json(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)