Page MenuHome

bam pack with -m FILE fails on copying deeper hierachies because of missing destination folders
Closed, ResolvedPublic

Description

I just right now installed blender-bam through pip3, so the following should apply to the latest published version:

Given the following file structure:
(...)/scene.blend
(...)/textures/HDRI/Outdoor/Rocky Ridge-4k.hdr

Inside (...)/ I run:

bam pack -o foo/scene.blend -m FILE scene.blend

Which produces (BAM!):

scanning deps: b'/home/user/project/scene.blend'...
  blend:       b'/home/user/project/scene.blend'

archiving: 2 files
  copying: b'/home/user/project/textures/HDRI/Outdoor/Rocky Ridge-4k.hdr' -> b'/home/user/project/foo/textures/HDRI/Outdoor/Rocky Ridge-4k.hdr'
Traceback (most recent call last):
  File "/usr/local/bin/bam", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/bam/__init__.py", line 8, in main
    sys.exit(main(argv[1:]))
  File "/usr/local/lib/python3.5/dist-packages/bam/cli.py", line 2003, in main
    args.func(args)
  File "/usr/local/lib/python3.5/dist-packages/bam/cli.py", line 1797, in <lambda>
    filename_filter=args.exclude,
  File "/usr/local/lib/python3.5/dist-packages/bam/cli.py", line 1386, in pack
    filename_filter=filename_filter,
  File "/usr/local/lib/python3.5/dist-packages/bam/blend/blendfile_pack.py", line 502, in pack
    shutil.copy(src, dst)
  File "/usr/lib/python3.5/shutil.py", line 235, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.5/shutil.py", line 115, in copyfile
    with open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: b'/home/user/project/foo/textures/HDRI/Outdoor/Rocky Ridge-4k.hdr'

This is the affected line ( "/usr/local/lib/python3.5/dist-packages/bam/blend/blendfile_pack.py", line 502) and surrounding block:

        for src, dst in path_copy_files:
            assert(b'.blend' not in dst)

            # in rare cases a filepath could point to a directory
            if (not os.path.exists(src)) or os.path.isdir(src):
                yield report("  %s: %r\n" % (colorize("source missing", color='red'), src))
            else:
                yield report("  %s: %r -> %r\n" % (colorize("copying", color='blue'), src, dst))
--------------> shutil.copy(src, dst)

To me this looks like the target folder structure foo/textures/HDRI/Outdoor/ into which Rocky Ridge-4k.hdr should go is non-existent, while shutil.copy requires it to exist (it doesn't create it automatically).

Possible solution: os.path.exists and os.makedirs to the rescue?

I'll supply a localized patch myself if you wish so, but in case this issue lies dormant all over the place also elsewhere in bam, this probably should be adressed by you as the masterminds behind it. :)

Thanks! Looking forward to smooth bam operation after this fix :)

Event Timeline

Super cool, already tested a few scenarios - works! Merci Bastien!

Any outlook when the pip package gets updated? (for the moment i just applied the patch locally)