示例#1
0
文件: api.py 项目: istvanfedak/mmpm
def force_refresh_magicmirror_modules() -> str:
    log.logger.info(f'Recieved request to refresh modules')
    process: Group = Group()
    Response(__stream_cmd_output__(process, ['-f', '--GUI']),
             mimetype='text/plain')
    log.logger.info('Finished refresh')
    return json.dumps(True)
示例#2
0
文件: api.py 项目: istvanfedak/mmpm
def remove_magicmirror_modules() -> Response:
    selected_modules: list = request.get_json(force=True)['selected-modules']
    process: Group = Group()

    return Response(__stream_cmd_output__(
        process, ['-r'] +
        [selected_module['title'] for selected_module in selected_modules]),
                    mimetype='text/plain')
示例#3
0
文件: api.py 项目: istvanfedak/mmpm
def install_magicmirror_modules() -> str:
    selected_modules: list = request.get_json(force=True)['selected-modules']
    log.logger.info(f'Request to install {selected_modules}')
    process: Group = Group()
    Response(__stream_cmd_output__(
        process, ['-i'] +
        [selected_module['title'] for selected_module in selected_modules]),
             mimetype='text/plain')

    log.logger.info('Finished installing')
    return json.dumps(True)
示例#4
0
def upgrade_magicmirror() -> str:
    log.logger.info(f'Request to upgrade MagicMirror')
    process: Group = Group()
    Response(__stream_cmd_output__(process, ['-M', '--GUI']), mimetype='text/plain')
    log.logger.info('Finished installing')

    if utils.get_pids('chromium') and utils.get_pids('node') and utils.get_pids('npm'):
        utils.kill_magicmirror_processes()
        utils.start_magicmirror()

    return json.dumps(True)
示例#5
0
def remove_external_module_source() -> str:
    selected_sources: list = request.get_json(force=True)['external-sources']
    log.logger.info(f'Request to remove external sources')

    process: Group = Group()
    Response(
        __stream_cmd_output__(process, ['-r'] + [external_source['title'] for external_source in selected_sources] + ['--ext-module-src']),
        mimetype='text/plain'
    )

    return json.dumps(True)
示例#6
0
def __stream_cmd_output__(process: Group, cmd: list):
    '''
    Streams command output to socket.io client on frontend.

    Parameters:
        process (Group): the process object responsible for running the command
        cmd (List[str]): list of command arguments

    Returns:
        None
    '''
    command: list = MMPM_EXECUTABLE + cmd
    log.logger.info(f"Executing {command}")
    process.run(command)

    try:
        while process.is_pending():
            log.logger.info('Process pending')
            for _, line in process.readlines():
                socketio.emit('live-terminal-stream', {'data': str(line.decode('utf-8'))})
        log.logger.info(f'Process complete: {command}')
    except Exception:
        pass