示例#1
0
def update_bundle_property(bdata, bcomp, prop_name):
    # bdata is bundle locale data
    # bcomp is bundle component
    locale_data = bdata.get(bcomp.name, [])
    if locale_data:
        # ensure there is bundle metadata file
        meta_file = bcomp.meta_file
        if not meta_file:
            print('creating bundle file for \"%s\"' % bcomp)
            meta_file = op.join(bcomp.directory, DEFAULT_BUNDLE_FILENAME)
            yaml.dump_dict(
                {
                    prop_name: {
                        DEFAULT_LOCAL_KEY: get_prop_from_comp(
                            prop_name, bcomp)
                    }
                }, meta_file)

        meta = yaml.load_as_dict(meta_file)
        meta = localize_property(meta, prop_name, DEFAULT_LOCAL_KEY)
        print('updating bundle locale data for \"%s\"' % bcomp)
        for locale_code, locale_str in locale_data.items():
            if locale_str:
                if locale_code in meta[prop_name]:
                    print('updating existing locale \"%s\" -> \"%s\"' %
                          (meta[prop_name][locale_code], locale_str))
                else:
                    print('adding locale \"%s\" -> \"%s\"' %
                          (locale_code, locale_str))
                meta[prop_name][locale_code] = locale_str

        yaml.dump_dict(meta, meta_file)

    if bcomp.is_container:
        for child_comp in bcomp:
            update_bundle_property(bdata, child_comp, prop_name)
示例#2
0
def save_configs(configs_dict, parma_file):
    # Load contents of yaml file into an ordered dict
    return yaml.dump_dict(configs_dict, parma_file)