64ff1c0f007d34f884495296e5978b3f93be690c
[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 import bpy
24 import bgl
25
26 import sys
27
28
29 def cutPoint(text, length):
30     "Returns position of the last space found before 'length' chars"
31     l = length
32     c = text[l]
33     while c != ' ':
34         l -= 1
35         if l == 0:
36             return length  # no space found
37         c = text[l]
38     return l
39
40
41 def textWrap(text, length=70):
42     lines = []
43     while len(text) > 70:
44         cpt = cutPoint(text, length)
45         line, text = text[:cpt], text[cpt + 1:]
46         lines.append(line)
47     lines.append(text)
48     return lines
49
50
51 def write_sysinfo(op):
52     output_filename = "system-info.txt"
53
54     output = bpy.data.texts.get(output_filename)
55     if output:
56         output.clear()
57     else:
58         output = bpy.data.texts.new(name=output_filename)
59
60     header = '= Blender {} System Information =\n'.format(bpy.app.version_string)
61     lilies = '{}\n\n'.format(len(header) * '=')
62     firstlilies = '{}\n'.format(len(header) * '=')
63     output.write(firstlilies)
64     output.write(header)
65     output.write(lilies)
66
67     # build info
68     output.write('\nBlender:\n')
69     output.write(lilies)
70     output.write('version {}, revision {}. {}\n'.format(bpy.app.version_string, bpy.app.build_revision, bpy.app.build_type))
71     output.write('build date: {}, {}\n'.format(bpy.app.build_date, bpy.app.build_time))
72     output.write('platform: {}\n'.format(bpy.app.build_platform))
73     output.write('binary path: {}\n'.format(bpy.app.binary_path))
74     output.write('build cflags: {}\n'.format(bpy.app.build_cflags))
75     output.write('build cxxflags: {}\n'.format(bpy.app.build_cxxflags))
76     output.write('build linkflags: {}\n'.format(bpy.app.build_linkflags))
77     output.write('build system: {}\n'.format(bpy.app.build_system))
78
79     # python info
80     output.write('\nPython:\n')
81     output.write(lilies)
82     output.write('version: {}\n'.format(sys.version))
83     output.write('paths:\n')
84     for p in sys.path:
85         output.write('\t{}\n'.format(p))
86
87     output.write('\nDirectories:\n')
88     output.write(lilies)
89     output.write('scripts: {}\n'.format(bpy.utils.script_paths()))
90     output.write('user scripts: {}\n'.format(bpy.utils.user_script_path()))
91     output.write('datafiles: {}\n'.format(bpy.utils.user_resource('DATAFILES')))
92     output.write('config: {}\n'.format(bpy.utils.user_resource('CONFIG')))
93     output.write('scripts : {}\n'.format(bpy.utils.user_resource('SCRIPTS')))
94     output.write('autosave: {}\n'.format(bpy.utils.user_resource('AUTOSAVE')))
95     output.write('tempdir: {}\n'.format(bpy.app.tempdir))
96
97     output.write('\nFFmpeg:\n')
98     output.write(lilies)
99     ffmpeg = bpy.app.ffmpeg
100     if ffmpeg.supported:
101         for lib in ['avcodec', 'avdevice', 'avformat', 'avutil', 'swscale']:
102             output.write('{}:{}{}\n'.format(lib, " "*(10-len(lib)),
103                          getattr(ffmpeg, lib + '_version_string')))
104     else:
105         output.write('Blender was built without FFmpeg support\n')
106
107     if bpy.app.background:
108         output.write('\nOpenGL: missing, background mode\n')
109     else:
110         output.write('\nOpenGL\n')
111         output.write(lilies)
112         output.write('renderer:\t{}\n'.format(bgl.glGetString(bgl.GL_RENDERER)))
113         output.write('vendor:\t\t{}\n'.format(bgl.glGetString(bgl.GL_VENDOR)))
114         output.write('version:\t{}\n'.format(bgl.glGetString(bgl.GL_VERSION)))
115         output.write('extensions:\n')
116
117         glext = bgl.glGetString(bgl.GL_EXTENSIONS)
118         glext = textWrap(glext, 70)
119         for l in glext:
120             output.write('\t\t{}\n'.format(l))
121
122     op.report({'INFO'}, "System information generated in 'system-info.txt'")