Exemple #1
0
def check_number(value, cast, minv=0, maxv=None):
    try:
        typed_value = cast(value)
    except ValueError:
        raise ConfigError("Expected [%s] number. Found [%s]" % (cast, value))
    else:
        if (minv is not None and typed_value < cast(minv)) or \
           (maxv is not None and typed_value > cast(maxv)):
            _minv = minv if minv is not None else "any"
            _maxv = maxv if maxv is not None else "any"
            raise ConfigError("[%s] not in the range (%s,%s)" %
                              (value, _minv, _maxv))
    return typed_value
Exemple #2
0
def is_appset_entry(value):
    if not isinstance(value, list) or len(value) != 2:
        raise ConfigError(
            "unexpected application format [%s]. Expected [appname, maxcpus] format"
            % value)
    try:
        cores = int(value[2])
    except ValueError:
        raise ConfigError(
            "unexpected application format [%s]. Expected [appname, maxcpus] format (maxcpus as integer)"
            % value)

    return [value[0], cores]
Exemple #3
0
def is_percent(value):
    try:
        is_float(value.rstrip('%'))
    except ConfigError:
        raise ConfigError('[%s] should a percentage value (i.e. 0.4%%)' %
                          value)
    return value
Exemple #4
0
def is_boolean(value):
    if str(value).lower() in set(["1", "true", "yes"]):
        return True
    elif str(value).lower() in set(["0", "false", "no"]):
        return False
    else:
        raise ConfigError('[%s] is not a boolean value' % (value))
Exemple #5
0
def is_app_link(value, allow_none=True):
    if allow_none and value == 'none':
        return value
    elif value.startswith('@'):
        return value
    else:
        raise ConfigError('[%s] is not a valid block link' % value)
Exemple #6
0
def is_raxml_bootstrap(value):
    try:
        return is_integer(value)
    except ValueError:
        if value == 'alrt' or value == 'alrt_phyml':
            return value
        else:
            raise ConfigError(
                '[%s] bootstrap value should an integer, "alrt" or "phyml_alrt"'
                % (value))
Exemple #7
0
def is_integer_or_percent(value):
    try:
        return is_integer(value)
    except ConfigError:
        try:
            is_percent(value)
        except ConfigError:
            raise ConfigError(
                '[%s] should be an integer or a percentage (i.e. 15 or 0.4%%)'
                % value)
    return value
Exemple #8
0
def check_cores(j, cores_used, cores_total, execution):
    if j.cores > cores_total:
        raise ConfigError("Job [%s] is trying to be executed using [%d] cores."
                          " However, the program is limited to [%d] core(s)."
                          " Use the --multicore option to enable more cores." %
                          (j, j.cores, cores_total))
    elif execution == "insitu" and j.cores > cores_total - cores_used:
        log.log(22, "Job [%s] awaiting [%d] core(s)" % (j, j.cores))
        return False
    else:
        return True
Exemple #9
0
def check_config(fname):
    conf = ConfigObj(fname, list_values=True)
    for k, v in conf.items():
        if '_inherits' in v:
            base = v['_inherits']
            try:
                new_dict = dict(conf[base])
            except KeyError:
                raise ConfigError(
                    '[%s] config block is referred in [%s] but not present in config file'
                    % (base, k))
            new_dict.update(v)
            conf[k] = new_dict

    for k in conf.iterkeys():
        blocktype = conf[k].get('_app', 'unknown')
        for attr, v in conf[k].items():
            conf[k][attr] = check_type(blocktype, attr, v)
            if isinstance(conf[k][attr], list):
                for i in conf[k][attr]:
                    check_block_link(conf, k, i)
            else:
                check_block_link(conf, k, conf[k][attr])
        for tag, tester in CHECKERS.iteritems():
            if tag[0] == blocktype and (tester[2] and tag[1] not in conf[k]):
                raise ConfigError('[%s] attribute expected in block [%s]' %
                                  (tag[1], k))

    # Check that the number of columns in main workflow definition is the same in all attributes
    for flow_name in conf.iterkeys():
        if conf[flow_name].get("_app", "") != "main":
            continue
        npr_config = [
            len(v) for k, v in conf[flow_name].iteritems()
            if type(v) == list and k != "target_levels"
        ]
        if len(set(npr_config)) != 1:
            raise ConfigError(
                "List values in [%s] should all have the same length" %
                flow_name)
    return conf
Exemple #10
0
def is_correlative_integer_list(value, minv=None, maxv=None):
    is_list(value)
    typed_value = []
    last_value = 0
    for v in value:
        cv = is_integer(v, minv=None, maxv=None)
        typed_value.append(cv)
        if cv <= last_value:
            raise ConfigError("[%s] Numeric values are not correlative" %
                              value)
        last_value = cv
    return typed_value
Exemple #11
0
def is_choice(value, choices):
    if value in choices:
        return value
    else:
        raise ConfigError('[%s] should be one of %s' % (value, choices))
Exemple #12
0
def is_text(value):
    if isinstance(value, str):
        return value
    else:
        raise ConfigError("[%s] is not a valid text string" % value)
Exemple #13
0
def is_list(value):
    if not isinstance(value, list):
        raise ConfigError("[%s] is not a list" % value)
    return value
Exemple #14
0
def is_set(value):
    if not isinstance(value, list):
        raise ConfigError("Expected a list of values. Found [%s]" % value)
    return set(value)
Exemple #15
0
def is_dir(value):
    if os.path.isdir(value):
        return value
    else:
        raise ConfigError("Not valid file")
Exemple #16
0
def check_block_link(conf, parent, v):
    if isinstance(v, str) and v.startswith('@') and v[1:] not in conf:
        raise ConfigError(
            '[%s] config block referred in [%s] but not found in config' %
            (v, parent))