Welcome to mirror list, hosted at ThFree Co, Russian Federation.

__init__.py « io_blend_utils - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: adbd2d041cbce2eca9fd0f72e148c1bf6a53070d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# ***** 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 *****

bl_info = {
    "name": "Blend File Utils",
    "author": "Campbell Barton",
    "version": (0, 1),
    "blender": (2, 76, 0),
    "location": "File > External Data > Blend Utils",
    "description": "Utility for packing blend files",
    "warning": "",
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/BlendFile_Utils",
    "support": 'OFFICIAL',
    "category": "Import-Export",
    }


import bpy
from bpy.types import Operator
from bpy_extras.io_utils import ExportHelper

from .bl_utils.subprocess_helper import SubprocessHelper


class ExportBlendPack(Operator, ExportHelper, SubprocessHelper):
    """Packs a blend file and all its dependencies into an archive for easy redistribution"""
    bl_idname = "export_blend.pack"
    bl_label = "Pack Blend to Archive"

    # ExportHelper
    filename_ext = ".zip"

    # SubprocessHelper
    report_interval = 0.25

    temp_dir = None

    @classmethod
    def poll(cls, context):
        return bpy.data.is_saved

    def process_pre(self):
        import os
        import tempfile

        self.temp_dir = tempfile.TemporaryDirectory()

        filepath_blend = bpy.data.filepath

        self.command = (
            bpy.app.binary_path_python,
            os.path.join(os.path.dirname(__file__), "blendfile_pack.py"),
            # file to pack
            "--input", filepath_blend,
            # file to write
            "--output", bpy.path.ensure_ext(self.filepath, ".zip"),
            "--temp", self.temp_dir.name,
            )

    def process_post(self, returncode):
        if self.temp_dir is not None:
            try:
                self.temp_dir.cleanup()
            except:
                import traceback
                traceback.print_exc()


def menu_func(self, context):
    layout = self.layout
    layout.separator()
    layout.operator(ExportBlendPack.bl_idname)


classes = (
    ExportBlendPack,
    )


def register():
    for cls in classes:
        bpy.utils.register_class(cls)

    bpy.types.INFO_MT_file_external_data.append(menu_func)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)

    bpy.types.INFO_MT_file_external_data.remove(menu_func)


if __name__ == "__main__":
    register()