示例#1
0
def update(request):
    """
    Запускает апгрейд ядра и редиректит на главную, где показывает процесс создания нового ядра.
    """
    core = Core.get_instance()
    core_loader = CoreLoader.get_instance()
    core_loader.restart(core.settings)
    return HttpResponseRedirect("/")
示例#2
0
文件: core.py 项目: helicontech/zoo
def state(request):
    """
    Возвращает состояние загрузчика ядра.
    Используется на корневой странице для показать, прогресс загрузки ядра.
    """
    instance = CoreLoader.get_instance()
    state = instance.get_state()
    instance.clean_warnings()
    return state
示例#3
0
def state(request):
    """
    Возвращает состояние загрузчика ядра.
    Используется на корневой странице для показать, прогресс загрузки ядра.
    """
    instance = CoreLoader.get_instance()
    state = instance.get_state()
    instance.clean_warnings()
    return state
示例#4
0
文件: settings.py 项目: perldev/zoo
def settings(request):
    """
    Хендлер.
    GET - Получить настройки
    POST - сохранить переданные настройки, после сохранения настроек - перезагрузить ядро

    :param request:
    :return:
    """
    core = Core.get_instance()

    if request.method == "POST":
        req = json_request(request)
        core.set_settings(req)
        # restart core
        setts = core.settings
        CoreLoader.get_instance().restart(setts)
    else:
        setts = core.settings

    return {"settings": setts.to_dict(), "info": setts.get_state()}
示例#5
0
def settings(request):
    """
    Хендлер.
    GET - Получить настройки
    POST - сохранить переданные настройки, после сохранения настроек - перезагрузить ядро

    :param request:
    :return:
    """
    core = Core.get_instance()

    if request.method == 'POST':
        req = json_request(request)
        core.set_settings(req)
        # restart core
        setts = core.settings
        CoreLoader.get_instance().restart(setts)
    else:
        setts = core.settings

    return {'settings': setts.to_dict(), 'info': setts.get_state()}
示例#6
0
文件: core.py 项目: perldev/zoo
def state(request):
    """
    Возвращает состояние загрузчика ядра.
    Используется на корневой странице для показать, прогресс загрузки ядра.
    """
    return CoreLoader.get_instance().get_state()
示例#7
0
文件: route.py 项目: perldev/zoo
def process_commands(args, settings):
    """
    Start Core and route cmd line commands
    :param args: parsed cmd line argumens (parser.parse_args())
    :param settings: Core will be created with this settings, by default they are loaded from settings.yaml
    :return: None
    """

    # if quiet mode - redefine stdout and stderr
    if args.quiet:
        sys.stdout = open("NUL", 'w')
        sys.stderr = open("NUL", 'w')

    core_loader = CoreLoader.get_instance()

    # start loader, core will be created and initialized in thread
    core_loader.start(settings)

    # commands that require the core, wait core creation
    core = core_loader.wait_core()

    # set interactive mode
    core.interactive = args.interactive
    # process commands that do not require the core
    if args.run_server:
        core_loader.start(settings, make_sync=True)
        cmd = RunServerCommand(settings, args.run_server_addr)
        cmd.setup_logs()
        cmd.start_supervisor()
        cmd.run()

        return



    # print settings
    if args.get_settings:
        settings = core.settings.get_state()
        print(format_dict(settings))
        return

    # set settings from cmd
    if args.set_settings:
        core.set_settings(str_list_to_dict(args.set_settings))
        settings = core.settings.get_state()
        print(format_dict(settings))
        return

    # process install/uninstall task

    if args.worker_task_id:
        RunInstallWorkerCommand(core, args.worker_task_id).run()
        return

    ## subprocess of installing
    if args.task_id:
        RunTaskWorkerCommand(core, args.task_id).run()
        return

    # print products
    if args.list_products:
        ListProductsCommand(core.feed).products()
        return

    # print installed products
    if args.show_installed:
        ListProductsCommand(core.feed).installed()
        return

    # search products and print
    if args.search:
        ListProductsCommand(core.feed).search(args.search)
        return

    # search installed products
    if args.sync:
        SyncCommand(core).do()
        return

    # install products from cmd line
    if args.install:
        InstallCommand(args.products, args.parameters).do()
        return

    # uninstall products from cmd line
    if args.uninstall:
        UninstallCommand(args.products, args.parameters).do()
        return
示例#8
0
文件: route.py 项目: helicontech/zoo
def process_commands(args, settings: Settings):
    """
    Start Core and route cmd line commands
    :param args: parsed cmd line argumens (parser.parse_args())
    :param settings: Core will be created with this settings, by default they are loaded from settings.yaml
    :return: None
    """

    # if quiet mode - redefine stdout and stderr
    if args.quiet:
        sys.stdout = open("NUL", 'w')
        sys.stderr = open("NUL", 'w')


    # get debug level
    log_level_str = args.log_level or os.environ.get('LOG_LEVEL') or 'INFO'
    log_level_str = log_level_str.upper()
    log_level = getattr(logging, log_level_str, logging.INFO)
    # #

    if args.zoo_compile:
        from .commands.zoo_compile import make_build
        make_build(args.zoo_compile)
        return

    core_loader = CoreLoader.get_instance()
    # start loader, core will be created and initialized in thread

    # process commands that do not require the core
    if args.run_server:

        setup_logs(settings.logs_path, log_level, settings.logs_conf)
        # commands that require the core, wait core creation
        logging.info("zoo is starting")
        logging.info(" ".join(sys.argv))
        core_loader.start(settings, make_sync=True)
        cmd = RunServerCommand(settings, args.run_server_addr)
        logging.info("web server is going to run")
        cmd.run()

        return

    if args.run_test:

        setup_logs(settings.logs_path, log_level, settings.logs_conf)
        # commands that require the core, wait core creation
        logging.info("starting test zoo")
        core_loader.start(settings, make_sync=True)
        core = core_loader.wait_core()
        cmd = RunTestCommand(core)
        logging.info("functional tests are going to run")
        cmd.run()

        return



    # print settings
    if args.get_settings:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        settings = core.settings.get_state()
        print(format_dict(settings))
        return

    # set settings from cmd
    if args.set_settings:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        core.set_settings(str_list_to_dict(args.set_settings))
        settings = core.settings.get_state()
        print(format_dict(settings))
        return

    # subprocess of installing
    if args.task_id:
        task_lock = InterProcessLock(name="zoo_task_worker")

        # infinite cycle of trying locking
        try:
            task_lock.lock()
        except SingleInstanceError:
            print("Another installation is currently running. Your installation should begin shortly.")
            while True:
                time.sleep(1)
                try:
                    task_lock.lock()
                    break
                except SingleInstanceError:
                    pass

        # configure logger for task works
        logger = logging.getLogger()
        # remove all handlers
        logger.handlers = []
        logger.setLevel(logging.DEBUG)

        filename = os.path.join(settings.logs_path, args.task_log)
        logging.Formatter('%(asctime)s [%(levelname)s] %(module)s.%(funcName)s: %(message)s')
        ch = None
        if args.task_log:
            ch = logging.FileHandler(filename, mode='a')

        ch1 = logging.StreamHandler(sys.stdout)
        ch1.setLevel(logging.INFO)
        logger.addHandler(ch)
        logger.addHandler(ch1)
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        core.log_manager.setup_log(int(args.task_id))
        logging.info('Instantiating installation worker with following settings:\n{0}'.format(core.settings.format()))
        RunTaskWorkerCommand(core, args.task_id).run()
        task_lock.unlock()
        # delete log
        return

    # print products
    if args.list_products:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        ListProductsCommand(core.feed).products()
        return

    # print installed products
    if args.show_installed:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        ListProductsCommand(core.feed).installed()
        return

    # search products and print
    if args.search:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        ListProductsCommand(core.feed).search(args.search)
        return

    # search installed products
    if args.sync:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        SyncCommand(core).do()
        return

    logger = logging.getLogger()
    # remove all handlers
    logger.handlers = []
    filename = "%s/_zoo_server.log" % settings.logs_path
    ch1 = logging.StreamHandler(sys.stdout) # logging.FileHandler(filename, mode='a')
    ch = logging.StreamHandler(sys.stdout)
    logging.Formatter('%(asctime)s [%(levelname)s] %(module)s.%(funcName)s: %(message)s')
    ch1.setLevel(logging.DEBUG)
    ch.setLevel(logging.INFO)
    logger.addHandler(ch1)
    logger.addHandler(ch)
    logger.setLevel(log_level)

    # install products from cmd line
    if args.install:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        # set interactive mode
        core.interactive = args.interactive
        InstallCommand(args.products, args).do()
        return

    # uninstall products from cmd line
    if args.uninstall:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        # set interactive mode
        core.interactive = args.interactive
        UninstallCommand(args.products, args.parameters).do()
        return
示例#9
0
def process_commands(args, settings: Settings):
    """
    Start Core and route cmd line commands
    :param args: parsed cmd line argumens (parser.parse_args())
    :param settings: Core will be created with this settings, by default they are loaded from settings.yaml
    :return: None
    """

    # if quiet mode - redefine stdout and stderr
    if args.quiet:
        sys.stdout = open("NUL", 'w')
        sys.stderr = open("NUL", 'w')

    # get debug level
    log_level_str = args.log_level or os.environ.get('LOG_LEVEL') or 'INFO'
    log_level_str = log_level_str.upper()
    log_level = getattr(logging, log_level_str, logging.INFO)
    # #

    if args.zoo_compile:
        from .commands.zoo_compile import make_build
        make_build(args.zoo_compile)
        return

    core_loader = CoreLoader.get_instance()
    # start loader, core will be created and initialized in thread

    # process commands that do not require the core
    if args.run_server:

        setup_logs(settings.logs_path, log_level, settings.logs_conf)
        # commands that require the core, wait core creation
        logging.info("zoo is starting")
        logging.info(" ".join(sys.argv))
        core_loader.start(settings, make_sync=True)
        cmd = RunServerCommand(settings, args.run_server_addr)
        logging.info("web server is going to run")
        cmd.run()

        return

    if args.run_test:

        setup_logs(settings.logs_path, log_level, settings.logs_conf)
        # commands that require the core, wait core creation
        logging.info("starting test zoo")
        core_loader.start(settings, make_sync=True)
        core = core_loader.wait_core()
        cmd = RunTestCommand(core)
        logging.info("functional tests are going to run")
        cmd.run()

        return

    # print settings
    if args.get_settings:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        settings = core.settings.get_state()
        print(format_dict(settings))
        return

    # set settings from cmd
    if args.set_settings:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        core.set_settings(str_list_to_dict(args.set_settings))
        settings = core.settings.get_state()
        print(format_dict(settings))
        return

    # subprocess of installing
    if args.task_id:
        task_lock = InterProcessLock(name="zoo_task_worker")

        # infinite cycle of trying locking
        try:
            task_lock.lock()
        except SingleInstanceError:
            print(
                "Another installation is currently running. Your installation should begin shortly."
            )
            while True:
                time.sleep(1)
                try:
                    task_lock.lock()
                    break
                except SingleInstanceError:
                    pass

        # configure logger for task works
        logger = logging.getLogger()
        # remove all handlers
        logger.handlers = []
        logger.setLevel(logging.DEBUG)

        filename = os.path.join(settings.logs_path, args.task_log)
        logging.Formatter(
            '%(asctime)s [%(levelname)s] %(module)s.%(funcName)s: %(message)s')
        ch = None
        if args.task_log:
            ch = logging.FileHandler(filename, mode='a')

        ch1 = logging.StreamHandler(sys.stdout)
        ch1.setLevel(logging.INFO)
        logger.addHandler(ch)
        logger.addHandler(ch1)
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        core.log_manager.setup_log(int(args.task_id))
        logging.info(
            'Instantiating installation worker with following settings:\n{0}'.
            format(core.settings.format()))
        RunTaskWorkerCommand(core, args.task_id).run()
        task_lock.unlock()
        # delete log
        return

    # print products
    if args.list_products:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        ListProductsCommand(core.feed).products()
        return

    # print installed products
    if args.show_installed:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        ListProductsCommand(core.feed).installed()
        return

    # search products and print
    if args.search:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        ListProductsCommand(core.feed).search(args.search)
        return

    # search installed products
    if args.sync:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        SyncCommand(core).do()
        return

    logger = logging.getLogger()
    # remove all handlers
    logger.handlers = []
    filename = "%s/_zoo_server.log" % settings.logs_path
    ch1 = logging.StreamHandler(
        sys.stdout)  # logging.FileHandler(filename, mode='a')
    ch = logging.StreamHandler(sys.stdout)
    logging.Formatter(
        '%(asctime)s [%(levelname)s] %(module)s.%(funcName)s: %(message)s')
    ch1.setLevel(logging.DEBUG)
    ch.setLevel(logging.INFO)
    logger.addHandler(ch1)
    logger.addHandler(ch)
    logger.setLevel(log_level)

    # install products from cmd line
    if args.install:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        # set interactive mode
        core.interactive = args.interactive
        InstallCommand(args.products, args).do()
        return

    # uninstall products from cmd line
    if args.uninstall:
        core_loader.start(settings)
        # commands that require the core, wait core creation
        core = core_loader.wait_core()
        # set interactive mode
        core.interactive = args.interactive
        UninstallCommand(args.products, args.parameters).do()
        return
示例#10
0
文件: manage.py 项目: perldev/zoo
#!/usr/bin/env python

import sys

import os
from core.core_loader import CoreLoader


if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings")

    core_loader = CoreLoader.get_instance()
    core_loader.start()
    core_loader.wait_core()

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)