Exemplo n.º 1
0

@app.context_processor
def inject_site_name():
    return dict(site_name=APP.SITE_NAME)


@app.context_processor
def inject_navbar(navigation_dict=navigation_dictionary_list):
    return dict(navbar_items=navigation_dict)

# Load the version of core specified by the user to pin
try:
    __import__("yams_api.core.%s" % APP.API_VERSION_CORE)
except ImportError as e:
    log.critical("Failed to load core version: %s" % e)
    exit(1)

@app.template_filter()
def to_json_valid_or_error(data_dict):
    """Validate JSON, returning an

    :param json_blob: the json data you want to validate
    :return: json_blob unchanged or {"status": "nok"}
    """
    try:
        json_blob = dumps(data_dict)
    except ValueError:
        json_blob = {"status": "nok"}
    return json_blob
Exemplo n.º 2
0
from importlib.machinery import SourceFileLoader

_here = os.path.abspath(os.path.dirname(__file__))
plugins = glob.glob(_here + "/*/views.py")

for _p in plugins:
    try:
        _plug_dirname = os.path.split(os.path.split(_p)[0])[1]

        # This is ugly: __import__("yams_api.dev.plugins.%s.views" % (_plug_dirname))
        _mod_name = "%s.views" % _plug_dirname
        s = SourceFileLoader(_mod_name, _p).load_module()

    except ImportError as e:
        log.critical("Failed to import module: %s :: %s" % (_p, e))


# error handling and request behavior
@dev_bp.errorhandler(ValidationError)
def validation_error(e):
    return bad_request(e.args[0])


@dev_bp.errorhandler(400)
def bad_request_error(e):
    return bad_request("invalid request")


@dev_bp.errorhandler(404)
def not_found_error(e):
Exemplo n.º 3
0
from importlib.machinery import SourceFileLoader

_here = os.path.abspath(os.path.dirname(__file__))
plugins = glob.glob(_here + "/*/views.py")

for _p in plugins:
    try:
        _plug_dirname = os.path.split(os.path.split(_p)[0])[1]

        # This is ugly: __import__("yams_api.dev.plugins.%s.views" % (_plug_dirname))
        _mod_name = "%s.views" % _plug_dirname
        s = SourceFileLoader(_mod_name, _p).load_module()

    except ImportError as e:
        log.critical("Failed to import module: %s :: %s" % (_p, e))


# error handling and request behavior
@dev_bp.errorhandler(ValidationError)
def validation_error(e):
    return bad_request(e.args[0])


@dev_bp.errorhandler(400)
def bad_request_error(e):
    return bad_request("invalid request")


@dev_bp.errorhandler(404)
def not_found_error(e):
Exemplo n.º 4
0
Arquivo: app.py Projeto: idjaw/yams
@app.context_processor
def inject_site_name():
    return dict(site_name=APP.SITE_NAME)


@app.context_processor
def inject_navbar(navigation_dict=navigation_dictionary_list):
    return dict(navbar_items=navigation_dict)


# Load the version of core specified by the user to pin
try:
    __import__("yams_api.core.%s" % APP.API_VERSION_CORE)
except ImportError as e:
    log.critical("Failed to load core version: %s" % e)
    exit(1)


@app.template_filter()
def to_json_valid_or_error(data_dict):
    """Validate JSON, returning an

    :param json_blob: the json data you want to validate
    :return: json_blob unchanged or {"status": "nok"}
    """
    try:
        json_blob = dumps(data_dict)
    except ValueError:
        json_blob = {"status": "nok"}
    return json_blob
Exemplo n.º 5
0
        log.debug("Setting poison pill to shut down the socket.")
        tcpsocket.POISON_PILL = True

        # for socket in rx_socket, wx_socket, err_sockets, shutdown
        # wait N duration
        # join


if __name__ == "__main__":

    log.info("Starting up.")
    if API.DEBUG:

        flask_reloader_sock_msg = "You will be receiving the error 'Failed to create socket: [Errno 48]...' " \
                                  "this is typical and due to Flask's reloader that gets called in debug mode."
        log.critical(flask_reloader_sock_msg)
        print(flask_reloader_sock_msg)

    # spawn a fresh process -- we don't have resources that we need to share via fork().
    # use a context in case our user wants to further subprocess.  check ipcs after failure mode testing
    # to make sure that this isn't problematic for named semaphores.
    _context = _mp.get_context('spawn')

    # create a general purpose internal queue -- useful for important messages like 'disconnect client x'.
    # unfortunately, POSIX semaphores require r/w to /dev/shm, which isn't there on OS X.
    # Leave here as a reminder that this functionality should be implemented.
    #ipc_queue = _context.Queue()
    # and pass as an arg to the Processes when ready.

    proc_api_http = _context.Process(target=api_http, name="API_HTTP")
    proc_api_socket = _context.Process(target=api_socket, name="API_SOCKET", args=(False,))
Exemplo n.º 6
0
        # for socket in rx_socket, wx_socket, err_sockets, shutdown
        # wait N duration
        # join


if __name__ == "__main__":

    log.info("Starting up.")
    if API.DEBUG:

        flask_reloader_sock_msg = (
            "You will be receiving the error 'Failed to create socket: [Errno 48]...' "
            "this is typical and due to Flask's reloader that gets called in debug mode."
        )
        log.critical(flask_reloader_sock_msg)
        print(flask_reloader_sock_msg)

    # spawn a fresh process -- we don't have resources that we need to share via fork().
    # use a context in case our user wants to further subprocess.  check ipcs after failure mode testing
    # to make sure that this isn't problematic for named semaphores.
    _context = _mp.get_context("spawn")

    # create a general purpose internal queue -- useful for important messages like 'disconnect client x'.
    # unfortunately, POSIX semaphores require r/w to /dev/shm, which isn't there on OS X.
    # Leave here as a reminder that this functionality should be implemented.
    # ipc_queue = _context.Queue()
    # and pass as an arg to the Processes when ready.

    proc_api_http = _context.Process(target=api_http, name="API_HTTP")
    proc_api_socket = _context.Process(target=api_socket, name="API_SOCKET", args=(False,))