Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not load complete.zip parts library #7

Open
hgschmie opened this issue Oct 25, 2020 · 6 comments
Open

can not load complete.zip parts library #7

hgschmie opened this issue Oct 25, 2020 · 6 comments

Comments

@hgschmie
Copy link

MacOS 10.15.7, python 3.8.6 (installed from homebrew)

pyldraw installed from git repo (git clone ... pip3 install . )

when running ldr2png:

❯ ldr2png --help
retrieve the complete.zip from ldraw.org ...
unzipping the complete.zip ...
mklist...
generate ldraw.library.colours...
generate ldraw.library.parts, this might take a long time...
section minifig|hats ... |################################| 36/36
section minifig|heads ... |################################| 339/339
section minifig|torsos ... |################################| 498/498
section minifig|legs ... |################################| 122/122
section minifig|arms ... |################################| 22/22
section minifig|hands ... |################################| 11/11
section minifig|accessories ... |################################| 894/894
section minifig| ... |################################| 141/141
section animal ... |################################| 251/251
section antenna ... |################################| 9/9
section arch ... |################################| 36/36
section arm ... |################################| 33/33
section ball ... |################################| 6/6
section sphere ... |################################| 16/16
section bar ... |################################| 68/68
section container ... |################################| 101/101
section baseplate ... |################################| 197/197
section electric ... |################################| 811/811
section electric| ... |################################| 1/1
section electric|~ ... |################################| 4/4
"""
__init__.py - Package file for the ldraw Python package.

Copyright (C) 2008 David Boddie <[email protected]>

This file is part of the ldraw Python package.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import hashlib
import imp
import os
import shutil
import sys
import zipfile
from distutils.dir_util import copy_tree
from urllib.request import urlretrieve

from mklist.generate import generate_parts_lst
from pkg_resources import get_distribution, DistributionNotFound

from ldraw.config import get_config, write_config
from ldraw.dirs import get_data_dir, get_config_dir, get_cache_dir
from ldraw.generation.colours import gen_colours
from ldraw.generation.parts import gen_parts
from ldraw.parts import Parts
from ldraw.utils import ensure_exists

try:
    __version__ = get_distribution(__name__).version
except DistributionNotFound:
    # package is not installed
    pass

LDRAW_URL = 'http://www.ldraw.org/library/updates/complete.zip'
LIBRARY_INIT = """\"\"\" the ldraw.library module, auto-generated \"\"\"
__all__ = [\'colours\']
"""


def load_lib_from(fullname, library_dir):
    """ load library from a dir """
    dot_split = fullname.split('.')
    dot_split.pop(0)
    lib_name = dot_split[-1]
    lib_dir = os.path.join(library_dir, *tuple(dot_split[:-1]))
    info = imp.find_module(lib_name, [lib_dir])
    library_module = imp.load_module(lib_name, *info)
    return library_module


def load_lib(library_path, fullname):
    """ try to load from library """
    return load_lib_from(fullname, library_path)


"""
__init__.py - Package file for the ldraw Python package.

Copyright (C) 2008 David Boddie <[email protected]>

This file is part of the ldraw Python package.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import hashlib
import imp
import os
import shutil
import sys
import zipfile
from distutils.dir_util import copy_tree
from urllib.request import urlretrieve

from mklist.generate import generate_parts_lst
from pkg_resources import get_distribution, DistributionNotFound

from ldraw.config import get_config, write_config
from ldraw.dirs import get_data_dir, get_config_dir, get_cache_dir
from ldraw.generation.colours import gen_colours
from ldraw.generation.parts import gen_parts
from ldraw.parts import Parts
from ldraw.utils import ensure_exists

try:
    __version__ = get_distribution(__name__).version
except DistributionNotFound:
    # package is not installed
    pass

LDRAW_URL = 'http://www.ldraw.org/library/updates/complete.zip'
LIBRARY_INIT = """\"\"\" the ldraw.library module, auto-generated \"\"\"
__all__ = [\'colours\']
"""


def load_lib_from(fullname, library_dir):
    """ load library from a dir """
    dot_split = fullname.split('.')
    dot_split.pop(0)
    lib_name = dot_split[-1]
    lib_dir = os.path.join(library_dir, *tuple(dot_split[:-1]))
    info = imp.find_module(lib_name, [lib_dir])
    library_module = imp.load_module(lib_name, *info)
    return library_module


def load_lib(library_path, fullname):
    """ try to load from library """
    return load_lib_from(fullname, library_path)


def try_download_generate_lib():
    # Download the library and generate it, if needed
    config = get_config()
    parts_lst_path = config['parts.lst']
"""
__init__.py - Package file for the ldraw Python package.

Copyright (C) 2008 David Boddie <[email protected]>

This file is part of the ldraw Python package.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import hashlib
import imp
import os
import shutil
import sys
import zipfile
from distutils.dir_util import copy_tree
from urllib.request import urlretrieve

section belville ... |################################| 10/10
section bigfig ... |################################| 8/8
section figure ... |################################| 657/657
"""
__init__.py - Package file for the ldraw Python package.

Copyright (C) 2008 David Boddie <[email protected]>

This file is part of the ldraw Python package.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import hashlib
import imp
import os
import shutil
import sys
import zipfile
from distutils.dir_util import copy_tree
from urllib.request import urlretrieve

from mklist.generate import generate_parts_lst
from pkg_resources import get_distribution, DistributionNotFound

from ldraw.config import get_config, write_config
from ldraw.dirs import get_data_dir, get_config_dir, get_cache_dir
from ldraw.generation.colours import gen_colours
from ldraw.generation.parts import gen_parts
from ldraw.parts import Parts
from ldraw.utils import ensure_exists

try:
    __version__ = get_distribution(__name__).version
except DistributionNotFound:
    # package is not installed
    pass

LDRAW_URL = 'http://www.ldraw.org/library/updates/complete.zip'
LIBRARY_INIT = """\"\"\" the ldraw.library module, auto-generated \"\"\"
__all__ = [\'colours\']
"""


def load_lib_from(fullname, library_dir):
    """ load library from a dir """
    dot_split = fullname.split('.')
    dot_split.pop(0)
    lib_name = dot_split[-1]
    lib_dir = os.path.join(library_dir, *tuple(dot_split[:-1]))
    info = imp.find_module(lib_name, [lib_dir])
    library_module = imp.load_module(lib_name, *info)
    return library_module


def load_lib(library_path, fullname):
    """ try to load from library """
    return load_lib_from(fullname, library_path)


def try_download_generate_lib():
    # Download the library and generate it, if needed
    config = get_config()
section bike ... |################################| 34/34
section vehicle ... |################################| 158/158
section constraction ... |################################| 45/45
section boat ... |################################| 103/103
section bracelet ... |################################| 7/7
section bracket ... |################################| 37/37
section brick ... |################################| 954/954
section magnet ... |################################| 16/16
section bucket ... |################################| 10/10
section || ... |################################| 1/1
generate ldraw.library.colours...
generate ldraw.library.parts, this might take a long time...
section minifig|hats ... |################################| 36/36
section minifig|heads ... |################################| 339/339
section minifig|torsos ... |################################| 498/498
section minifig|legs ... |################################| 122/122
section minifig|arms ... |################################| 22/22
section minifig|hands ... |################################| 11/11
section minifig|accessories ... |################################| 894/894
section minifig| ... |################################| 141/141
section animal ... |################################| 251/251
section antenna ... |################################| 9/9
section arch ... |################################| 36/36
section arm ... |################################| 33/33
section ball ... |################################| 6/6
section sphere ... |################################| 16/16
section bar ... |################################| 68/68
section container ... |################################| 101/101
section baseplate ... |################################| 197/197
section electric ... |################################| 811/811
section electric| ... |################################| 1/1
section electric|~ ... |################################| 4/4
section belville ... |################################| 10/10
section bigfig ... |################################| 8/8
section figure ... |################################| 657/657
section bike ... |################################| 34/34
section vehicle ... |################################| 158/158
section constraction ... |################################| 45/45
section boat ... |################################| 103/103
section bracelet ... |################################| 7/7
section bracket ... |################################| 37/37
section brick ... |################################| 954/954
section magnet ... |################################| 16/16
section bucket ... |################################| 10/10
section || ... |################################| 1/1
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/ldraw/__init__.py", line 84, in try_download_generate_lib
    generate(parts_lst_path, ldraw_path)
  File "/usr/local/lib/python3.8/site-packages/ldraw/__init__.py", line 180, in generate
    gen_parts(parts, output_dir)
  File "/usr/local/lib/python3.8/site-packages/ldraw/generation/parts.py", line 73, in gen_parts
    generate_section(parts, parts_dir, section_name, section_parts)
  File "/usr/local/lib/python3.8/site-packages/ldraw/generation/parts.py", line 120, in generate_section
    write_section_file(parts_dir, parts_list, module_path(section_name))
  File "/usr/local/lib/python3.8/site-packages/ldraw/generation/parts.py", line 33, in write_section_file
    with codecs.open(parts_py, 'w', encoding='utf-8') as generated_file:
  File "/usr/local/Cellar/[email protected]/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 905, in open
    file = builtins.open(filename, mode, buffering)
OSError: [Errno 30] Read-only file system: '//.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/ldr2png", line 5, in <module>
    from ldraw.tools.ldr2png import main
  File "/usr/local/lib/python3.8/site-packages/ldraw/tools/ldr2png.py", line 29, in <module>
    from ldraw.writers.png import PNGWriter, PNGArgs
  File "/usr/local/lib/python3.8/site-packages/ldraw/writers/png.py", line 27, in <module>
    from ldraw.writers.common import Writer
  File "/usr/local/lib/python3.8/site-packages/ldraw/writers/common.py", line 7, in <module>
    from ldraw.library.colours import White, Main_Colour
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
  File "/usr/local/lib/python3.8/site-packages/ldraw/__init__.py", line 152, in load_module
    generated_library_path = try_download_generate_lib()
  File "/usr/local/lib/python3.8/site-packages/ldraw/__init__.py", line 88, in try_download_generate_lib
    generate(parts_lst_path, data_dir)
  File "/usr/local/lib/python3.8/site-packages/ldraw/__init__.py", line 180, in generate
    gen_parts(parts, output_dir)
  File "/usr/local/lib/python3.8/site-packages/ldraw/generation/parts.py", line 73, in gen_parts
    generate_section(parts, parts_dir, section_name, section_parts)
  File "/usr/local/lib/python3.8/site-packages/ldraw/generation/parts.py", line 120, in generate_section
    write_section_file(parts_dir, parts_list, module_path(section_name))
  File "/usr/local/lib/python3.8/site-packages/ldraw/generation/parts.py", line 33, in write_section_file
    with codecs.open(parts_py, 'w', encoding='utf-8') as generated_file:
  File "/usr/local/Cellar/[email protected]/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 905, in open
    file = builtins.open(filename, mode, buffering)
OSError: [Errno 30] Read-only file system: '//.py'

and stuck. Any ideas?

@rienafairefr
Copy link
Owner

issue comes from a unexpectedly named part, https://www.ldraw.org/parts/official-part-lookup.html?folder=parts&partid=t1001c01, which python-ldraw parse with a name starting with |
In https://www.ldraw.org/article/398.html they mention that part names starting with | or |~ is related to third party parts, this is a bug in python-ldraw

@TobitRE
Copy link

TobitRE commented Mar 10, 2021

is there any fix or workaround?
How can I use a older version of the complete.zip?

@rienafairefr
Copy link
Owner

Sorry all, the code has been left kinda unmaintained, I've started to try and fix the problem, there is a separate branch that you might try (rework) but it's still not fixed there. contributions welcome.

@TobitRE
Copy link

TobitRE commented Mar 10, 2021

Hi,
is there an option to define the complete.zip?
I mean that it not be downloaded. So I can use an older version without this change

@rienafairefr
Copy link
Owner

Yes, the complete.zip is just unzipped in a certain directory, then the library is generated from it. might be able to remove the problematic parts from the ldraw ibrary (in ~/.local/share/data or cache, on linux, I think, no idea about other OSes, I'm using appdirs), then remove the generate lib (although it should detect the change and re-generate automatically)

@TobitRE
Copy link

TobitRE commented Mar 10, 2021

i am not familiar with the changes which was made.
can you give me an example which entries are cause the error?
So I can remove the lines in the file and the rest will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants