This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfilmic_blender.py
91 lines (76 loc) · 3.04 KB
/
filmic_blender.py
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
bl_info = {
"name": "Install Filmic Blender",
"description": "A simple add-on that can download and install Filmic Blender",
"author": "Greg Zaal",
"version": (0, 1),
"blender": (2, 78, 0),
"location": "Properties Editor > Scene > Color Management",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Render"}
import bpy
import os
from sys import platform
url = "https://github.com/sobotka/filmic-blender/archive/master.zip"
blender_version = '.'.join(str(n) for n in bpy.app.version[:2])
if platform == 'darwin':
cpath = os.path.join(os.path.abspath(os.path.join(bpy.app.binary_path, '../..')), 'Resources', blender_version, 'datafiles')
else:
cpath = os.path.join(os.path.dirname(bpy.app.binary_path), blender_version, "datafiles")
cmpath = os.path.join(cpath, "colormanagement")
def filmic_is_installed():
# For now just check if readme from github exists. Probably a better way to do this.
check_path = os.path.join(cmpath, 'README.md')
return os.path.exists(check_path)
class FBDownloadFilmic(bpy.types.Operator):
"Download and install Filmic Blender. Restart Blender when it's done"
bl_idname='filmic_blender.get'
bl_label='Get Filmic Blender'
def execute(self,context):
td = bpy.app.tempdir
if not os.path.exists(td):
os.makedirs(td)
from urllib.request import urlretrieve
dfile = os.path.join(td, 'filmic_blender.zip')
try:
urlretrieve(url, dfile)
except:
self.report({'ERROR'}, "Failed to download Filmic Blender, maybe check your internet connection?")
print ("URL:", url, "\nDownload Path:", dfile)
return {'CANCELLED'}
else:
if os.path.exists(cmpath):
opath = os.path.join(cpath, 'colormanagement_old')
i = 1
while os.path.exists(opath):
opath = os.path.join(cpath, 'colormanagement'+'_old'*i)
i += 1
os.rename(cmpath, opath)
import zipfile
zfile = zipfile.ZipFile(dfile)
zfile.extractall(os.path.join(cpath))
zfile.close()
os.rename(os.path.join(cpath, 'filmic-blender-master'), cmpath)
self.report({'INFO'}, "Filmic Blender successfully installed! Now restart Blender")
return {'FINISHED'}
def ui(self, context):
if not filmic_is_installed():
layout = self.layout
box = layout.box()
col = box.column(align=True)
row = col.row()
row.scale_y=1.5
row.alignment = 'CENTER'
row.operator('filmic_blender.get', icon='SEQ_CHROMA_SCOPE')
row = col.row()
row.alignment = 'CENTER'
row.label("Please restart Blender when it's done")
def register():
bpy.utils.register_module(__name__)
bpy.types.SCENE_PT_color_management.prepend(ui)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.SCENE_PT_color_management.remove(ui)
if __name__ == "__main__":
register()