Exemple #1
0
def gen_colours(parts, output_dir):
    """
    Generates a colours.py from library data
    """
    print('generate ldraw.library.colours...')

    colours_mustache = get_resource(
        os.path.join('templates', 'colours.mustache'))
    colours_template_file = codecs.open(colours_mustache,
                                        'r',
                                        encoding='utf-8')
    colours_template = pystache.parse(colours_template_file.read())

    context = {
        'colours': [get_c_dict(c) for c in parts.colours_by_name.values()]
    }
    context['colours'].sort(key=lambda r: r['code'])

    colours_str = pystache.render(colours_template, context=context)
    library_path = os.path.join(output_dir, 'library')

    colours_py = os.path.join(library_path, 'colours.py')

    with codecs.open(colours_py, 'w', encoding='utf-8') as generated_file:
        generated_file.write(colours_str)
Exemple #2
0
#!/usr/bin/env python
"""
Generates the ldraw.library.parts namespace
"""
import codecs
import os
import itertools

from progress.bar import Bar
import pystache

from ldraw.resources import get_resource
from ldraw.utils import clean, camel, ensure_exists, flatten
from ldraw.parts import PartError

PARTS__INIT__TEMPLATE = get_resource(
    os.path.join('templates', 'parts__init__.mustache'))
PARTS__INIT__TEMPLATE = codecs.open(PARTS__INIT__TEMPLATE,
                                    'r',
                                    encoding='utf-8')
PARTS__INIT__TEMPLATE = pystache.parse(PARTS__INIT__TEMPLATE.read())

PARTS_TEMPLATE = get_resource(os.path.join('templates', 'parts.mustache'))
PARTS_TEMPLATE = codecs.open(PARTS_TEMPLATE, 'r', encoding='utf-8')
PARTS_TEMPLATE = pystache.parse(PARTS_TEMPLATE.read())

SECTION_SEP = '|'


def write_section_file(parts_dir, list_of_parts, mod_path):
    """ Writes a single section files"""
    list_of_parts.sort(key=lambda o: o['description'])