Пример #1
0
def _validate_state(state):
    # App info
    if not state.name:
        return 1, "Application name must be provided"
    if not state.version:
        return 1, "Application version must be provided"

    # Logging
    if not state.log_output:
        return 1, "Logging output mode must be provided"
    if not state.log_filename_tpl:
        return 1, "Logging file name template must be provided"
    if not state.log_history_size:
        return 1, "Logging history size must be provided"

    # Resources dir
    if not os.path.exists(state.dir_resources):
        return 1, "Resource directory not found: {}".format(state.dir_resources)

    # Config dir
    if not os.path.exists(state.dir_config):
        return 1, "Config directory not found: {}".format(state.dir_config)

    # Work dir
    err, msg = fsutil.ensure_dir(state.dir_work)
    if err:
        return err, msg

    # Log dir
    err, msg = fsutil.ensure_dir(state.dir_log)
    if err:
        return err, msg

    # Diagnostics dir
    err, msg = fsutil.ensure_dir(state.dir_diagnostics)
    if err:
        return err, msg

    # Temp dir
    err, msg = fsutil.ensure_dir(state.dir_temp)
    if err:
        return err, msg

    return 0, None
Пример #2
0
def _init_model(dir_resource, dir_work, filename):

    # Resource directory
    if not os.path.exists(dir_resource):
        return None, 1, "HTML Diags Resource directory does not exist: {}".format(dir_resource)

    # Working dir
    if not os.path.exists(dir_work):
        return None, 1, "HTML Diags Work directory does not exist: {}".format(dir_work)

    err, msg = fsutil.empty_dir(dir_work)
    if err:
        return None, err, "Diagnostic directory cannot be emptied: {}".format(msg)

    err, msg = fsutil.ensure_dir(dir_work)
    if err:
        return None, err, msg

    # HTML log filename
    if not filename:
        return None, 1, "HTML log filename must be provided"

    return Model(dir_resource, dir_work, filename), 0, None