def test_generate_test_data(mode):
    _, parts_file = tempfile.mkstemp(suffix='.lst')
    parts_folder_path = os.path.join('tests', 'test_data', 'ldraw', 'parts')
    generate_parts_lst(mode,
                       parts_folder_path=parts_folder_path,
                       parts_lst_path=parts_file)
    expected_parts_file = os.path.join('tests', 'test_data', 'ldraw',
                                       'parts.%s.lst' % mode)

    comparison = filecmp.cmp(parts_file, expected_parts_file, shallow=False)

    if not comparison:
        content = open(parts_file).readlines()
        expected = open(expected_parts_file).readlines()
        for line in difflib.context_diff(expected,
                                         content,
                                         fromfile='expected',
                                         tofile='content'):
            sys.stdout.write(line)

    assert comparison
Exemplo n.º 2
0
def download(output_dir):
    """ download complete.zip, mklist, main function"""
    tmp_ldraw = get_cache_dir()
    parts_lst_path = os.path.join(output_dir, 'parts.lst')

    retrieved = os.path.join(tmp_ldraw, "complete.zip")

    print('retrieve the complete.zip from ldraw.org ...')
    urlretrieve(LDRAW_URL, filename=retrieved)

    print('unzipping the complete.zip ...')
    zip_ref = zipfile.ZipFile(retrieved, 'r')
    zip_ref.extractall(tmp_ldraw)
    zip_ref.close()

    output_dir = ensure_exists(output_dir)

    copy_tree(os.path.join(tmp_ldraw, 'ldraw'), os.path.join(output_dir))

    print('mklist...')
    generate_parts_lst('description', os.path.join(output_dir, 'parts'),
                       parts_lst_path)
Exemplo n.º 3
0
def main(input_directory, description, number, ):
    """Console script for pymklist."""
    if input_directory is None:
        input_directory = os.getcwd()
    if re.match(ldraw, input_directory) and os.path.exists('parts'):
        print('operating from a LDraw folder, continuing...')
    elif not (
        re.match(ldraw, input_directory)
        and
        os.path.exists(os.path.join(input_directory, 'parts'))
    ):
        print('LDraw parts directory not found')
        print('Please specify a LDraw parts library directory'
              'location in the arguments of the mklist call')
        raise click.Abort()

    parts_lst_path = os.path.join(input_directory, 'parts.lst')
    parts_folder_path = os.path.join(input_directory, 'parts')
    if description:
        generate_parts_lst('description', parts_folder_path, parts_lst_path)
    if number:
        generate_parts_lst('number', parts_folder_path, parts_lst_path)