Cleanup: pep8
[blender-staging.git] / release / scripts / modules / sys_info.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 # classes for extracting info from blenders internal classes
22
23
24 def write_sysinfo(filepath):
25     import sys
26
27     import textwrap
28     import subprocess
29
30     import bpy
31     import bgl
32
33     # pretty repr
34     def prepr(v):
35         r = repr(v)
36         vt = type(v)
37         if vt is bytes:
38             r = r[2:-1]
39         elif vt is list or vt is tuple:
40             r = r[1:-1]
41         return r
42
43     output = open(filepath, 'w', encoding="utf-8")
44
45     header = "= Blender %s System Information =\n" % bpy.app.version_string
46     lilies = "%s\n\n" % ((len(header) - 1) * "=")
47     output.write(lilies[:-1])
48     output.write(header)
49     output.write(lilies)
50
51     def title(text):
52         return "\n%s:\n%s" % (text, lilies)
53
54     # build info
55     output.write(title("Blender"))
56     output.write("version: %s, branch: %s, commit date: %s %s, hash: %s, type: %s\n" %
57         (bpy.app.version_string,
58          prepr(bpy.app.build_branch),
59          prepr(bpy.app.build_commit_date),
60          prepr(bpy.app.build_commit_time),
61          prepr(bpy.app.build_hash),
62          prepr(bpy.app.build_type),
63          ))
64
65     output.write("build date: %s, %s\n" % (prepr(bpy.app.build_date), prepr(bpy.app.build_time)))
66     output.write("platform: %s\n" % prepr(bpy.app.build_platform))
67     output.write("binary path: %s\n" % prepr(bpy.app.binary_path))
68     output.write("build cflags: %s\n" % prepr(bpy.app.build_cflags))
69     output.write("build cxxflags: %s\n" % prepr(bpy.app.build_cxxflags))
70     output.write("build linkflags: %s\n" % prepr(bpy.app.build_linkflags))
71     output.write("build system: %s\n" % prepr(bpy.app.build_system))
72
73     # python info
74     output.write(title("Python"))
75     output.write("version: %s\n" % (sys.version))
76     output.write("paths:\n")
77     for p in sys.path:
78         output.write("\t%r\n" % p)
79
80     output.write(title("Python (External Binary)"))
81     output.write("binary path: %s\n" % prepr(bpy.app.binary_path_python))
82     try:
83         py_ver = prepr(subprocess.check_output([
84                 bpy.app.binary_path_python,
85                 "--version",
86                 ]).strip())
87     except Exception as e:
88         py_ver = str(e)
89     output.write("version: %s\n" % py_ver)
90     del py_ver
91
92     output.write(title("Directories"))
93     output.write("scripts:\n")
94     for p in bpy.utils.script_paths():
95         output.write("\t%r\n" % p)
96     output.write("user scripts: %r\n" % (bpy.utils.script_path_user()))
97     output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref()))
98     output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES')))
99     output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG')))
100     output.write("scripts : %r\n" % (bpy.utils.user_resource('SCRIPTS')))
101     output.write("autosave: %r\n" % (bpy.utils.user_resource('AUTOSAVE')))
102     output.write("tempdir: %r\n" % (bpy.app.tempdir))
103
104     output.write(title("FFmpeg"))
105     ffmpeg = bpy.app.ffmpeg
106     if ffmpeg.supported:
107         for lib in ("avcodec", "avdevice", "avformat", "avutil", "swscale"):
108             output.write("%s:%s%r\n" % (lib, " " * (10 - len(lib)),
109                          getattr(ffmpeg, lib + "_version_string")))
110     else:
111         output.write("Blender was built without FFmpeg support\n")
112
113     if bpy.app.build_options.sdl:
114         output.write(title("SDL"))
115         output.write("Version: %s\n" % bpy.app.sdl.version_string)
116         output.write("Loading method: ")
117         if bpy.app.build_options.sdl_dynload:
118             output.write("dynamically loaded by Blender (WITH_SDL_DYNLOAD=ON)\n")
119         else:
120             output.write("linked (WITH_SDL_DYNLOAD=OFF)\n")
121         if not bpy.app.sdl.available:
122             output.write("WARNING: Blender could not load SDL library\n")
123
124     output.write(title("Other Libraries"))
125     ocio = bpy.app.ocio
126     output.write("OpenColorIO: ")
127     if ocio.supported:
128         if ocio.version_string == "fallback":
129             output.write("Blender was built with OpenColorIO, " +
130                          "but it currently uses fallback color management.\n")
131         else:
132             output.write("%s\n" % (ocio.version_string))
133     else:
134         output.write("Blender was built without OpenColorIO support\n")
135
136     oiio = bpy.app.oiio
137     output.write("OpenImageIO: ")
138     if ocio.supported:
139         output.write("%s\n" % (oiio.version_string))
140     else:
141         output.write("Blender was built without OpenImageIO support\n")
142
143     output.write("OpenShadingLanguage: ")
144     if bpy.app.build_options.cycles:
145         if bpy.app.build_options.cycles_osl:
146             from _cycles import osl_version_string
147             output.write("%s\n" % (osl_version_string))
148         else:
149             output.write("Blender was built without OpenShadingLanguage support in Cycles\n")
150     else:
151         output.write("Blender was built without Cycles support\n")
152
153     openvdb = bpy.app.openvdb
154     output.write("OpenVDB: ")
155     if openvdb.supported:
156         output.write("%s\n" % openvdb.version_string)
157     else:
158         output.write("Blender was built without OpenVDB support\n")
159
160     if not bpy.app.build_options.sdl:
161         output.write("SDL: Blender was built without SDL support\n")
162
163     if bpy.app.background:
164         output.write("\nOpenGL: missing, background mode\n")
165     else:
166         output.write(title("OpenGL"))
167         version = bgl.glGetString(bgl.GL_RENDERER)
168         output.write("renderer:\t%r\n" % version)
169         output.write("vendor:\t\t%r\n" % (bgl.glGetString(bgl.GL_VENDOR)))
170         output.write("version:\t%r\n" % (bgl.glGetString(bgl.GL_VERSION)))
171         output.write("extensions:\n")
172
173         glext = sorted(bgl.glGetString(bgl.GL_EXTENSIONS).split())
174         for l in glext:
175             output.write("\t%s\n" % l)
176
177         output.write(title("Implementation Dependent OpenGL Limits"))
178         limit = bgl.Buffer(bgl.GL_INT, 1)
179         bgl.glGetIntegerv(bgl.GL_MAX_TEXTURE_UNITS, limit)
180         output.write("Maximum Fixed Function Texture Units:\t%d\n" % limit[0])
181         bgl.glGetIntegerv(bgl.GL_MAX_ELEMENTS_VERTICES, limit)
182         output.write("Maximum DrawElements Vertices:\t%d\n" % limit[0])
183         bgl.glGetIntegerv(bgl.GL_MAX_ELEMENTS_INDICES, limit)
184         output.write("Maximum DrawElements Indices:\t%d\n" % limit[0])
185
186         output.write("\nGLSL:\n")
187         bgl.glGetIntegerv(bgl.GL_MAX_VARYING_FLOATS, limit)
188         output.write("Maximum Varying Floats:\t%d\n" % limit[0])
189         bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_ATTRIBS, limit)
190         output.write("Maximum Vertex Attributes:\t%d\n" % limit[0])
191         bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_UNIFORM_COMPONENTS, limit)
192         output.write("Maximum Vertex Uniform Components:\t%d\n" % limit[0])
193         bgl.glGetIntegerv(bgl.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, limit)
194         output.write("Maximum Fragment Uniform Components:\t%d\n" % limit[0])
195         bgl.glGetIntegerv(bgl.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, limit)
196         output.write("Maximum Vertex Image Units:\t%d\n" % limit[0])
197         bgl.glGetIntegerv(bgl.GL_MAX_TEXTURE_IMAGE_UNITS, limit)
198         output.write("Maximum Fragment Image Units:\t%d\n" % limit[0])
199         bgl.glGetIntegerv(bgl.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, limit)
200         output.write("Maximum Pipeline Image Units:\t%d\n" % limit[0])
201
202     if bpy.app.build_options.cycles:
203         import cycles
204         output.write(title("Cycles"))
205         output.write(cycles.engine.system_info())
206
207     output.close()
208