How to use the clldutils.inifile.INI function in clldutils

To help you get started, we’ve selected a few clldutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clld / glottolog3 / glottolog3 / scripts / tofs.py View on Github external
def mkdir(lang, triggers, parent=None):
    # turn "Unclassified xxx" into an extra dir!
    if lang.jsondata.get('hname', '').startswith('Unclassified'):
        parent = mkdir(UnclassifiedGroup(lang.jsondata['hname']), triggers, parent=parent)

    parent = parent or Path('.')
    fname = '%s.%s' % (slug(lang.name), lang.id)
    d = parent.joinpath(fname)
    d.mkdir(exist_ok=True)

    subgroup = lang.level == LanguoidLevel.family
    md = INI(interpolation=None)
    for section, options in [
        ('core', [
            ('name', lang.name),
            ('glottocode', lang.id),
            ('hid', getattr(lang, 'hid', None)),
            ('level', lang.level.value),
            ('iso639-3', getattr(lang, 'iso_code', None)),
            ('latitude', getattr(lang, 'latitude', None)),
            ('longitude', getattr(lang, 'longitude', None)),
            ('macroareas', None if subgroup else [ma.name for ma in lang.macroareas]),
            ('countries', None if subgroup else ['%s (%s)' % (c.name, c.id) for c in lang.countries]),
            ('status', getattr(lang, 'endangerment', None)),
        ]),
        ('alternative names', [
            ('ethnologue', None),
            ('wals', None)
github clld / glottolog3 / glottolog3 / scripts / tofs.py View on Github external
def main(args):
    code_pattern = re.compile('{(?P<code>[^}]+)}$')
    triggers = OrderedDict()
    triggers['lgcode'] = {}
    triggers['inlg'] = {}

    for type_ in triggers:
        cfg = INI(interpolation=None)
        with io.open(args.data_dir.joinpath('references', 'alt4%s.ini' % type_), encoding='utf8') as fp:
            cfg.readfp(fp)
        for section in cfg.sections():
            match = code_pattern.search(section)
            if match:
                triggers[type_][match.group('code')] = cfg.get(section, 'triggers')

    roots = [
        row[0] for row in DBSession.query(Languoid.pk)
        .filter(Languoid.active == True)
        .filter(Languoid.father_pk == None)]

    for root in roots:
        root = DBSession.query(Languoid).filter(Languoid.pk == root).one()
        print(root.name)
        mkdir(root, triggers)</code>
github lmaurits / BEASTling / beastling / models / binary.py View on Github external
def __init__(self, model_config, global_config):
        BinaryModel.__init__(self, model_config, global_config)
        try:
            share_params = model_config.get("share_params", "True")
            self.share_params = INI.BOOLEAN_STATES[share_params.lower().strip()]
        except KeyError:
            raise ValueError("Invalid setting of 'share_params' (%s) for model %s, not a boolean" % (share_params, self.name))
        self.single_sitemodel = self.share_params and not (self.rate_variation or self.feature_rates)