Esempio n. 1
0
def config(site):
    if site is None:
        for site in ['site.yml', 'src/site.yml']:
            if os.path.exists(site):
                break
    if not os.path.exists(site):
        logger.error("Site configuration not found.")
        return -1
    config = load_config(site)
    click.echo(yaml.dump(config))
Esempio n. 2
0
File: up.py Progetto: svx/beam-up
def up(site):
    if site is None:
        for site in ['site.yml', 'src/site.yml']:
            if os.path.exists(site):
                break
    if not os.path.exists(site):
        logger.error("Site configuration not found.")
        return -1
    config = load_config(site)
    site = Site(config)
    site.build()
Esempio n. 3
0
def config(site, as_json):
    if site is None:
        for site in ['site.yml', 'src/site.yml']:
            if os.path.exists(site):
                break
    if not os.path.exists(site):
        logger.error("Site configuration not found.")
        return -1
    config = load_config(site)
    if as_json:
        result = json.dumps(config, indent=2, sort_keys=True)
    else:
        result = yaml.dump(config, width=60, indent=2, sort_keys=True, allow_unicode=True, encoding='utf-8').decode('utf-8')
    click.echo(result)
Esempio n. 4
0
def translate_file(token, site_path, destination_path, source_language,
                   target_language, cache):
    count = 0
    source_data = load_config(site_path, with_data=False)

    filters = {
        't':
        lambda key, value, data, context: value
        if source_language == target_language else deserialize_text(
            cached_translate(serialize_text(value), source_language,
                             target_language, cache, token)),
        'f':
        lambda key, value, data, context: value.format(**context),
        'exists?':
        exists,
        'id':
        lambda key, value, data, context: value,
        'ld':
        lambda key, value, data, context: value.get(context['target_language'],
                                                    value['default']),
        'slugify':
        slugify,
    }
    """
    We iterate through the file, parsing the modifiers and generating a new
    config from them...
    """
    transformed_data = transform_data(
        source_data, {
            "source_language": source_language,
            "target_language": target_language,
            "pwd": os.path.dirname(site_path),
        }, filters)
    os.makedirs(os.path.dirname(destination_path), exist_ok=True)
    with open(destination_path, "wb") as output_file:
        output_file.write((
            "# Warning, this is an auto-generated file, do not modify!\n" +
            f"# Modify this file instead: {os.path.relpath(site_path, os.path.dirname(destination_path))}\n"
        ).encode("utf-8"))
        output_file.write(
            yaml.dump(transformed_data,
                      indent=2,
                      sort_keys=True,
                      allow_unicode=True,
                      encoding="utf-8",
                      width=60))