40 import urlgrabber.grabber
43 from urlparse
import urljoin
44 from urlparse
import urlparse
45 from urllib
import urlencode
48 from json
import JSONEncoder
53 from smolt_config
import get_config_attr
54 from fs_util
import get_fslist
55 from devicelist
import cat
57 from devicelist
import get_device_list
59 from logging.handlers
import RotatingFileHandler
61 import MultipartPostHandler
66 except ImportError, e:
70 WITHHELD_MAGIC_STRING =
'WITHHELD'
77 fs_mounts = dict.fromkeys(
get_config_attr(
"FS_MOUNTS", [
"/",
"/home",
"/etc",
"/var",
"/boot"]),
True)
86 clientVersion =
'1.3.2'
87 smoltProtocol =
'0.97'
88 supported_protocols = [
'0.97',]
89 user_agent =
'smolt/%s' % smoltProtocol
95 PCI_BASE_CLASS_STORAGE = 1
96 PCI_CLASS_STORAGE_SCSI = 0
97 PCI_CLASS_STORAGE_IDE = 1
98 PCI_CLASS_STORAGE_FLOPPY = 2
99 PCI_CLASS_STORAGE_IPI = 3
100 PCI_CLASS_STORAGE_RAID = 4
101 PCI_CLASS_STORAGE_OTHER = 80
103 PCI_BASE_CLASS_NETWORK = 2
104 PCI_CLASS_NETWORK_ETHERNET = 0
105 PCI_CLASS_NETWORK_TOKEN_RING = 1
106 PCI_CLASS_NETWORK_FDDI = 2
107 PCI_CLASS_NETWORK_ATM = 3
108 PCI_CLASS_NETWORK_OTHER = 80
109 PCI_CLASS_NETWORK_WIRELESS = 128
111 PCI_BASE_CLASS_DISPLAY = 3
112 PCI_CLASS_DISPLAY_VGA = 0
113 PCI_CLASS_DISPLAY_XGA = 1
114 PCI_CLASS_DISPLAY_3D = 2
115 PCI_CLASS_DISPLAY_OTHER = 80
117 PCI_BASE_CLASS_MULTIMEDIA = 4
118 PCI_CLASS_MULTIMEDIA_VIDEO = 0
119 PCI_CLASS_MULTIMEDIA_AUDIO = 1
120 PCI_CLASS_MULTIMEDIA_PHONE = 2
121 PCI_CLASS_MULTIMEDIA_HD_AUDIO = 3
122 PCI_CLASS_MULTIMEDIA_OTHER = 80
124 PCI_BASE_CLASS_BRIDGE = 6
125 PCI_CLASS_BRIDGE_HOST = 0
126 PCI_CLASS_BRIDGE_ISA = 1
127 PCI_CLASS_BRIDGE_EISA = 2
128 PCI_CLASS_BRIDGE_MC = 3
129 PCI_CLASS_BRIDGE_PCI = 4
130 PCI_CLASS_BRIDGE_PCMCIA = 5
131 PCI_CLASS_BRIDGE_NUBUS = 6
132 PCI_CLASS_BRIDGE_CARDBUS = 7
133 PCI_CLASS_BRIDGE_RACEWAY = 8
134 PCI_CLASS_BRIDGE_OTHER = 80
136 PCI_BASE_CLASS_COMMUNICATION = 7
137 PCI_CLASS_COMMUNICATION_SERIAL = 0
138 PCI_CLASS_COMMUNICATION_PARALLEL = 1
139 PCI_CLASS_COMMUNICATION_MULTISERIAL = 2
140 PCI_CLASS_COMMUNICATION_MODEM = 3
141 PCI_CLASS_COMMUNICATION_OTHER = 80
143 PCI_BASE_CLASS_INPUT = 9
144 PCI_CLASS_INPUT_KEYBOARD = 0
145 PCI_CLASS_INPUT_PEN = 1
146 PCI_CLASS_INPUT_MOUSE = 2
147 PCI_CLASS_INPUT_SCANNER = 3
148 PCI_CLASS_INPUT_GAMEPORT = 4
149 PCI_CLASS_INPUT_OTHER = 80
151 PCI_BASE_CLASS_SERIAL = 12
152 PCI_CLASS_SERIAL_FIREWIRE = 0
153 PCI_CLASS_SERIAL_ACCESS = 1
155 PCI_CLASS_SERIAL_SSA = 2
156 PCI_CLASS_SERIAL_USB = 3
157 PCI_CLASS_SERIAL_FIBER = 4
158 PCI_CLASS_SERIAL_SMBUS = 5
162 FORMFACTOR_LIST = [
"Unknown",
166 "Low Profile Desktop",
179 "Main Server Chassis",
182 "Bus Expansion Chassis",
183 "Peripheral Chassis",
185 "Rack Mount Chassis",
193 if not isinstance(o, basestring):
196 if isinstance(o, unicode):
199 s = unicode(o, current_encoding)
208 self.
os = gate.process(
'distro', software.read_os(), WITHHELD_MAGIC_STRING)
211 self.
bogomips = gate.process(
'cpu', cpuInfo.get(
'bogomips', 0), 0)
212 self.
cpuVendor = gate.process(
'cpu', cpuInfo.get(
'type',
''), WITHHELD_MAGIC_STRING)
213 self.
cpuModel = gate.process(
'cpu', cpuInfo.get(
'model',
''), WITHHELD_MAGIC_STRING)
214 self.
cpu_stepping = gate.process(
'cpu', cpuInfo.get(
'cpu_stepping', 0), 0)
215 self.
cpu_family = gate.process(
'cpu', cpuInfo.get(
'cpu_family',
''),
'')
216 self.
cpu_model_num = gate.process(
'cpu', cpuInfo.get(
'cpu_model_num', 0), 0)
217 self.
numCpus = gate.process(
'cpu', cpuInfo.get(
'count', 0), 0)
218 self.
cpuSpeed = gate.process(
'cpu', cpuInfo.get(
'speed', 0), 0)
221 self.
systemSwap = gate.process(
'swap_size', memory[
'swap'], 0)
222 self.
kernelVersion = gate.process(
'kernel', os.uname()[2], WITHHELD_MAGIC_STRING)
223 if gate.grants(
'language'):
228 status, lang = commands.getstatusoutput(
"grep LANG /etc/sysconfig/i18n")
236 self.
language = WITHHELD_MAGIC_STRING
238 tempform = platform.machine()
239 self.
platform = gate.process(
'arch', tempform, WITHHELD_MAGIC_STRING)
241 if gate.grants(
'vendor'):
250 if gate.grants(
'model'):
252 self.
systemModel =
cat(
'/sys/devices/virtual/dmi/id/product_name')[0].strip() +
' ' +
cat(
'/sys/devices/virtual/dmi/id/product_version')[0].strip()
265 if gate.grants(
'form_factor'):
267 formfactor_id =
int(
cat(
'/sys/devices/virtual/dmi/id/chassis_type')[0].strip())
274 if tempform ==
'ppc64':
275 if hostInfo.get(
'openfirmware.model'):
276 if hostInfo[
'openfirmware.model'][:3] ==
'IBM':
278 model = hostInfo[
'openfirmware.model'][4:8]
290 model_name = model_map[model]
291 self.
systemModel = gate.process(
'model', model_name)
292 self.
formfactor = gate.process(
'form_factor',
'Blade')
296 if gate.grants(
'selinux'):
300 if selinux.is_selinux_enabled() == 1:
311 enforce = selinux.security_getenforce()
333 if not gate.grants(
'file_systems'):
337 file_systems = [fs
for fs
in get_fslist()
if fs.fs_type
in fs_types]
341 file_systems = [fs
for fs
in file_systems
if fs.mnt_dev.startswith(
'/dev/')]
344 for fs
in file_systems:
345 if not fs.mnt_pnt
in fs_mounts:
346 fs.mnt_pnt = WITHHELD_MAGIC_STRING
348 for fs
in file_systems:
349 fs.mnt_pnt = WITHHELD_MAGIC_STRING
355 if device.bus ==
'Unknown' or device.bus ==
'unknown':
357 if device.vendorid
in (0,
None)
and device.type ==
None:
359 if device.bus ==
'usb' and device.driver ==
'hub':
361 if device.bus ==
'usb' and 'Hub' in device.description:
363 if device.bus ==
'sound' and device.driver ==
'Unknown':
365 if device.bus ==
'pnp' and device.driver
in (
'Unknown',
'system'):
367 if device.bus ==
'block' and device.type ==
'DISK':
369 if device.bus ==
'usb_device' and device.type ==
None:
377 return repr(self.
value)
380 for line
in page.split(
"\n"):
382 return line.strip()[6:]
383 if 'ServerMessage:' in line:
384 if 'Critical' in line:
385 raise ServerError, line.split(
'ServerMessage: ')[1]
387 print _(
'Server Message: "%s"') % line.split(
'ServerMessage: ')[1]
390 print >> sys.stderr, message
397 '''Attempt to reset the system hostname resolver.
398 returns 0 on success, or -1 if an error occurs.'''
402 resolv = ctypes.CDLL(
"libresolv.so.2")
403 r = resolv.__res_init()
404 except (OSError, AttributeError):
405 print "Warning: could not find __res_init in libresolv.so.2"
451 if gate.grants(
'devices'):
526 for d
in distros.all.get():
529 logging.info(
'Distro "%s" detected' % (key))
530 d.gather(gate, debug=
True)
535 'rst_excerpt':d.rst_excerpt(),
562 VendorID = self.
devices[device].vendorid
563 DeviceID = self.
devices[device].deviceid
564 SubsysVendorID = self.
devices[device].subsysvendorid
565 SubsysDeviceID = self.
devices[device].subsysdeviceid
566 Driver = self.
devices[device].driver
567 Type = self.
devices[device].type
568 Description = self.
devices[device].description
573 my_devices.append({
"vendor_id": VendorID,
574 "device_id": DeviceID,
575 "subsys_vendor_id": SubsysVendorID,
576 "subsys_device_id": SubsysDeviceID,
580 "description": Description})
585 return {
'uuid' : self.host.UUID,
587 'default_runlevel': self.host.defaultRunlevel,
588 'language' : self.host.language,
589 'platform' : self.host.platform,
590 'bogomips' : self.host.bogomips,
591 'cpu_vendor' : self.host.cpuVendor,
592 'cpu_model' : self.host.cpuModel,
593 'cpu_stepping' : self.host.cpu_stepping,
594 'cpu_family' : self.host.cpu_family,
595 'cpu_model_num' : self.host.cpu_model_num,
596 'num_cpus': self.host.numCpus,
597 'cpu_speed' : self.host.cpuSpeed,
598 'system_memory' : self.host.systemMemory,
599 'system_swap' : self.host.systemSwap,
600 'vendor' : self.host.systemVendor,
601 'system' : self.host.systemModel,
602 'kernel_version' : self.host.kernelVersion,
603 'formfactor' : self.host.formfactor,
604 'selinux_enabled': self.host.selinux_enabled,
605 'selinux_policy': self.host.selinux_policy,
606 'selinux_enforce': self.host.selinux_enforce
610 return [fs.to_dict()
for fs
in self.
fss]
613 smoonURLparsed=urlparse(smoonURL)
618 uuiddb.set_pub_uuid(uuid, smoonURLparsed[1], pub_uuid)
620 sys.stderr.write(
_(
'\tYour pub_uuid could not be written.\n\n'))
624 smoonURLparsed=urlparse(smoonURL)
625 admin_token_file += (
"-"+smoonURLparsed[1])
627 file(admin_token_file,
'w').
write(admin)
629 sys.stderr.write(
_(
'\tYour admin token could not be cached: %s\n' % e))
636 send_host_obj[
'smolt_protocol'] = prefered_protocol
639 for k, v
in self.distro_specific.items():
640 dist_data_dict[k] = v[
'data']
641 send_host_obj[
'distro_specific'] = dist_data_dict
648 lines.append(
_(
'No distribution-specific data yet'))
650 for k, v
in self.distro_specific.items():
651 lines.append(v[
'html'])
652 return '\n'.join(lines)
654 def send(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, proxies=proxies, batch=False):
655 def serialize(object, human=False):
662 return JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
665 grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout, proxies=proxies)
668 token = grabber.urlopen(urljoin(smoonURL +
"/",
'/tokens/token_json?uuid=%s' % self.host.UUID,
False))
669 except urlgrabber.grabber.URLGrabError, e:
670 error(
_(
'Error contacting Server: %s') % e)
671 return (1,
None,
None)
672 tok_str = token.read()
675 tok_obj = json.loads(tok_str)
676 if tok_obj[
'prefered_protocol']
in supported_protocols:
677 prefered_protocol = tok_obj[
'prefered_protocol']
679 error(
_(
'Wrong version, server incapable of handling your client'))
680 return (1,
None,
None)
681 tok = tok_obj[
'token']
683 except ValueError, e:
684 error(
_(
'Something went wrong fetching a token'))
691 debug(
'smoon server URL: %s' % smoonURL)
693 serialized_host_obj_machine = serialize(send_host_obj, human=
False)
697 '.json':serialize(send_host_obj, human=
True),
699 '.rst':
'\n'.join(map(to_ascii, self.
getProfile())),
701 logdir = os.path.expanduser(
'~/.smolt/')
703 if not os.path.exists(logdir):
704 os.mkdir(logdir, 0700)
706 for k, v
in log_matrix.items():
707 filename = os.path.expanduser(os.path.join(
708 logdir,
'submission%s' % k))
709 r = RotatingFileHandler(filename, \
710 maxBytes=1000000, backupCount=9)
721 debug(
'sendHostStr: %s' % serialized_host_obj_machine)
722 debug(
'Sending Host')
725 entry_point =
"/client/batch_add_json"
726 logging.debug(
'Submitting in asynchronous mode')
728 entry_point =
"/client/add_json"
729 logging.debug(
'Submitting in synchronous mode')
730 request_url = urljoin(smoonURL +
"/", entry_point,
False)
731 logging.debug(
'Sending request to %s' % request_url)
734 params = {
'uuid':self.host.UUID,
735 'host':serialized_host_obj_machine,
737 'smolt_protocol':smoltProtocol}
738 o = opener.open(request_url, params)
741 error(
_(
'Error contacting Server: %s') % e)
742 return (1,
None,
None)
746 except ServerError, e:
747 error(
_(
'Error contacting server: %s') % e)
748 return (1,
None,
None)
754 pub_uuid = server_response
758 admin_token = grabber.urlopen(urljoin(smoonURL +
"/",
'/tokens/admin_token_json?uuid=%s' % self.host.UUID,
False))
759 except urlgrabber.grabber.URLGrabError, e:
760 error(
_(
'An error has occured while contacting the server: %s' % e))
762 admin_str = admin_token.read()
763 admin_obj = json.loads(admin_str)
764 if admin_obj[
'prefered_protocol']
in supported_protocols:
765 prefered_protocol = admin_obj[
'prefered_protocol']
767 error(
_(
'Wrong version, server incapable of handling your client'))
768 return (1,
None,
None)
769 admin = admin_obj[
'token']
771 if not admin_token_file ==
'' :
773 return (0, pub_uuid, admin)
776 grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout)
778 new_uuid = grabber.urlopen(urljoin(smoonURL +
"/",
'/client/regenerate_pub_uuid?uuid=%s' % self.host.UUID))
779 except urlgrabber.grabber.URLGrabError, e:
780 raise ServerError, str(e)
782 response = new_uuid.read()
784 response_dict = json.loads(response)
787 raise ServerError,
_(
'Reply from server could not be interpreted')
790 pub_uuid = response_dict[
'pub_uuid']
792 raise ServerError,
_(
'Reply from server could not be interpreted')
799 _(
'OS'):self.host.os,
800 _(
'Default run level'):self.host.defaultRunlevel,
801 _(
'Language'):self.host.language,
804 for k, v
in d.items():
805 lines.append(
'%s: %s' % (k, v))
807 return '\n'.join(lines)
811 for i, (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description) \
815 lines.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, \
816 SubsysDeviceID, Bus, Driver, Type, Description))
818 return '\n'.join(lines)
822 lines.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
823 for i, v
in enumerate(self.
fss):
828 return '\n'.join(lines)
831 for k, v
in self.distro_specific.items():
832 return v[
'rst_excerpt']
833 return "No data, yet"
838 printBuffer.append(
'# ' +
_(
'This is a Smolt report shown within your default pager.'))
839 printBuffer.append(
'# ' +
_(
'Below you can see what data you will submit to the server.'))
840 printBuffer.append(
'# ' +
_(
'To get back to Smolt exit the pager (try hitting "q").'))
841 printBuffer.append(
'#')
842 printBuffer.append(
'# ' +
_(
'NOTE: Editing this file does not change the data submitted.'))
843 printBuffer.append(
'')
844 printBuffer.append(
'')
846 printBuffer.append(
_(
'General'))
847 printBuffer.append(
'=================================')
850 printBuffer.append(
'%s: %s' % (label, data))
851 except UnicodeDecodeError:
853 printBuffer.append(
'%s: %s' % (unicode(label,
'utf-8'), data))
854 except UnicodeDecodeError:
855 printBuffer.append(
'%r: %r' % (label, data))
858 printBuffer.append(
'')
859 printBuffer.append(
'')
860 printBuffer.append(
_(
'Devices'))
861 printBuffer.append(
'=================================')
863 for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
in self.
deviceIter():
864 printBuffer.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description))
866 printBuffer.append(
'')
867 printBuffer.append(
'')
868 printBuffer.append(
_(
'Filesystem Information'))
869 printBuffer.append(
'=================================')
870 printBuffer.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
871 printBuffer.append(
'-------------------------------------------------------------------')
873 printBuffer.append(str(fs))
875 for k, v
in self.distro_specific.items():
876 printBuffer.append(
'')
877 printBuffer.append(
'')
878 printBuffer.append(v[
'rst'])
880 printBuffer.append(
'')
885 '''Iterate over host information.'''
886 yield _(
'UUID'), self.host.UUID
887 yield _(
'OS'), self.host.os
888 yield _(
'Default run level'), self.host.defaultRunlevel
889 yield _(
'Language'), self.host.language
890 yield _(
'Platform'), self.host.platform
891 yield _(
'BogoMIPS'), self.host.bogomips
892 yield _(
'CPU Vendor'), self.host.cpuVendor
893 yield _(
'CPU Model'), self.host.cpuModel
894 yield _(
'CPU Stepping'), self.host.cpu_stepping
895 yield _(
'CPU Family'), self.host.cpu_family
896 yield _(
'CPU Model Num'), self.host.cpu_model_num
897 yield _(
'Number of CPUs'), self.host.numCpus
898 yield _(
'CPU Speed'), self.host.cpuSpeed
899 yield _(
'System Memory'), self.host.systemMemory
900 yield _(
'System Swap'), self.host.systemSwap
901 yield _(
'Vendor'), self.host.systemVendor
902 yield _(
'System'), self.host.systemModel
903 yield _(
'Form factor'), self.host.formfactor
904 yield _(
'Kernel'), self.host.kernelVersion
905 yield _(
'SELinux Enabled'), self.host.selinux_enabled
906 yield _(
'SELinux Policy'), self.host.selinux_policy
907 yield _(
'SELinux Enforce'), self.host.selinux_enforce
910 '''Iterate over our devices.'''
913 VendorID = self.
devices[device].vendorid
914 DeviceID = self.
devices[device].deviceid
915 SubsysVendorID = self.
devices[device].subsysvendorid
916 SubsysDeviceID = self.
devices[device].subsysdeviceid
917 Driver = self.
devices[device].driver
918 Type = self.
devices[device].type
919 Description = self.
devices[device].description
922 yield VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
927 def get_entry(a, entry):
933 if not os.access(
"/proc/cpuinfo", os.R_OK):
936 cpulist =
open(
"/proc/cpuinfo",
"r").read()
937 uname = os.uname()[4].lower()
945 hwdict = {
'class':
"CPU",
946 'desc' :
"Processor",
948 if uname[0] ==
"i" and uname[-2:] ==
"86" or (uname ==
"x86_64"):
952 for cpu
in cpulist.split(
"\n\n"):
958 for cpu_attr
in cpu.split(
"\n"):
959 if not len(cpu_attr):
961 vals = cpu_attr.split(
':')
965 name, value = vals[0].strip(), vals[1].strip()
966 tmpdict[name.lower()] = value
968 if uname ==
"x86_64":
969 hwdict[
'platform'] =
'x86_64'
971 hwdict[
'platform'] =
"i386"
973 hwdict[
'count'] = count
974 hwdict[
'type'] = get_entry(tmpdict,
'vendor_id')
975 hwdict[
'model'] = get_entry(tmpdict,
'model name')
976 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu family')
977 hwdict[
'model_ver'] = get_entry(tmpdict,
'model')
978 hwdict[
'cpu_stepping'] = get_entry(tmpdict,
'stepping')
979 hwdict[
'cpu_family'] = get_entry(tmpdict,
'cpu family')
980 hwdict[
'cpu_model_num'] = get_entry(tmpdict,
'model')
981 hwdict[
'cache'] = get_entry(tmpdict,
'cache size')
982 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
983 hwdict[
'other'] = get_entry(tmpdict,
'flags')
984 mhz_speed = get_entry(tmpdict,
'cpu mhz')
989 hwdict[
'speed'] =
int(round(float(mhz_speed)) - 1)
994 elif uname
in[
"alpha",
"alphaev6"]:
997 for cpu_attr
in cpulist.split(
"\n"):
998 if not len(cpu_attr):
1000 vals = cpu_attr.split(
':')
1004 name, value = vals[0].strip(), vals[1].strip()
1005 tmpdict[name.lower()] = value.lower()
1007 hwdict[
'platform'] =
"alpha"
1008 hwdict[
'count'] = get_entry(tmpdict,
'cpus detected')
1009 hwdict[
'type'] = get_entry(tmpdict,
'cpu')
1010 hwdict[
'model'] = get_entry(tmpdict,
'cpu model')
1011 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu variation')
1012 hwdict[
'model_version'] =
"%s/%s" % (get_entry(tmpdict,
'system type'),
1013 get_entry(tmpdict,
'system variation'))
1014 hwdict[
'model_rev'] = get_entry(tmpdict,
'cpu revision')
1015 hwdict[
'cache'] =
""
1016 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1017 hwdict[
'other'] = get_entry(tmpdict,
'platform string')
1018 hz_speed = get_entry(tmpdict,
'cycle frequency [Hz]')
1020 hz_speed = hz_speed.split()
1022 hwdict[
'speed'] =
int(round(float(hz_speed[0]))) / 1000000
1024 hwdict[
'speed'] = -1
1026 elif uname
in [
"ia64"]:
1029 for cpu
in cpulist.split(
"\n\n"):
1036 for cpu_attr
in cpu.split(
"\n"):
1037 if not len(cpu_attr):
1039 vals = cpu_attr.split(
":")
1043 name, value = vals[0].strip(), vals[1].strip()
1044 tmpdict[name.lower()] = value.lower()
1046 hwdict[
'platform'] = uname
1047 hwdict[
'count'] = count
1048 hwdict[
'type'] = get_entry(tmpdict,
'vendor')
1049 hwdict[
'model'] = get_entry(tmpdict,
'family')
1050 hwdict[
'model_ver'] = get_entry(tmpdict,
'archrev')
1051 hwdict[
'model_rev'] = get_entry(tmpdict,
'revision')
1052 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1053 mhz_speed = tmpdict[
'cpu mhz']
1055 hwdict[
'speed'] =
int(round(float(mhz_speed)) - 1)
1057 hwdict[
'speed'] = -1
1058 hwdict[
'other'] = get_entry(tmpdict,
'features')
1060 elif uname
in [
'ppc64',
'ppc']:
1063 for cpu
in cpulist.split(
"processor"):
1070 for cpu_attr
in cpu.split(
"\n"):
1071 if not len(cpu_attr):
1073 vals = cpu_attr.split(
":")
1077 name, value = vals[0].strip(), vals[1].strip()
1078 tmpdict[name.lower()] = value.lower()
1080 hwdict[
'platform'] = uname
1081 hwdict[
'count'] = count
1082 hwdict[
'model'] = get_entry(tmpdict,
"cpu")
1083 hwdict[
'model_ver'] = get_entry(tmpdict,
'revision')
1084 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1085 hwdict[
'vendor'] = get_entry(tmpdict,
'machine')
1086 if get_entry(tmpdict,
'cpu').startswith(
'ppc970'):
1087 hwdict[
'type'] =
'IBM'
1089 hwdict[
'type'] = get_entry(tmpdict,
'platform')
1090 hwdict[
'system'] = get_entry(tmpdict,
'detected as')
1092 mhz_speed = get_entry(tmpdict,
'clock')[:-3]
1094 hwdict[
'speed'] =
int(round(float(mhz_speed)) - 1)
1096 hwdict[
'speed'] = -1
1098 elif uname
in [
"sparc64",
"sparc"]:
1101 for cpu
in cpulist.split(
"\n\n"):
1105 for cpu_attr
in cpu.split(
"\n"):
1106 if not len(cpu_attr):
1108 vals = cpu_attr.split(
":")
1112 name, value = vals[0].strip(), vals[1].strip()
1113 if name.endswith(
'Bogo'):
1115 bogomips =
int(round(float(value)) )
1118 tmpdict[name.lower()] = value.lower()
1120 if not os.access(
"/proc/openprom/banner-name", os.R_OK):
1122 if os.access(
"/proc/openprom/banner-name", os.R_OK):
1123 system =
open(
"/proc/openprom/banner-name",
"r").read()
1124 hwdict['platform'] = uname
1125 hwdict[
'count'] = get_entry(tmpdict,
'ncpus probed')
1126 hwdict[
'model'] = get_entry(tmpdict,
'cpu')
1127 hwdict[
'type'] = get_entry(tmpdict,
'type')
1128 hwdict[
'model_ver'] = get_entry(tmpdict,
'type')
1129 hwdict[
'bogomips'] = bogomips
1130 hwdict[
'vendor'] =
'sun'
1131 hwdict[
'cache'] =
""
1132 speed =
int(round(float(bogomips))) / 2
1133 hwdict[
'speed'] = speed
1134 hwdict[
'system'] = system
1138 hwdict[
'platform'] = uname
1140 hwdict[
'type'] = uname
1141 hwdict[
'model'] = uname
1142 hwdict[
'model_number'] =
""
1143 hwdict[
'model_ver'] =
""
1144 hwdict[
'model_rev'] =
""
1145 hwdict[
'cache'] =
""
1146 hwdict[
'bogomips'] =
""
1147 hwdict[
'other'] =
""
1151 if not hwdict[
"count"]:
1155 hwdict[
"count"] =
int(hwdict[
"count"])
1159 if hwdict[
"count"] == 0:
1168 if os.path.exists(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq'):
1169 hwdict[
'speed'] =
int(file(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq').read().strip()) / 1000
1179 if kernel[:2] ==
"3.":
1181 if kernel[:3] ==
"2.6":
1183 if kernel[:3] ==
"2.4":
1187 if not os.access(
"/proc/meminfo", os.R_OK):
1190 meminfo =
open(
"/proc/meminfo",
"r").read()
1191 lines = meminfo.split("\n")
1193 memlist = curline.split()
1195 memdict[
'class'] =
"MEMORY"
1196 megs =
int(long(memlist[1])/(1024*1024))
1198 megs = megs + (4 - (megs % 4))
1200 megs = megs + (16 - (megs % 16))
1201 memdict[
'ram'] = str(megs)
1203 memlist = curline.split()
1205 megs =
int(long(memlist[1])/(1024*1024))
1206 memdict[
'swap'] = str(megs)
1210 if not os.access(
"/proc/meminfo", os.R_OK):
1212 meminfo =
open(
"/proc/meminfo",
"r").read()
1213 lines = meminfo.split("\n")
1216 blobs = line.split(
":", 1)
1221 value = blobs[1].strip()
1225 memdict[
"class"] =
"MEMORY"
1227 total_str = dict[
'MemTotal']
1228 blips = total_str.split(
" ")
1229 total_k = long(blips[0])
1230 megs = long(total_k/(1024))
1232 swap_str = dict[
'SwapTotal']
1233 blips = swap_str.split(
' ')
1234 swap_k = long(blips[0])
1235 swap_megs = long(swap_k/(1024))
1237 memdict[
'ram'] = str(megs)
1238 memdict[
'swap'] = str(swap_megs)
1252 except SystemBusError, e:
1253 error(
_(
'Error:') +
' ' + e.msg)
1254 if e.hint
is not None:
1255 error(
'\t' +
_(
'Hint:') +
' ' + e.hint)
1260 return urljoin(smoonURL,
'/client/show/%s' % pub_uuid)
1264 UUID = file(hw_uuid_file).read().strip()
1267 UUID = file(
'/proc/sys/kernel/random/uuid').read().strip()
1269 file(hw_uuid_file,
'w').
write(UUID)
1270 except Exception, e:
1271 raise UUIDError,
'Unable to save UUID to %s. Please run once as root.' % hw_uuid_file
1273 sys.stderr.write(
_(
'Unable to determine UUID of system!\n'))
1274 raise UUIDError,
'Could not determine UUID of system!\n'
1277 def read_pub_uuid(uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, silent=False):
1278 smoonURLparsed=urlparse(smoonURL)
1279 res = uuiddb.get_pub_uuid(uuid, smoonURLparsed[1])
1283 grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout, proxies=proxies)
1285 o = grabber.urlopen(urljoin(smoonURL +
"/",
'/client/pub_uuid/%s' % uuid))
1286 pudict = json.loads(o.read())
1288 uuiddb.set_pub_uuid(uuid, smoonURLparsed[1], pudict[
"pub_uuid"])
1289 return pudict[
"pub_uuid"]
1290 except Exception, e:
1292 error(
_(
'Error determining public UUID: %s') % e)
1293 sys.stderr.write(
_(
"Unable to determine Public UUID! This could be a network error or you've\n"))
1294 sys.stderr.write(
_(
"not submitted your profile yet.\n"))
1295 raise PubUUIDError,
'Could not determine Public UUID!\n'