コード例 #1
0
# -*- coding: utf-8 -*-

import falcon

from app.api import items
from app import logger
from app.middleware.json_parser import JSONTranslator
from app.errors import AppError

LOG = logger.get_logger()


class App(falcon.API):
    def __init__(self, *args, **kwargs):
        super(App, self).__init__(*args, **kwargs)
        LOG.info('API Server is starting')

        self.add_route('/item', items.ReqItem())
        self.add_error_handler(AppError, AppError.handle)


middleware = [JSONTranslator()]

main = App(middleware=middleware)
コード例 #2
0
import markdown
import markdown.extensions.fenced_code
import os
import app.util
import app.logger as logger
import langdetect

from bs4 import BeautifulSoup
from markdown.extensions.codehilite import CodeHiliteExtension
from markdown.extensions.extra import ExtraExtension

log = logger.get_logger(__name__)


class ErrNotFound(Exception):
    pass


class ErrInvalidFormat(Exception):
    pass


class ErrInvalidName(Exception):
    pass


CONTENT_DIR = "content/posts"


def get(name=""):
コード例 #3
0
import os

from app.utils.io_utils import get_abs_path, get_all_data_from_yaml
from app.logger import get_logger, init_default_handler

# init variables
_global_config_abs_path = get_abs_path(rel_path="../files/globals.cfg.yaml",
                                       caller_script_directory=__file__)

# read configuration from global config file and flatten
_global_config_data = get_all_data_from_yaml(_global_config_abs_path)

# flatten the config for the current environment
base_config_data = _global_config_data.get("dev")
base_config_data.update(
    _global_config_data.get(os.getenv("ENVIRONMENT", "dev")))

# create the global logger
log = get_logger(__name__, log_level=base_config_data.get("log_level"))

# setup the default handler
init_default_handler(log, log_level=base_config_data.get("log_level"))
コード例 #4
0
#!/usr/bin/env python3
from urllib.parse import urlparse

from flask import render_template, request, redirect, abort, escape, jsonify

from app import app
from app.basic_resp import BasicResp
from app.dbutils import get_long_link, insert_id_unique
from app.logger import get_logger

logger = get_logger(__file__)


@app.route('/', methods=['GET', 'POST', 'HEAD'])
@app.route('/<short_link>', methods=['GET', 'POST'])
def short(short_link=""):
    if request.method == "GET" or request.method == 'HEAD':
        if short_link:
            no_auto = short_link[-1] == "+"
            if no_auto:
                short_link = short_link[:-1]
            result = get_long_link(short_link)
            logger.info("get long link {}".format(result))
            if result != "":
                url = result
                parsed_url = urlparse(url)
                if parsed_url.scheme == "":
                    url = "http://" + url

                if "resolve" in request.args:
                    return escape(url)
コード例 #5
0
import sys
import os
import argparse

from flask import Flask, jsonify
from flask import request

# fix app root
app_root = os.getcwd()
sys.path.append(app_root)

from app.config import app_ip, app_version
from app.logger import get_logger

log = get_logger(__name__)
flask_app = Flask(__name__)
log.info('app root dir: {}'.format(app_root))


@flask_app.errorhandler(404)
def not_found(error):
    return json_error(Exception('endpoint not found'), http_code=404)


@flask_app.route('/api/v1/version', methods=['GET'])
def get_version():
    return jsonify({'version': app_version})


@flask_app.route('/api/v1/test', methods=['GET'])
def get_models():
コード例 #6
0
ファイル: main.py プロジェクト: Cypukat85/demo-app
from fastapi import FastAPI, Depends
from app.config import config
from app.logger import get_logger
from app.events import setup_events
from app.route_api import router as api_router

logger = get_logger(level=config['LOG_LEVEL'])
logger.info(f'Logger level is {config["LOG_LEVEL"]}')
# Create application
app = FastAPI(title='Demo app', version='v0.1.0')

# Application init
setup_events(app=app, config=config)
app.extra.update({'config': config})
# Add routes
app.include_router(api_router, prefix='/api', tags=['DEMO API'])

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)
コード例 #7
0
from app.arg_parser import get_args
from app.command_executer import CommandExecuter
from app.logger import get_logger

logger = get_logger()


def execute_console_commands() -> None:
    _args = get_args()
    if getattr(_args, "toolchain_command", None):
        if _args.toolchain_command == "build":
            CommandExecuter.toolchain_build(_args.docker_folder,
                                            _args.docker_context)
    if getattr(_args, "vortex_command", None):
        if _args.vortex_command == "build":
            CommandExecuter.vortex_build(_args.docker_folder,
                                         _args.docker_context,
                                         _args.docker_compose_file)
        if _args.vortex_command == "migrate":
            CommandExecuter.migrate()
        if _args.vortex_command == "start":
            CommandExecuter.vortex_start()
        if _args.vortex_command == "stop":
            CommandExecuter.vortex_stop()
    if getattr(_args, "tests_command", None):
        if _args.tests_command == "run":
            CommandExecuter.vortex_run_tests(_args.tests_set_path)
    if getattr(_args, "git_command", None):
        if _args.git_command == "update_submodules":
            CommandExecuter.update_submodules()
    if getattr(_args, "visualizer_command", None):