* Enable compile and link flags to build info also on Windows and in SCons.
[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 def cutPoint(text, length):
29         "Returns position of the last space found before 'length' chars"
30         l = length
31         c = text[l]
32         while c != ' ':
33                 l -= 1
34                 if l == 0: return length # no space found
35                 c = text[l]
36         return l
37
38 def textWrap(text, length = 70):
39         lines = []
40         while len(text) > 70:
41                 cpt = cutPoint(text, length)
42                 line, text = text[:cpt], text[cpt + 1:]
43                 lines.append(line)
44         lines.append(text)
45         return lines
46
47 def write_sysinfo(op):
48         output_filename = "system-info.txt"
49         warnings = 0
50         notices = 0
51
52         if output_filename in bpy.data.texts.keys():
53             output = bpy.data.texts[output_filename]
54             output.clear()
55         else:
56             output = bpy.data.texts.new(name=output_filename)
57
58         header = '= Blender {} System Information =\n'.format(bpy.app.version_string)
59         lilies = '{}\n\n'.format(len(header)*'=')
60         firstlilies = '{}\n'.format(len(header)*'=')
61         output.write(firstlilies)
62         output.write(header)
63         output.write(lilies)
64
65         # build info
66         output.write('\nBlender:\n')
67         output.write(lilies)
68         output.write('version {}, revision {}. {}\n'.format(bpy.app.version_string, bpy.app.build_revision, bpy.app.build_type))
69         output.write('build date: {}, {}\n'.format(bpy.app.build_date, bpy.app.build_time))
70         output.write('platform: {}\n'.format(bpy.app.build_platform))
71         output.write('binary path: {}\n'.format(bpy.app.binary_path))
72         output.write('build cflags: {}\n'.format(bpy.app.build_cflags))
73         output.write('build cxxflags: {}\n'.format(bpy.app.build_cxxflags))
74         output.write('build linkflags: {}\n'.format(bpy.app.build_linkflags))
75         output.write('build system: {}\n'.format(bpy.app.build_system))
76
77         # python info
78         output.write('\nPython:\n')
79         output.write(lilies)
80         output.write('version: {}\n'.format(sys.version))
81         output.write('paths:\n')
82         for p in sys.path:
83             output.write('\t{}\n'.format(p))
84
85         output.write('\nDirectories:\n')
86         output.write(lilies)
87         output.write('scripts: {}\n'.format(bpy.utils.script_paths()))
88         output.write('user scripts: {}\n'.format(bpy.utils.user_script_path()))
89         output.write('datafiles: {}\n'.format(bpy.utils.user_resource('DATAFILES')))
90         output.write('config: {}\n'.format(bpy.utils.user_resource('CONFIG')))
91         output.write('scripts : {}\n'.format(bpy.utils.user_resource('SCRIPTS')))
92         output.write('autosave: {}\n'.format(bpy.utils.user_resource('AUTOSAVE')))
93         output.write('tempdir: {}\n'.format(bpy.app.tempdir))
94
95         output.write('\nOpenGL\n')
96         output.write(lilies)
97         output.write('renderer:\t{}\n'.format(bgl.glGetString(bgl.GL_RENDERER)))
98         output.write('vendor:\t\t{}\n'.format(bgl.glGetString(bgl.GL_VENDOR)))
99         output.write('version:\t{}\n'.format(bgl.glGetString(bgl.GL_VERSION)))
100         output.write('extensions:\n')
101
102         glext = bgl.glGetString(bgl.GL_EXTENSIONS)
103         glext = textWrap(glext, 70)
104         for l in glext:
105             output.write('\t\t{}\n'.format(l))
106         
107         op.report({'INFO'}, "System information generated in 'system-info.txt'")