Example #1
0
File: core.py Project: alttch/eva3
def create_dump(e='request', msg='', minimal=False):
    try:
        if minimal:
            result = minidump.run()
        else:
            result = dump.run()
        result.update({'reason': {'event': e, 'info': str(msg)}})
        if not minimal:
            result['log'] = pyaltt2.logs.get(n=DUMP_LOG_RECORDS)
        result['plugin_modules'] = serialize_plugins()
        result['plugins'] = {
            p: exec_plugin_func(p, v, 'dump')
            for p, v in plugin_modules.items()
        }
        filename = dir_var + '/' + time.strftime('%Y%m%d%H%M%S') + \
                '.dump.gz'
        dmp = format_json(result,
                          minimal=not config.development,
                          unpicklable=True).encode()
        with gzip.open(filename, 'w') as fd:
            pass
        os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR)
        with gzip.open(filename, 'a') as fd:
            fd.write(dmp)
        logging.warning('dump created, file: %s, event: %s (%s)' %
                        (filename, e, msg))
    except:
        log_traceback()
        return None
    return filename
Example #2
0
def save():
    try:
        with open(eva.core.dir_runtime + '/uc_modbus.json', 'w') as fd:
            fd.write(format_json(serialize(config=True)))
    except:
        logging.error('unable to save modbus ports config')
        eva.core.log_traceback()
        return False
    return True
Example #3
0
def save():
    try:
        with open(eva.core.dir_runtime + '/lm_extensions.json', 'w') as fd:
            fd.write(format_json(serialize(config=True), minimal=False))
        return True
    except Exception as e:
        logging.error('unable to save ext config: {}'.format(e))
        eva.core.log_traceback()
        return False
Example #4
0
def save_cvars(fname=None):
    fname_full = format_cfg_fname(fname, 'cvars', ext='json', runtime=True)
    logging.info('Saving custom vars to %s' % fname_full)
    try:
        with open(fname_full, 'w') as fd:
            fd.write(format_json(cvars, minimal=False))
    except:
        logging.error('can not save custom vars into %s' % fname_full)
        log_traceback()
        return False
    return True
Example #5
0
def create_dump(e='request', msg=''):
    try:
        result = dump.run()
        result.update({'reason': {'event': e, 'info': str(msg)}})
        filename = dir_var + '/' + time.strftime('%Y%m%d%H%M%S') + \
                '.dump.gz'
        dmp = format_json(result,
                          minimal=not config.development,
                          unpicklable=True).encode()
        with gzip.open(filename, 'w') as fd:
            pass
        os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR)
        with gzip.open(filename, 'a') as fd:
            fd.write(dmp)
        logging.warning('dump created, file: %s, event: %s (%s)' %
                        (filename, e, msg))
    except:
        log_traceback()
        return None
    return filename