[Bf-extensions-cvs] [6e38b996] master: Unpacked BAM wheel into a directory.

Sybren A. Stüvel noreply at git.blender.org
Sat Jun 10 10:56:11 CEST 2017


Commit: 6e38b99641004ed1ef1f87c937750e8774a37c50
Author: Sybren A. Stüvel
Date:   Sat Jun 10 10:42:03 2017 +0200
Branches: master
https://developer.blender.org/rBA6e38b99641004ed1ef1f87c937750e8774a37c50

Unpacked BAM wheel into a directory.

This avoids having binary data in the addons repository. I've
also added a script that automates this task. It:

- wipes any pre-existing unpacked BAM wheel,
- unpacks the new BAM wheel,
- copies some files from the extracted wheel into the addon
  directly,
- updates the version number of the add-on so that it matches
  the version of BAM, and
- updates the path where the add-on searches for the unpacked
  wheel.

===================================================================

M	io_blend_utils/README.md
M	io_blend_utils/__init__.py
D	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__init__.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__main__.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/__init__.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile_copy.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile_pack.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile_pack_restore.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile_path_remap.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile_path_walker.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/cli.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/pack.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/utils/__init__.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/utils/system.py
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/DESCRIPTION.rst
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/METADATA
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/RECORD
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/WHEEL
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/entry_points.txt
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/metadata.json
A	io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/blender_bam-1.1.7.dist-info/top_level.txt
A	io_blend_utils/install_whl.py

===================================================================

diff --git a/io_blend_utils/README.md b/io_blend_utils/README.md
index 436ec684..e3f3b0a0 100644
--- a/io_blend_utils/README.md
+++ b/io_blend_utils/README.md
@@ -10,17 +10,23 @@ Bundling BAM with Blender
 -------------------------
 
 Blender is bundled with a version of [BAM](https://pypi.python.org/pypi/blender-bam/).
-To update this version, first build a new `wheel <http://pythonwheels.com/>`_ file in
+To update this version, first build a new [wheel](http://pythonwheels.com/) file in
 BAM itself:
 
     python3 setup.py bdist_wheel
 
-Then copy this wheel to Blender:
+Since we do not want to have binaries in the addons repository, unpack this wheel to Blender
+by running:
 
-    cp dist/blender_bam-xxx.whl /path/to/blender/release/scripts/addons/io_blend_utils/
+    python3 install_whl.py /path/to/blender-asset-manager/dist/blender_bam-xxx.whl
 
-Remove old wheels that are still in `/path/to/blender/release/scripts/addons/io_blend_utils/`
-before committing.
+This script also updates `__init__.py` to update the version number and path of the extracted
+wheel, and removes any pre-existing older versions of the BAM wheels.
+
+The version number and `.whl` extension are maintained in the directory name on purpose.
+This way it is clear that it is not a directory to import directly into Blender itself.
+Furthermore, I (Sybren) hope that it helps to get changes made in the addons repository
+back into the BAM repository.
 
 
 Running bam-pack from the wheel
@@ -29,4 +35,3 @@ Running bam-pack from the wheel
 This is the way that Blender runs bam-pack:
 
     PYTHONPATH=./path/to/blender_bam-xxx.whl python3 -m bam.pack
-
diff --git a/io_blend_utils/__init__.py b/io_blend_utils/__init__.py
index a00366ac..03cae55c 100644
--- a/io_blend_utils/__init__.py
+++ b/io_blend_utils/__init__.py
@@ -29,7 +29,7 @@ bl_info = {
     "category": "Import-Export",
 }
 
-BAM_WHEEL_FILE = 'blender_bam-1.1.7-py3-none-any.whl'
+BAM_WHEEL_PATH = 'blender_bam-1.1.7-py3-none-any.whl'
 
 import logging
 
@@ -117,11 +117,11 @@ def pythonpath() -> str:
     log = logging.getLogger('%s.pythonpath' % __name__)
 
     # Find the wheel to run.
-    wheelpath = pathlib.Path(__file__).with_name(BAM_WHEEL_FILE)
+    wheelpath = pathlib.Path(__file__).with_name(BAM_WHEEL_PATH)
     if not wheelpath.exists():
-        raise EnvironmentError('Wheel file %s does not exist!' % wheelpath)
+        raise EnvironmentError('Wheel %s does not exist!' % wheelpath)
 
-    log.info('Using wheel file %s to run BAM-Pack', wheelpath)
+    log.info('Using wheel %s to run BAM-Pack', wheelpath)
 
     # Update the PYTHONPATH to include that wheel.
     existing_pypath = os.environ.get('PYTHONPATH', '')
diff --git a/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl
deleted file mode 100644
index 72fad694..00000000
Binary files a/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl and /dev/null differ
diff --git a/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__init__.py b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__init__.py
new file mode 100644
index 00000000..cd0a5014
--- /dev/null
+++ b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__init__.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+__version__ = '1.1.7'
+
+if __name__ == '__main__':
+    from .cli import main
+
+    main()
diff --git a/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__main__.py b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__main__.py
new file mode 100644
index 00000000..c5f166b0
--- /dev/null
+++ b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/__main__.py
@@ -0,0 +1,8 @@
+"""Main module for running python -m bam.
+
+Doesn't do much, except for printing general usage information.
+"""
+
+print("The 'bam' module cannot be run directly. The following subcommand is available:")
+print()
+print("python -m bam.pack")
diff --git a/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/__init__.py b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile.py b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile.py
new file mode 100644
index 00000000..e471beae
--- /dev/null
+++ b/io_blend_utils/blender_bam-1.1.7-py3-none-any.whl/bam/blend/blendfile.py
@@ -0,0 +1,956 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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 2
+# 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, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+#
+# (c) 2009, At Mind B.V. - Jeroen Bakker
+# (c) 2014, Blender Foundation - Campbell Barton
+
+import gzip
+import logging
+import os
+import struct
+import tempfile
+
+log = logging.getLogger("blendfile")
+
+FILE_BUFFER_SIZE = 1024 * 1024
+
+
+class BlendFileError(Exception):
+    """Raised when there was an error reading/parsing a blend file."""
+
+
+# -----------------------------------------------------------------------------
+# module global routines
+#
+# read routines
+# open a filename
+# determine if the file is compressed
+# and returns a handle
+def open_blend(filename, access="rb"):
+    """Opens a blend file for reading or writing pending on the access
+    supports 2 kind of blend files. Uncompressed and compressed.
+    Known issue: does not support packaged blend files
+    """
+    handle = open(filename, access)
+    magic_test = b"BLENDER"
+    magic = handle.read(len(magic_test))
+    if magic == magic_test:
+        log.debug("normal blendfile detected")
+        handle.seek(0, os.SEEK_SET)
+        bfile = BlendFile(handle)
+        bfile.is_compressed = False
+        bfile.filepath_orig = filename
+        return bfile
+    elif magic[:2] == b'\x1f\x8b':
+        log.debug("gzip blendfile detected")
+        handle.close()
+        log.debug("decompressing started")
+        fs = gzip.open(filename, "rb")
+        data = fs.read(FILE_BUFFER_SIZE)
+        magic = data[:len(magic_test)]
+        if magic == magic_test:
+            handle = tempfile.TemporaryFile()
+            while data:
+                handle.write(data)
+                data = fs.read(FILE_BUFFER_SIZE)
+            log.debug("decompressing finished")
+            fs.close()
+            log.debug("resetting decompressed file")
+            handle.seek(os.SEEK_SET, 0)
+            bfile = BlendFile(handle)
+            bfile.is_compressed = True
+            bfile.filepath_orig = filename
+            return bfile
+        else:
+            raise BlendFileError("filetype inside gzip not a blend")
+    else:
+        raise BlendFileError("filetype not a blend or a gzip blend")
+
+
+def pad_up_4(offset):
+    return (offset + 3) & ~3
+
+
+# -----------------------------------------------------------------------------
+# module classes
+
+
+class BlendFile:
+    """
+    Blend file.
+    """
+    __slots__ = (
+        # file (result of open())
+        "handle",
+        # str (original name of the file path)
+        "filepath_orig",
+        # BlendFileHeader
+        "header",
+        # struct.Struct
+        "block_header_struct",
+        # BlendFileBlock
+        "blocks",
+        # [DNAStruct, ...]
+        "structs",
+        # dict {b'StructName': sdna_index}
+        # (where the index is an index into 'structs')
+        "sdna_index_from_id",
+        # dict {addr_old: block}
+        "block_from_offset",
+        # int
+        "code_index",
+        # bool (did we make a change)
+        "is_modified",
+        # bool (is file gzipped)
+        "is_compressed",
+        )
+
+    def __init__(self, handle):
+        log.debug("initializing reading blend-file")
+        self.handle = handle
+        self.header = BlendFileHeader(handle)
+        self.block_header_struct = self.header.create_block_header_struct()
+        self.blocks = []
+        self.code_index = {}
+        self.structs = []
+        self.sdna_index_from_id = {}
+
+        block = BlendFileBlock(handle, self)
+        while block.code != b'ENDB':
+            if block.code == b'DNA1':
+                (self.structs,
+                 self.sdna_index_from_id,
+                 ) = BlendFile.decode_structs(self.header, block, handle)
+            else:
+                handle.seek(block.size, os.SEEK_CUR)
+
+            self.blocks.append(block)
+            self.code_index.setdefault(block.code, []).append(block)
+
+            block = BlendFileBlock(handle, self)
+        self.is_modified = False
+        self.blocks.append(block)
+
+        if not self.structs:
+            raise BlendFileError("No DNA1 block in file, this is not a valid .blend file!")
+
+        # cache (could lazy init, incase we never use?)
+        self.block_from_offset = {block.addr_old: block for block in self.blocks if block.code != b'ENDB'}
+
+    def __repr__(self):
+        return '<%s %r>' % (self.__class__.__qualname__, self.handle)
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, type, value, traceback):
+        self.close()
+
+    def find_blocks_from_code(self, code):
+        assert(type(code) == bytes)
+        if code not in self.code_index:
+            return []
+        return self.code_index[code]
+
+    def find_block_from_offset(self, offset):
+        # same as looking looping over all blocks,
+        # then checking ``block.addr_old == offset``
+        assert(type(offset) is int)
+        return self.block_from_offset.get(offset)
+
+    def close(self):
+        """
+        Close the blend file
+        writes the blend f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list