"""
Technical information
"""
"""
qtgui/plugins/TechnicalInfo.py: CCP4MG Molecular Graphics Program
Copyright (C) 2009-2010 University of York
Copyright (C) 2012 STFC
This library is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
version 3, modified in accordance with the provisions of the
license to address the requirements of UK law.
You should have received a copy of the modified GNU Lesser General
Public License along with this library. If not, copies may be
downloaded from http://www.ccp4.ac.uk/ccp4license.php
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
"""
from PyQt4 import QtCore, QtGui
import MGSimpleDialog
import MGApplication
import sys,os
def handleTechDialog(checked=False):
mainwin = MGApplication.GetMainWindow()
if not hasattr(mainwin,"tech_dialog"):
mainwin.tech_dialog = AboutTech(mainwin)
mainwin.tech_dialog.UnClose()
def initializePlugin():
mainwin = MGApplication.GetMainWindow()
if not sys.argv.count('-quit'):
menu_defn = {}
menu_defn['icon'] = 'technicalinfo'
menu_defn['icon_path'] = os.path.normpath(os.path.dirname(__file__))
menu_defn['text'] = "Technical information"
menu_defn["tip"] = "Technical information"
window_item = mainwin.addMenuDefinition(menu_defn['text'],menu_defn,'Tools',draw_menu=False)
window_item.triggered.connect(handleTechDialog)
def getBuildInfo():
text = ""
if os.path.exists(os.path.join(os.environ["CCP4MG"],"lib","TIMESTAMP")):
try:
f = open(os.path.join(os.environ["CCP4MG"],"lib","TIMESTAMP"))
lines = f.readlines()
for l in lines:
text += l + "
"
except:
text = "Unknown"
return text
def getProcessorNameFromRegistry():
try:
import _winreg
reg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
key = _winreg.OpenKey(reg,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0")
for i in range(1024):
try:
name,value,type = _winreg.EnumValue(key,i)
if name == "ProcessorNameString":
return value
except:
pass
_winreg.CloseKey(key)
_winreg.CloseKey(reg)
except:
return ""
return ""
def getSystemInfo():
import platform
system = platform.system()
text = "Platform: "+platform.platform()+"
\n"
if sys.platform == "darwin":
text += "Processor: "+platform.processor()+"
\n"
text += "OS X version: " + platform.mac_ver()[0]+"
\n"
try:
import subprocess
hardinfo = subprocess.Popen(["system_profiler","SPHardwareDataType","-detailLevel","mini"], stdout=subprocess.PIPE).communicate()[0]
dispinfo = subprocess.Popen(["system_profiler","SPDisplaysDataType","-detailLevel","mini"], stdout=subprocess.PIPE).communicate()[0]
except:
hardinfo = ""
dispinfo = ""
if hardinfo.find('Processor Name')>-1 and len(hardinfo[hardinfo.find('Processor Name'):])>16 and hardinfo[hardinfo.find('Processor Name')+16:].find('\n') > -1:
model = hardinfo[hardinfo.find('Processor Name')+16:]
model = model[:model.find('\n')].strip()
speed = ''
if hardinfo.find('Processor Speed')>-1 and len(hardinfo[hardinfo.find('Processor Speed'):])>17 and hardinfo[hardinfo.find('Processor Speed')+17:].find('\n') > -1:
speed = hardinfo[hardinfo.find('Processor Speed')+17:]
speed = speed[:speed.find('\n')].strip()
nproc = 0
if hardinfo.find('Total Number Of Cores')>-1 and len(hardinfo[hardinfo.find('Total Number Of Cores'):])>len('Total Number Of Cores') and hardinfo[hardinfo.find('Total Number Of Cores')+len('Total Number Of Cores'):].find('\n') > -1:
nproc = hardinfo[hardinfo.find('Total Number Of Cores')+len('Total Number Of Cores')+1:]
nproc = nproc[:nproc.find('\n')].strip()
if len(model)>0:
text += "Processor details: "+model
if speed: text += " "+speed
if nproc>0:
text+= ' ('+str(nproc)+' cores available)'
text += "
\n"
text += """
Further information:
(+)
"""
elif sys.platform == "linux2":
text += "Processor: "+platform.processor()+"
\n"
if hasattr(platform,"linux_distribution"):
text += "Linux distribution: " + platform.linux_distribution()[0]+" "+ platform.linux_distribution()[1]+" "+ platform.linux_distribution()[2]+"
\n"
elif hasattr(platform,"dist"):
text += "Linux distribution: " + platform.dist()[0]+" "+ platform.dist()[1]+" "+ platform.dist()[2]+"
"
try:
import subprocess
cpuinfo = subprocess.Popen(["cat","/proc/cpuinfo"], stdout=subprocess.PIPE).communicate()[0]
meminfo = subprocess.Popen(["cat","/proc/meminfo"], stdout=subprocess.PIPE).communicate()[0]
except:
cpuinfo = ''
meminfo = ''
if cpuinfo.find('model name')>-1 and len(cpuinfo[cpuinfo.find('model name'):])>12 and cpuinfo[cpuinfo.find('model name')+12:].find('\n') > -1:
model = cpuinfo[cpuinfo.find('model name')+12:]
model = model[:model.find('\n')].strip()
nproc = cpuinfo.count('\nmodel name\t')
if len(model)>0:
text += "Processor details: "+model
if nproc>0:
text+= ' ('+str(nproc)+' processors available)'
text += "
\n"
text += """
Further information:
(+)
"""
elif sys.platform == "win32":
text += "Processor Name: "+getProcessorNameFromRegistry()
if os.environ.has_key("NUMBER_OF_PROCESSORS"):
text+= " ("+os.environ["NUMBER_OF_PROCESSORS"]+" processors available)"
text += "
\n"
text += "Processor details: "+platform.processor()+"
\n"
text += "Windows version: " + platform.win32_ver()[0]+" "+ platform.win32_ver()[1]+" "+ platform.win32_ver()[2]+"
\n"
else:
text += "Processor: "+platform.processor()+"
\n"
return text
def getOtherInfo():
text = ''
text += "Qt version: "+QtCore.QT_VERSION_STR+"
\n"
text += "PyQt4 version: "+QtCore.PYQT_VERSION_STR+"
\n"
text += "Python version: "+sys.version+"
\n"
return text
def getGLInfo():
text = ""
mainwin = MGApplication.GetMainWindow()
try:
import glShaders
shaderVersion = glShaders.MGGLShader.getShadingLanguageVersion()
except:
shaderVersion = "OpenGL shaders not available"
if hasattr(mainwin,"glWidget") and mainwin.glWidget.isValid():
mainwin.glWidget.makeCurrent()
import opengl
text += "Direct rendering: "+str(mainwin.glWidget.context().format().directRendering())+"
"
text += "GL vendor: "+opengl.glGetString(opengl.GL_VENDOR)+"
"
text += "GL renderer: "+opengl.glGetString(opengl.GL_RENDERER)+"
"
text += "GL version: "+opengl.glGetString(opengl.GL_VERSION)+"
"
text += "GL shader version: "+shaderVersion+"
"
text += "GL extensions: "
text += """
(+)
"""
return text
class AboutTech(MGSimpleDialog.MGSimpleDialog):
def UnClose(self):
label_text = self.getLabelText()
self.label.setHtml(label_text)
MGSimpleDialog.MGSimpleDialog.UnClose(self)
def getLabelText (self):
label_text = """