Ejemplo n.º 1
0
def do_all(*args):
    def pp(filename):
        c = Ucm2()
        c.load(filename)

    if len(args) == 0:
        error(1, 'Specify root directory with ucm configuration files.')

    env(args[0])
    cs = ucm_get_configs(args[0])
    for c in cs:
        pp(c)
Ejemplo n.º 2
0
def do_configs(*args):

    def import_config(filename):
        fp = open(filename)
        ctx = fp.read(128 * 1024)
        glob = {}
        exec(compile(ctx, filename, 'exec'), glob)
        topdir = os.path.abspath(filename + '/../..')
        config = glob['generate_config'](topdir)
        if not config:
            return
        for k in config:
            if not k in configs:
                configs[k] = config[k]
            else:
                configs[k].update(config[k])

    def config_walk(path1):
        errors = 0
        warnings = 0
        for file in os.listdir(path1):
            if file.startswith('.'):
                continue
            path2 = path1 + '/' + file
            if os.path.isdir(path2):
                errors1, warnings1 = config_walk(path2)
                errors += errors1
                warnings += warnings1
                continue
            if file.endswith('.conf.py'):
                import_config(path2)
                continue
            if not file.endswith('.txt') and not file.endswith('.json') and \
               not file.endswith('.py'):
                continue
            info = file.endswith('.txt') and AlsaInfo() or AlsaJson()
            if filter and not path2 in filter:
                continue
            info.load(path2)
            for cardnum in info.cards:
                card = info.cards[cardnum]
                if card.driver in SKIP_DRIVERS:
                    continue
                c = Ucm2(verify=card)
                for l in c.get_file_list(ucm_path):
                    if os.path.exists(l):
                        break
                    l = None
                if not l:
                    if card.driver in SKIP_DRIVERS2:
                        continue
                    warnings += 1
                    warning('Unable to find UCM configuration for %s', repr(path2))
                    idx = 0
                    for l in c.get_file_list(ucm_path):
                        warning('  Path#%s: %s', idx, repr(l))
                        idx += 1
                    continue
                c.log(1, '*** configuration %s @ %s ***', repr(path2), repr(card))
                if card.components:
                    c.log(1, '  Components: %s', repr(card.components))
                c.conditions = conditions
                c.load(l)
                paths.append(c.shortfn())
                try:
                    c.check()
                except UcmError as e:
                    error1(str(e))
                    error1('  ' + repr(card))
                    errors += 1
                if LOG_LEVEL > 255:
                    sys.stdout.write(c.dump())
        return errors, warnings

    paths = []
    ucm_path = args[0]
    env(ucm_path)
    alsainfo_path = args[1]
    filter = args[2:]
    conditions = {}
    configs = {'suppress_if': {}}
    errors, warnings = config_walk(alsainfo_path)
    # check, if all configuration files were handled
    cs = ucm_get_configs(args[0], short=True, link=False)
    for c in cs:
        if filter and alsainfo_path + '/' + c != filter:
            continue
        if not c in paths:
            error1('%s: no alsa-info files!', c)
            errors += 1
    # check, if all conditions were executed
    for filename in conditions:
        for id in conditions[filename]:
            v = conditions[filename][id]
            if not ('True' in v and 'False' in v):
                what = 'True' in v and 'False' or 'True'
                ifstr = '%s: %s - %s' % (filename, id, what)
                if not ifstr in configs['suppress_if'] or not configs['suppress_if'][ifstr]:
                    error1('%s block not executed', ifstr)
                    errors += 1
    if warnings > 0:
        warning('total warnings: %s' % warnings)
    if errors > 0:
        error1('total errors: %s' % errors)
    return errors and 1 or 0
Ejemplo n.º 3
0
def do_configs(*args):
    def config_walk(path1):
        errors = 0
        warnings = 0
        for file in os.listdir(path1):
            if file.startswith('.'):
                continue
            path2 = path1 + '/' + file
            if os.path.isdir(path2):
                errors1, warnings1 = config_walk(path2)
                errors += errors1
                warnings += warnings1
                continue
            if not file.endswith('.txt') and not file.endswith('.json'):
                continue
            info = file.endswith('.json') and AlsaJson() or AlsaInfo()
            if filter and not path2 in filter:
                continue
            info.load(path2)
            for cardnum in info.cards:
                card = info.cards[cardnum]
                if card.driver in SKIP_DRIVERS:
                    continue
                l1 = ucm_path + '/' + ucm_safe_fn(
                    card.driver) + '/' + ucm_safe_fn(card.longname) + '.conf'
                l2 = ucm_path + '/' + ucm_safe_fn(
                    card.driver) + '/' + ucm_safe_fn(card.driver) + '.conf'
                l = l1
                if not os.path.exists(l):
                    if card.driver in SKIP_DRIVERS2:
                        continue
                    l = l2
                if not os.path.exists(l):
                    warnings += 1
                    warning('Unable to find UCM configuration for %s',
                            repr(path2))
                    warning('  First path: %s', repr(l1))
                    if l1 != l2:
                        warning('  Second path: %s', repr(l2))
                    continue
                c = Ucm2(verify=card)
                c.conditions = conditions
                c.load(l)
                paths.append(c.shortfn())
                try:
                    c.check()
                except UcmError as e:
                    error1(str(e))
                    errors += 1
                if LOG_LEVEL > 255:
                    sys.stdout.write(c.dump())
        return errors, warnings

    paths = []
    ucm_path = args[0]
    env(ucm_path)
    alsainfo_path = args[1]
    filter = args[2:]
    conditions = {}
    errors, warnings = config_walk(alsainfo_path)
    # check, if all configuration files were handled
    cs = ucm_get_configs(args[0], short=True, link=False)
    for c in cs:
        if filter and alsainfo_path + '/' + c != filter:
            continue
        if not c in paths:
            error1('%s: no alsa-info files!', c)
            errors += 1
    # check, if all conditions were executed
    for filename in conditions:
        for cond in conditions[filename]:
            v = conditions[filename][cond]
            if not ('True' in v and 'False' in v):
                what = 'True' in v and 'False' or 'True'
                error1('%s: %s - %s block not executed', filename, v['id'],
                       what)
                errors += 1
    if warnings > 0:
        warning('total warnings: %s' % warnings)
    if errors > 0:
        error1('total errors: %s' % errors)
    return errors and 1 or 0