On Fri, 2007-12-14 at 05:00 +0000, Ted Gould wrote:
> It needs to be cleaned up, but I'm currently more worried about
> correctness.  I don't need posts from everyone unless the values come
> out with something that is incorrect.  If everything is right don't
> worry about it.

If I run the script on my machine, I get this:

Processor:  AMD Athlon(tm) XP 2200+
HD size:  61492838400 bytes
Network:  VIA Technologies, Inc. :  VT6102 [Rhine-II]
Traceback (most recent call last):
  File "test.py", line 115, in <module>
    main()
  File "test.py", line 56, in main
    finalnode = xorgline.split('"')[1]
IndexError: list index out of range

This is because you don't seem to be skipping empty lines for xorg.conf,
which I have in my "Device" section. I fixed it like this in your
script:

if len(xorgline) == 0:
        continue

Also, note that Python strings are immutable: the call to strip()
returns the stripped version of the string, but doesn't touch the
original object. So:

xorgline.strip()

has to be:

xorgline = xorgline.strip()

I attached the script with the told changes to this mail. Besides that,
all information was gathered correctly for me.

Cheers,
Denis
#!/usr/bin/env python

import dbus
import os

def main () :
	system_bus = dbus.SystemBus()

	halmanager = system_bus.get_object('org.freedesktop.Hal',
										'/org/freedesktop/Hal/Manager')
	processors =  halmanager.FindDeviceByCapability('processor')

	# print (processors)
	for processor in processors :
	# print processor
		proc  = system_bus.get_object('org.freedesktop.Hal', processor)
		print 'Processor: ', proc.GetPropertyString('info.product')

	rootfses = halmanager.FindDeviceStringMatch('volume.mount_point', '/')
	if len(rootfses) != 1 :
		print 'Hmm, more than one root filesystem?'
	else:
		rootfs = system_bus.get_object('org.freedesktop.Hal', rootfses[0])
		rootfshd = system_bus.get_object('org.freedesktop.Hal', rootfs.GetPropertyString('info.parent'))
		print 'HD size: ', rootfshd.GetProperty('storage.size'), 'bytes'

	networkifaces =  halmanager.FindDeviceByCapability('net')
	networkcards = {}
	for networkiface in networkifaces :
		netiface = system_bus.get_object('org.freedesktop.Hal', networkiface)
		networkcards[netiface.GetPropertyString('info.parent')] = 1
	for networkcard in networkcards.keys() :
		netcard = system_bus.get_object('org.freedesktop.Hal', networkcard)
		print 'Network: ', netcard.GetProperty('info.vendor'), ': ', netcard.GetProperty('info.product')

	xorgconf = open('/etc/X11/xorg.conf')
	xorgconf_indev = False
	xorgconf_id = ""
	xorgconf_dev = ""
	videocards = {}
	for xorgline in xorgconf:
		xorgline = xorgline.strip()

		if len(xorgline) == 0:
			continue
		if xorgline.startswith('EndSection'):
			xorgconf_indev = False
			if xorgconf_id != "" and xorgconf_dev != "" :
				videocards[xorgconf_id] = xorgconf_dev
			xorgconf_id = ""
			xorgconf_dev = ""
		if xorgline.startswith('Section "Device"'):
			xorgconf_indev = True

		if xorgconf_indev == True :
			finalnode = xorgline.split('"')[1]
			if xorgline.find('Identifier') != -1 :
				xorgconf_id = finalnode
			if xorgline.find('Driver') != -1 :
				xorgconf_dev = finalnode
	for videocard in videocards.keys() :
		print 'Video: ', videocard, ' (', videocards[videocard], ')'
	xorgconf.close()

	lsb_release = open('/etc/lsb-release')
	lsb_release_vals = {}
	distrib = ""
	for lsb_release_line in lsb_release :
		lsb_release_line.strip()
		lsb_split = lsb_release_line.split('=')
		if len(lsb_split) == 2 :
			lsb_release_vals[lsb_split[0]] = lsb_split[1]
	lsb_release.close()
	if lsb_release_vals.has_key('DISTRIB_ID') :
		distrib = lsb_release_vals['DISTRIB_ID'].strip()
		if lsb_release_vals.has_key('DISTRIB_RELEASE') :
			distrib += " "
			distrib += lsb_release_vals["DISTRIB_RELEASE"].strip()
		if lsb_release_vals.has_key('DISTRIB_CODENAME') :
			distrib += " ("
			distrib += lsb_release_vals["DISTRIB_CODENAME"].strip()
			distrib += ")"
	if distrib != "":
		print "Distribution: ", distrib

	uname = os.popen('uname -r')
	print "Linux Kernel: ", uname.read().strip();
	uname.close()

	meminfo = open('/proc/meminfo')
	for memline in meminfo :
		if memline.startswith('MemTotal:') :
			split = memline.split(' ')
			print "RAM: ", split[-2].strip(), split[-1].strip()
	meminfo.close()

	gnomever = ""
	try:
		[dontcare, gnomeinfo, dontcareeither] = os.popen3('gnome-about --gnome-version')
		for gnomeline in gnomeinfo :
			if gnomeline.startswith('Version:') :
				gnomever = gnomeline.split(':')[-1].strip()
		dontcare.close()
		gnomeinfo.close()
		dontcareeither.close()
	except:
		gnomever = ""

	if gnomever != "" :
		print "GNOME: ", gnomever
	else:
		print "GNOME:  <undefined>"

if __name__ == '__main__':
	main()
-- 
ubuntu-desktop mailing list
ubuntu-desktop@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-desktop

Reply via email to