PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wxgeometrie/pylib/infos.py

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