Debian Codegraph @

wxgeometrie/pylib/infos.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3
4 ##--------------------------------------#######
5 # infos pylib #
6 ##--------------------------------------#######
7 # WxGeometrie
8 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
9 # Copyright (C) 2005-2013 Nicolas Pourcelot
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25 import sys
26 import matplotlib
27 import os
28 import platform
29 import locale
30 import PyQt5.QtCore as qt
31
32 try:
33 # infos.py helps debuging, so should almost never fail.
34 from ..param import NOMPROG, encodage
35 except Exception:
36 NOMPROG = "Logiciel"
37 encodage = "utf8"
38
39 class dossier(object):
40 def __init__(self, titre):
41 self.titre = titre
42
43 def contenu(self):
44 l = []
45 l.append("+ " + self.titre + ":")
46 if hasattr(self, "version"):
47 l.append(" Version: " + self.version)
48 for key in self.__dict__:
49 if key not in ("titre", "version"):
50 content = getattr(self, key)
51 if not isinstance(content, str):
52 if isinstance(content, bytes):
53 content = str(content, encodage, errors="replace")
54 else:
55 # If content isn't a string, specifying encodage raises an error.
56 content = str(content)
57 l.append(" %s: %s" %(key.capitalize(), content))
58 return "\n".join(l) + "\n\n"
59
60
61
62 def informations_configuration():
63 dossier_os = dossier("Systeme")
64 dossier_os.repertoire = os.getcwd()
65 dossier_os.processeur = os.environ.get("PROCESSOR_IDENTIFIER", "?")
66 dossier_os.version = platform.platform().replace("-", " ")
67
68 #TODO (?): parse /proc/cpuinfo and /proc/meminfo if platform is Linux
69
70 if dossier_os.version.startswith("Windows"):
71 dossier_os.distribution = "%s.%s build %s (%s) - %s" %tuple(sys.getwindowsversion())
72 # Il faut convertir en tuple sous Python 2.7
73 elif dossier_os.version.startswith("Linux"):
74 try:
75 f = open("/etc/lsb-release")
76 s = f.read()
77 f.close()
78 dossier_os.distribution = " ".join(elt.split("=")[1] for elt in s.split("\n") if "=" in elt)
79 except IOError:
80 dossier_os.distribution = "?"
81 except Exception:
82 dossier_os.distribution = "#ERREUR#"
83 # os.version = sys.platform
84 # try:
85 # __major__, __minor__, __build__, platform, __text__ = sys.getwindowsversion()
86 # if platform is 0:
87 # platform = "win32s"
88 # elif platform is 1:
89 # platform = "Windows 9x/ME"
90 # elif platform is 2:
91 # platform = "Windows NT/2000/XP"
92 # else:
93 # platform = "Unknown"
94 # os.version += " %s version %s.%s %s build %s" %(platform, __major__, __minor__, __text__, __build__)
95 # except AttributeError:
96 # pass
97 dossier_local = dossier("Localisation")
98 dossier_local.langue = locale.getdefaultlocale()[0]
99 dossier_local.encodage = locale.getpreferredencoding()
100
101 dossier_python = dossier("Python")
102 dossier_python.encodage = sys.getdefaultencoding() + " / Noms de fichiers: " + sys.getfilesystemencoding()
103 dossier_python.version = sys.version
104 dossier_python.executable = sys.executable
105
106 # Pas tres utile :
107 # dossier_python.api = sys.api_version
108 # dossier_python.recursions = sys.getrecursionlimit()
109
110
111
112 dossier_pyqt = dossier("PyQt")
113 dossier_pyqt.portage = "PyQt %s (%s) %s bits" %(qt.PYQT_VERSION_STR, qt.PYQT_VERSION, qt.QSysInfo.WordSize)
114 dossier_pyqt.version = 'Qt %s (%s)' %(qt.QT_VERSION_STR, qt.QT_VERSION)
115
116 dossier_matplotlib = dossier("Matplolib")
117 dossier_matplotlib.version = matplotlib.__version__
118 dossier_matplotlib.tex = matplotlib.rcParams["text.usetex"]
119 if hasattr(matplotlib, "numerix"): # matplotlib <= 0.92
120 dossier_matplotlib.numerix = matplotlib.rcParams["numerix"]
121 dossier_matplotlib.numerix += " (" + matplotlib.numerix.version + ")"
122 else: # matplotlib 0.98+
123 dossier_matplotlib.numerix = "numpy"
124 dossier_matplotlib.numerix += " (" + matplotlib.numpy.__version__ + ")"
125
126 dossier_sympy = dossier("Sympy")
127 try:
128 import sympy
129 dossier_sympy.version = sympy.__version__
130 except:
131 dossier_sympy.version = "?"
132
133
134 dossier_wxgeometrie = dossier(NOMPROG)
135 try:
136 from .. import param
137 dossier_wxgeometrie.version = param.version
138 dossier_wxgeometrie.session = param.ID
139 except Exception:
140 dossier_wxgeometrie.version = "?"
141 dossier_wxgeometrie.session = "?"
142
143 return (dossier_os.contenu() + dossier_local.contenu() + dossier_python.contenu()
144 + dossier_pyqt.contenu() + dossier_matplotlib.contenu()
145 + dossier_sympy.contenu() + dossier_wxgeometrie.contenu())