rendered paste body__module_name__ = "X-Chat Sysinfo Script"
__module_version__ = "1.3"
__module_description__ = "Prints system info"
__module_author__ = "Martin Mortensen <loke@totalirc.net>"
"""
Copyright (C) 2005 Martin Mortensen <loke@totalirc.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import xchat
import string
import commands
import os
import decimal
def exists(location):
check = os.path.exists(location)
return check
def system_info(word, word_eol, userdata):
# Dist #
checkp = 0
if (exists("/etc/SuSE-release")):
dist = open("/etc/SuSE-release")
elif (exists("/etc/gentoo-release")):
dist = open("/etc/gentoo-release")
elif (exists("/etc/debian_version")): # Debian only shows version number
dist = open("/etc/debian_version")
dist = dist.read( )
dist = string.split(dist, "\n")
dist = "Debian GNU/Linux "+dist[0]
checkp = 1
elif (exists("/etc/debian_release")):
dist = open("/etc/debian_release")
dist = dist.read( )
dist = string.split(dist, "\n")
dist = "Debian GNU/Linux "+dist[0]
checkp = 1
elif (exists("/etc/fedora-release")):
dist = open("/etc/fedora-release")
elif (exists("/etc/mandrake-release")):
dist = open("/etc/mandrake-release")
elif (exists("/etc/slackware-release")):
dist = open("/etc/slackware-release")
elif (exists("/etc/arch-release")):
dist = open("/etc/arch-release")
elif (exists("/etc/centos-release")):
dist = open("/etc/centos-release")
elif (exists("/etc/yellowdog-release")):
dist = open("/etc/yellowdog-release")
elif (exists("/etc/lfs-release")):
dist = open("/etc/lfs-release")
elif (exists("/etc/pld-release")):
dist = open("/etc/pld-release")
elif (exists("/etc/aurox-release")):
dist = open("/etc/aurox-release")
elif (exists("/etc/connectiva-release")):
dist = open("/etc/connectiva-release")
elif (exists("/etc/turbolinux-release")):
dist = open("/etc/turbolinux-release")
elif (exists("/etc/redhat-release")):
dist = open("/etc/redhat-release")
else:
print "[Unknown Distro]"
if (checkp == 0):
dist = dist.read( )
dist = string.split(dist, "\n")
dist = dist[0]
dist.rstrip(os.linesep)
# Uname #
uname = commands.getoutput("/bin/uname -sr")
uname.rstrip(os.linesep)
# Cpuinfo #
getcpu = commands.getoutput("cat /proc/cpuinfo | grep name")
getcpu = string.split(getcpu, "\n")
i = 0
for item in getcpu:
i = i + 1
getcpu = string.split(getcpu[0], ":")
getcpu = getcpu[1][1:]
getcpu.rstrip(os.linesep)
if (i > 1):
cpuinfo = str(i)+" x "+getcpu
else:
cpuinfo = getcpu
# Cpu speed #
getspeed = commands.getoutput("cat /proc/cpuinfo | grep MHz")
getspeed = string.split(getspeed, "\n")
getspeed = string.split(getspeed[0])
getspeed = getspeed[3]
getspeed.rstrip(os.linesep)
getspeed = float(getspeed)
getspeed = getspeed / 1000
getspeed = round(getspeed, 2)
getspeed = str(getspeed)+"GHz"
# Bogomips #
getbogo = commands.getoutput("cat /proc/cpuinfo | grep bogomips")
getbogo = string.split(getbogo, "\n")
i = 0
for item in getbogo:
i = i+1
bogo1 = getbogo[0]
bogo1 = string.split(bogo1)
bogo1 = bogo1[2]
if (i == 2):
bogo1 = float(bogo1)
bogo2 = getbogo[1]
bogo2 = string.split(bogo2)
bogo2 = bogo2[2]
bogo1 = float(bogo1)
bogo2 = float(bogo2)
getbogo = bogo1+bogo2
getbogo = str(getbogo)
else:
getbogo = bogo1
# End bogomips #
# Memoryinfo #
getmem = commands.getoutput("cat /proc/meminfo | grep MemTotal")
getmem = string.split(getmem)
getmem = getmem[1]
getmem.rstrip(os.linesep)
getmem = int(getmem)
getmem = getmem / 1024
getmem = str(getmem)
freemem = commands.getoutput("cat /proc/meminfo | grep MemFree")
freemem = string.split(freemem)
freemem = freemem[1]
freemem.rstrip(os.linesep)
freemem = int(freemem)
freemem = freemem / 1024
memtotal = commands.getoutput("cat /proc/meminfo | grep MemTotal")
memtotal = string.split(memtotal)
memtotal = memtotal[1]
memtotal.rstrip(os.linesep)
memtotal = int(memtotal)
memtotal = memtotal / 1024
usedmem = memtotal - freemem
usedmem = str(usedmem)
# End memoryinfo #
# Videocard #
# if (exists("/sbin/lspci")):
# getvideo = commands.getoutput("/sbin/lspci | grep VGA")
#
# elif (exists("/bin/lspci")):
# getvideo = commands.getoutput("/bin/lspci | grep VGA")
#
# elif (exists("/usr/bin/lspci")):
# getvideo = commands.getoutput("/usr/bin/lspci | grep VGA")
#
# getvideo.rstrip(os.linesep)
# getvideo = string.split(getvideo, ":")
# getvideo = getvideo[3][1:]
# getvideo.rstrip(os.linesep)
# End videocard #
# Resolution #
getres = commands.getoutput("xdpyinfo | grep dimensions")
getres.rstrip(os.linesep)
getres = string.split(getres)
getres = getres[1]
# End Resolution #
# Depth #
getdep = commands.getoutput("xdpyinfo | grep depth:")
getdep = string.split(getdep, "\n")
getdep = getdep[0]
getdep = string.split(getdep)
getdep = getdep[1]
getdep.rstrip(os.linesep)
# End depth #
# Uptime #
uptime = commands.getoutput("cat /proc/uptime")
uptime = string.split(uptime, " ")
days = int(float(uptime[0])/86400)
secs = int(float(uptime[0])%60)
mins = int(float(uptime[0])/60%60)
hours = int(float(uptime[0])/3600%24)
final = ""
if (days < 1): pass
if (days == 1): final += "1 day "
if (days > 1): final += str(days)+" days "
if (hours < 1): pass
if (hours == 1): final += "1 hour "
if (hours > 1): final += str(hours)+" hrs "
if (mins < 1): pass
if (mins == 1): final += "1 min "
if (mins > 1): final += str(mins)+" mins "
final += str(secs)+" secs"
# End uptime #
# Network #
route = commands.getoutput("/sbin/route | grep default")
route = string.split(route)
route = route[7]
route.rstrip(os.linesep)
conf = commands.getoutput("/sbin/ifconfig %s | grep \"RX bytes\"" % route)
conf = string.split(conf, ":")
inconf = conf[1]
inconf = string.split(inconf)
inetin = inconf[1]
inetin = inetin+" "+inconf[2]
inetin = string.replace(inetin, "(", "")
inetin = string.replace(inetin, ")", "")
outconf = string.split(conf[2])
inetout = outconf[1]
inetout = inetout+" "+outconf[2]
inetout = string.replace(inetout, "(", "")
inetout = string.replace(inetout, ")", "")
# End network #
# GVSU #
#gvsu = commands.getoutput("cat /home/lc/gvsu")
# End GVSU #
# Put it all together #
system = dist+" - "
system = system+uname+" "
system = system+""+cpuinfo+ " "
system = system+"Mem: (Used/Total) "+usedmem+"MB/"+getmem+"MB |"
system = system+"Res: "+getres+" (bpp: "+getdep+") "
system = system+"Up: "+final+" ------> G.V.S.U. 2006 Div2 National Champions!!"
#system = system+gvsu+" "
xchat.command("say %s" % system)
return xchat.EAT_ALL
xchat.hook_command("sysinfo", system_info, help="Prints system info")
print "X-Chat2 Sysinfo Script [1.3] by Loke Successfully loaded!"