![]()
If you use Gentoo and want to upload your report just run this program as root.
Download
Here is the report that was generated when I ran it.
#!/usr/bin/python
# Filename : gentoo_report.py
import os
import sys
import commands
import subprocess
import datetime
import ftplib
from time import sleep
import gzip
def usage():
"""Explains the program to the user"""
print \
"\n\tGentoo System Report\n" \
"\n" \
"\t", "To generate this report you will need:\n" \
"\t", "To be root!\n" \
"\t", "sys-apps/pciutils\n" \
"\t", "sys-apps/usbutils\n"
def check_whoami():
"""Check if root"""
if commands.getoutput( "whoami" ) != "root":
sys.exit("\tSorry, You must be root!\n" )
def pn():
"""progress bar"""
sys.stdout.write(". ")
sleep(0.1)
sys.stdout.flush()
def uname_report():
"""Generate uname -a"""
p = subprocess.Popen("uname -a > /tmp/uname.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def uptime_report():
"""Generate uptime"""
p = subprocess.Popen("uptime > /tmp/uptime.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def wm_version():
"""Generate window mamnager and version"""
path = "/etc/X11/Sessions"
lsdir = os.listdir(path)
for fname in lsdir:
if fname == "Gnome":
p = subprocess.Popen(
"gnome-about --version | sed 's/gnome-about//' > /tmp/window_manager.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
elif fname == "kde-3.5":
p = subprocess.Popen(
"kde-config --version >> /tmp/window_manager.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
elif fname == "kde-4.1":
p = subprocess.Popen(
"kde4-config --version >> /tmp/window_manager.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
elif fname == "kde-4.2":
p = subprocess.Popen(
"kde4-config --version >> /tmp/window_manager.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
elif fname == "openbox":
p = subprocess.Popen(
"openbox --version | sed '1!d' >> /tmp/window_manager.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
elif fname == "fluxbox":
p = subprocess.Popen(
"fluxbox --version >> /tmp/window_manager.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
else:
print "No Window Manager Found."
def disk_report():
"""Generate disk usage and mount points"""
p = subprocess.Popen("df -h > /tmp/disk_report.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def rcupdate_report():
"""Generate Gentoo spacific command rc-update show"""
p = subprocess.Popen("rc-update show > /tmp/rc_update.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def cpuinfo_report():
"""Generate cpu information"""
p = subprocess.Popen("cat /proc/cpuinfo > /tmp/cpu_info.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def emerge_report():
"""Generate Gentoo spicific command emerge --info"""
p = subprocess.Popen("emerge --info > /tmp/emerge_info.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def lspci_report():
"""Generate pci bus information"""
p = subprocess.Popen("lspci > /tmp/lspci.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def lsusb_report():
"""Generate usb bus information"""
p = subprocess.Popen("lsusb > /tmp/lsusb.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def rcconf_report():
"""OpenRC configuration file"""
p = subprocess.Popen(
"sed '/^[[:space:]]*\($\|#\)/d' /etc/rc.conf > /tmp/rc.conf.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def xorg_report():
"""xorg-server configuration file"""
p = subprocess.Popen(
"sed '/^[[:space:]]*\($\|#\)/d' /etc/X11/xorg.conf > /tmp/xorg.conf.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def net_report():
"""/etc/conf.d/net configuration file"""
p = subprocess.Popen(
"sed '/^[[:space:]]*\($\|#\)/d' /etc/conf.d/net > /tmp/net.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def kernel_config():
"""Add kernel .config to report"""
input_file = gzip.open('/proc/config.gz', 'rb')
kconfig = input_file.read()
try:
fname = '/tmp/kernel_config.txt'
fobj = open(fname, 'w')
fobj.write(kconfig)
fobj.close()
finally:
input_file.close()
def alsa_config():
"""/etc/modules.d/alsa configuration file"""
input_file = open('/etc/modules.d/alsa', 'rb')
aconfig = input_file.read()
try:
fname = '/tmp/alsa_conf.txt'
fobj = open(fname, 'w')
fobj.write(aconfig)
fobj.close()
finally:
input_file.close()
def keywords():
"""/etc/portage/package.keywords"""
filename = '/etc/portage/package.keywords'
if os.path.exists(filename):
input_file = open(filename, 'rb')
aconfig = input_file.read()
try:
fname = '/tmp/package.keywords.txt'
fobj = open(fname, 'w')
fobj.write(aconfig)
fobj.close()
finally:
input_file.close()
def mask():
"""/etc/portage/package.mask"""
filename = '/etc/portage/package.mask'
if os.path.exists(filename):
input_file = open(filename, 'rb')
aconfig = input_file.read()
try:
fname = '/tmp/package.mask.txt'
fobj = open(fname, 'w')
fobj.write(aconfig)
fobj.close()
finally:
input_file.close()
def create_date():
"""Add current date to bottom of report"""
now = datetime.datetime.today()
date = now.strftime('%h %d %Y %H:%M:%S')
handle = open('/tmp/data.txt','a')
logline = []
logline.append(date)
handle.write((' '.join(logline))+'\n')
handle.close()
def logoutFTP():
"""Log out from ftp server"""
ftp = ftplib.FTP(server)
ftp.close
print "Closing FTP connection to ", server
def sendfile(filename):
"""Upload file to web server via ftp"""
ftp = ftplib.FTP(server)
ftp.login(username, passwd)
try:
ftp.mkd(nick)
print 'Created new directory', nick
except ftplib.error_perm, resp:
if str(resp) == "550 Can't create directory: File exists":
pass
ftp.cwd(nick)
fname = '/tmp/' + filename
(head, tail) = os.path.split(fname)
command = 'STOR ' + tail
fd = open(fname, 'rb')
temp = fd.read(2048)
fd.seek(0, 0)
if temp.find('\0') != -1:
ftp.storbinary(command, fd)
print 'OK Uploaded', filename
else:
ftp.storlines(command, fd)
print 'OK Uploaded', filename
def sendall(files):
for name in files:
sendfile(name)
def grabfiles():
files=['data.txt', 'uname.txt', 'window_manager.txt', 'disk_report.txt',
'rc_update.txt', 'cpu_info.txt', 'emerge_info.txt', 'lspci.txt',
'rc.conf.txt', 'xorg.conf.txt', 'uptime.txt', 'kernel_config.txt',
'net.txt', 'alsa_conf.txt', 'package.keywords.txt',
'package.mask.txt']
sendall(files)
def getdata():
"""Run all the functions from above"""
uname_report()
pn()
uptime_report()
pn()
disk_report()
pn()
wm_version()
pn()
rcupdate_report()
pn()
cpuinfo_report()
pn()
emerge_report()
pn()
lspci_report()
pn()
lsusb_report()
pn()
rcconf_report()
pn()
xorg_report()
pn()
kernel_config()
pn()
net_report()
pn()
alsa_config()
pn()
keywords()
pn()
mask()
pn()
create_date()
pn()
sys.stdout.write('\r')
if __name__ == "__main__":
usage()
check_whoami()
nick = raw_input("Enter your nick on the Gentoo forum: ")
make = raw_input("Enter the make of your computer: ")
model = raw_input("Enter the model of your computer: ")
filename = "/tmp/data.txt"
fobj = open(filename, "w")
fobj.write(nick)
fobj.write("\n")
fobj.write(make)
fobj.write("\n")
fobj.write(model)
fobj.write("\n")
fobj.write("\n")
fobj.close()
server = raw_input("Enter the FTP server: ")
username = raw_input(
"Enter the username to upload your file: ")
passwd = raw_input(
"Enter the password: ")
getdata()
grabfiles()
logoutFTP()
print
print "Your report has been uploaded to http://wirelessfun.mobi/%s" % nick + "/"
print
David Abbott - david at linuxcrazy dot com