summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey <jcollie@fedoraproject.org>2007-01-27 03:35:16 (GMT)
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2007-01-27 03:35:16 (GMT)
commitb1563a95953fa7bc0761822156014fc07f623968 (patch)
tree4739b097af13107c50d548f61d67ca8e6e83d631
parentcd6529c008a11e28ced0f2439019f61db08ce114 (diff)
downloadsmolt-b1563a95953fa7bc0761822156014fc07f623968.zip
smolt-b1563a95953fa7bc0761822156014fc07f623968.tar.gz
smolt-b1563a95953fa7bc0761822156014fc07f623968.tar.xz
Put duplicated code into a common clas so that the code can be shared.
-rwxr-xr-xhw-client/Profile.py112
-rwxr-xr-xhw-client/readProfile.py95
-rwxr-xr-xhw-client/sendProfile.py116
3 files changed, 126 insertions, 197 deletions
diff --git a/hw-client/Profile.py b/hw-client/Profile.py
new file mode 100755
index 0000000..ff181b1
--- /dev/null
+++ b/hw-client/Profile.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+
+import hardware
+import sys
+import os
+import commands
+import re
+
+initdefault_re = re.compile(r':(\d+):initdefault:')
+
+class Profile:
+ def __init__(self):
+ try:
+ self.UUID = file('/etc/sysconfig/hw-uuid').read()
+ except IOError:
+ try:
+ self.UUID = file('/proc/sys/kernel/random/uuid').read()
+ try:
+ file('/etc/sysconfig/hw-uuid', 'w').write(self.UUID)
+ except:
+ sys.stderr.write('Unable to save UUID, continuing...\n')
+ except IOError:
+ sys.stderr.write('Unable to determine UUID of system!\n')
+ sys.exit(1)
+
+ self.hw = hardware.Hardware()
+ self.lsbRelease = commands.getstatusoutput('/usr/bin/lsb_release')[1]
+
+ try:
+ self.OS = file('/etc/redhat-release').read()
+ except IOError:
+ self.OS = 'Unknown'
+
+ self.defaultRunlevel = 'Unknown'
+ try:
+ inittab = file('/etc/inittab').read()
+ match = initdefault_re.search(inittab)
+ if match:
+ self.defaultRunlevel = match.group(1)
+ except IOError:
+ sys.stderr.write('Unable to read /etc/inittab, continuing...')
+
+ self.language = os.environ['LANG']
+
+ self.platform = self.bogomips = self.CPUVendor = self.numCPUs = self.CPUSpeed = self.systemMemory = self.systemSwap = self.vendor = self.system = ''
+
+ for device in self.hw:
+ try:
+ self.platform = device['platform']
+ self.bogomips = device['bogomips']
+ self.CPUVendor = "%s - %s" % (device['type'], device['model'])
+ self.numCPUs = device['count']
+ self.CPUSpeed = device['speed']
+ except:
+ pass
+ try:
+ self.systemMemory = device['ram']
+ self.systemSwap = device['swap']
+ except:
+ pass
+ try:
+ self.vendor = device['vendor']
+ self.system = device['system']
+ except:
+ pass
+
+ def get_host_string(self):
+ return "UUID=%s&lsbRelease=%s&OS=%s&defaultRunlevel=%s&language=%s&platform=%s&bogomips=%s&CPUVendor=%s&numCPUs=%s&CPUSpeed=%s&systemMemory=%s&systemSwap=%s&vendor=%s&system=%s" % (self.UUID, self.lsbRelease, self.OS, self.defaultRunlevel, self.language, self.platform, self.bogomips, self.CPUVendor, self.numCPUs, self.CPUSpeed, self.systemMemory, self.systemSwap, self.vendor, self.system)
+
+ def get_device_string(self):
+ for device in self.hw:
+ try:
+ Bus = device['bus']
+ Driver = device['driver']
+ Class = device['class']
+ Description = device['desc']
+ except:
+ continue
+ else:
+ yield "UUID=%s&Bus=%s&Driver=%s&Class=%s&Description=%s" % (self.UUID, Bus, Driver, Class, Description)
+
+ def print_data(self):
+ print 'We are about to send the following information to the Fedora Smolt server:'
+ print
+ print '\tUUID: %s' % self.UUID
+ print '\tlsbRelease: %s' % self.lsbRelease
+ print '\tOS: %s' % self.OS
+ print '\tdefaultRunlevel: %s' % self.defaultRunlevel
+ print '\tlanguage: %s' % self.language
+ print '\tplatform: %s' % self.platform
+ print '\tbogomips: %s' % self.bogomips
+ print '\tCPUVendor: %s' % self.CPUVendor
+ print '\tnumCPUs: %s' % self.numCPUs
+ print '\tCPUSpeed: %s' % self.CPUSpeed
+ print '\tsystemMemory: %s' % self.systemMemory
+ print '\tsystemSwap: %s' % self.systemSwap
+ print '\tvendor: %s' % self.vendor
+ print '\tsystem: %s' % self.system
+ print
+ print '\t\t Devices'
+ print '\t\t================================='
+ for device in self.hw:
+ try:
+ Bus = device['bus']
+ Driver = device['driver']
+ Class = device['class']
+ Description = device['desc']
+ except:
+ continue
+ else:
+ print '\t\t%s, %s, %s, %s' % (Bus, Driver, Class, Description)
+
diff --git a/hw-client/readProfile.py b/hw-client/readProfile.py
index 470a8ad..73a886d 100755
--- a/hw-client/readProfile.py
+++ b/hw-client/readProfile.py
@@ -1,96 +1,7 @@
#!/usr/bin/python
-import hardware
-import sys
-import os
-import commands
-import re
-import urlgrabber.grabber
+import Profile
-try:
- UUID = file('/etc/sysconfig/hw-uuid').read()
-except IOError:
- try:
- UUID = file('/proc/sys/kernel/random/uuid').read()
- try:
- file('/etc/sysconfig/hw-uuid', 'w').write(UUID)
- except:
- print 'couldn\'t write'
- except IOError:
- sys.stderr.write('Unable to determine UUID of system!\n')
- sys.exit(1)
-
-hw = hardware.Hardware()
-lsbRelease = commands.getstatusoutput('/usr/bin/lsb_release')[1]
-
-try:
- OS = file('/etc/redhat-release').read()
-except IOError:
- OS = 'Unknown'
-
-initdefault_re = re.compile(r':(\d+):initdefault:')
-defaultRunlevel = 'Unknown'
-try:
- inittab = file('/etc/inittab').read()
- match = initdefault_re.search(inittab)
- if match:
- defaultRunlevel = match.group(1)
-except IOError:
- sys.stderr.write('Unable to read /etc/inittab, continuing...')
-
-language = os.environ['LANG']
-
-platform = bogomips = CPUVendor = numCPUs = CPUSpeed = systemMemory = systemSwap = vendor = system = ''
-
-for device in hw:
- try:
- platform = device['platform']
- bogomips = device['bogomips']
- CPUVendor = "%s - %s" % (device['type'], device['model'])
- numCPUs = device['count']
- CPUSpeed = device['speed']
- except:
- pass
- try:
- systemMemory = device['ram']
- systemSwap = device['swap']
- except:
- pass
- try:
- vendor = device['vendor']
- system = device['system']
- except:
- pass
-
-
-
-print 'We would send the following information to the Fedora Smolt server:'
-print
-print '\tUUID: %s' % UUID
-print '\tlsbRelease: %s' % lsbRelease
-print '\tOS: %s' % OS
-print '\tdefaultRunlevel: %s' % defaultRunlevel
-print '\tlanguage: %s' % language
-print '\tplatform: %s' % platform
-print '\tbogomips: %s' % bogomips
-print '\tCPUVendor: %s' % CPUVendor
-print '\tnumCPUs: %s' % numCPUs
-print '\tCPUSpeed: %s' % CPUSpeed
-print '\tsystemMemory: %s' % systemMemory
-print '\tsystemSwap: %s' % systemSwap
-print '\tvendor: %s' % vendor
-print '\tsystem: %s' % system
-print
-print '\t\t Devices'
-print '\t\t================================='
-for device in hw:
- try:
- Bus = device['bus']
- Driver = device['driver']
- Class = device['class']
- Description = device['desc']
- except:
- continue
- else:
- print '\t\t%s, %s, %s, %s' % (Bus, Driver, Class, Description)
+profile = Profile.Profile()
+profile.print_data()
diff --git a/hw-client/sendProfile.py b/hw-client/sendProfile.py
index 64a4797..76d9811 100755
--- a/hw-client/sendProfile.py
+++ b/hw-client/sendProfile.py
@@ -1,124 +1,30 @@
#!/usr/bin/python
-import hardware
-import sys
-import os
-import commands
-import re
import urlgrabber.grabber
-try:
- UUID = file('/etc/sysconfig/hw-uuid').read()
-except IOError:
- try:
- UUID = file('/proc/sys/kernel/random/uuid').read()
- try:
- file('/etc/sysconfig/hw-uuid', 'w').write(UUID)
- except:
- sys.stderr.write('Unable to save UUID, continuing...\n')
- except IOError:
- sys.stderr.write('Unable to determine UUID of system!\n')
- sys.exit(1)
+import Profile
-hw = hardware.Hardware()
-lsbRelease = commands.getstatusoutput('/usr/bin/lsb_release')[1]
+profile = Profile.Profile()
-try:
- OS = file('/etc/redhat-release').read()
-except IOError:
- OS = 'Unknown'
-
-initdefault_re = re.compile(r':(\d+):initdefault:')
-defaultRunlevel = 'Unknown'
-try:
- inittab = file('/etc/inittab').read()
- match = initdefault_re.search(inittab)
- if match:
- defaultRunlevel = match.group(1)
-except IOError:
- sys.stderr.write('Unable to read /etc/inittab, continuing...')
-
-language = os.environ['LANG']
-
-platform = bogomips = CPUVendor = numCPUs = CPUSpeed = systemMemory = systemSwap = vendor = system = ''
-
-for device in hw:
- try:
- platform = device['platform']
- bogomips = device['bogomips']
- CPUVendor = "%s - %s" % (device['type'], device['model'])
- numCPUs = device['count']
- CPUSpeed = device['speed']
- except:
- pass
- try:
- systemMemory = device['ram']
- systemSwap = device['swap']
- except:
- pass
- try:
- vendor = device['vendor']
- system = device['system']
- except:
- pass
-
-sendHostStr = "UUID=%s&lsbRelease=%s&OS=%s&defaultRunlevel=%s&language=%s&platform=%s&bogomips=%s&CPUVendor=%s&numCPUs=%s&CPUSpeed=%s&systemMemory=%s&systemSwap=%s&vendor=%s&system=%s" % (UUID, lsbRelease, OS, defaultRunlevel, language, platform, bogomips, CPUVendor, numCPUs, CPUSpeed, systemMemory, systemSwap, vendor, system)
-
-
-print 'We are about to send the following information to the Fedora Smolt server:'
-print
-print '\tUUID: %s' % UUID
-print '\tlsbRelease: %s' % lsbRelease
-print '\tOS: %s' % OS
-print '\tdefaultRunlevel: %s' % defaultRunlevel
-print '\tlanguage: %s' % language
-print '\tplatform: %s' % platform
-print '\tbogomips: %s' % bogomips
-print '\tCPUVendor: %s' % CPUVendor
-print '\tnumCPUs: %s' % numCPUs
-print '\tCPUSpeed: %s' % CPUSpeed
-print '\tsystemMemory: %s' % systemMemory
-print '\tsystemSwap: %s' % systemSwap
-print '\tvendor: %s' % vendor
-print '\tsystem: %s' % system
-print
-print '\t\t Devices'
-print '\t\t================================='
-for device in hw:
- try:
- Bus = device['bus']
- Driver = device['driver']
- Class = device['class']
- Description = device['desc']
- except:
- continue
- else:
- print '\t\t%s, %s, %s, %s' % (Bus, Driver, Class, Description)
+profile.print_data()
print 'Transmitting ...'
grabber = urlgrabber.grabber.URLGrabber()
+sendHostStr = profile.get_host_string()
+
o=grabber.urlopen('http://publictest4.fedora.redhat.com/add', data=sendHostStr, http_headers=(('Content-length', '%i' % len(sendHostStr)),
('Content-type', 'application/x-www-form-urlencoded')))
o.close()
print 'sent host data'
-for device in hw:
- try:
- Bus = device['bus']
- Driver = device['driver']
- Class = device['class']
- Description = device['desc']
- except:
- continue
- else:
- sendDeviceStr = "UUID=%s&Bus=%s&Driver=%s&Class=%s&Description=%s" % (UUID, Bus, Driver, Class, Description)
- o=grabber.urlopen('http://publictest4.fedora.redhat.com/addDevice', data=sendDeviceStr, http_headers=(('Content-length', '%i' % len(sendDeviceStr)),
- ('Content-type', 'application/x-www-form-urlencoded')))
- o.close()
+for sendDeviceStr in profile.get_device_string():
+ o=grabber.urlopen('http://publictest4.fedora.redhat.com/addDevice', data=sendDeviceStr, http_headers=(('Content-length', '%i' % len(sendDeviceStr)),
+ ('Content-type', 'application/x-www-form-urlencoded')))
+ o.close()
- print 'sent device data'
+ print 'sent device data'
-print 'Thank you, your uuid (in /etc/sysconfig/hw-uuid), is %s' % UUID
+print 'Thank you, your uuid (in /etc/sysconfig/hw-uuid), is %s' % profile.UUID