async def set_value(self, ctx, key=None, *value): """ Dynamicaly change config values """ if key is None or not value: await ctx.send(utils.get_command_signature(ctx)) return load_config() await self.change_value(ctx, key, list(value), False)
async def append(self, ctx, key=None, *value): """ Append value(s) to existing config For string and int types command has same bahaviour as `set_value`. """ if key is None or not value: await ctx.send(Messages.config_append_format) return load_config() await self.change_value(ctx, key, list(value), True)
async def sync_template(self, ctx): path = os.path.dirname(__file__)[:-4] config_path = f"{path}config/config.toml" template = toml.load(f"{path}config/config.template.toml", _dict=dict) for section in template: if section in config.toml_dict: for key in template[section]: if key not in config.toml_dict[section]: config.toml_dict[section][key] = template[section][key] else: config.toml_dict[section] = template[section] with open(config_path, "w+", encoding="utf-8") as fd: toml.dump(config.toml_dict, fd) load_config() await ctx.send(Messages.config_synced)
async def load(self, ctx): """ Load config from `config.toml` """ load_config() await ctx.send(Messages.config_loaded)
#!/usr/bin/python # -*- coding: utf-8 -*- from flask import current_app, Blueprint, jsonify, render_template, abort, request, flash, redirect, url_for import config.app_config as app_config import psutil import random import os app_config.load_config() monitor = Blueprint('monitor', __name__, template_folder='templates') @monitor.route('/appsoft') def appsoft(): #cpu = str(psutil.virtual_memory().percent) dict = {} mem_tot = float(psutil.virtual_memory().total) mem_free = float(psutil.virtual_memory().free) percent = mem_free / mem_tot * 100 percent_cpu = str(percent + random.uniform(0, 1)) percent = str(percent + random.uniform(0, 1)) dict['cpu'] = percent_cpu dict['mem'] = percent ob_pid = os.popen( "ps -ef|grep appName|grep -v grep|awk '{print $2}'").readlines() if ob_pid != []: dict['ob_status'] = 'running' else: dict['ob_status'] = 'down'