34 from __future__
import print_function
44 from urllib2
import build_opener
46 from urllib.request
import build_opener
48 from urllib.parse
import urlparse
50 from urlparse
import urlparse
52 from json
import JSONEncoder
53 from simplejson
import errors
as sje
58 from smolt_config
import get_config_attr
59 from fs_util
import get_fslist
60 from devicelist
import cat
62 from devicelist
import get_device_list
64 from logging.handlers
import RotatingFileHandler
66 import MultipartPostHandler
70 except ImportError
as e:
78 WITHHELD_MAGIC_STRING =
'WITHHELD'
83 EXCEPTIONS = (requests.exceptions.HTTPError,
84 requests.exceptions.URLRequired,
85 requests.exceptions.Timeout,
86 requests.exceptions.ConnectionError,
87 requests.exceptions.InvalidURL)
90 fs_mounts = dict.fromkeys(
get_config_attr(
"FS_MOUNTS", [
"/",
"/home",
"/etc",
"/var",
"/boot"]),
True)
99 clientVersion =
'1.3.2'
100 smoltProtocol =
'0.97'
101 supported_protocols = [
'0.97',]
102 user_agent =
'smolt/%s' % smoltProtocol
108 PCI_BASE_CLASS_STORAGE = 1
109 PCI_CLASS_STORAGE_SCSI = 0
110 PCI_CLASS_STORAGE_IDE = 1
111 PCI_CLASS_STORAGE_FLOPPY = 2
112 PCI_CLASS_STORAGE_IPI = 3
113 PCI_CLASS_STORAGE_RAID = 4
114 PCI_CLASS_STORAGE_OTHER = 80
116 PCI_BASE_CLASS_NETWORK = 2
117 PCI_CLASS_NETWORK_ETHERNET = 0
118 PCI_CLASS_NETWORK_TOKEN_RING = 1
119 PCI_CLASS_NETWORK_FDDI = 2
120 PCI_CLASS_NETWORK_ATM = 3
121 PCI_CLASS_NETWORK_OTHER = 80
122 PCI_CLASS_NETWORK_WIRELESS = 128
124 PCI_BASE_CLASS_DISPLAY = 3
125 PCI_CLASS_DISPLAY_VGA = 0
126 PCI_CLASS_DISPLAY_XGA = 1
127 PCI_CLASS_DISPLAY_3D = 2
128 PCI_CLASS_DISPLAY_OTHER = 80
130 PCI_BASE_CLASS_MULTIMEDIA = 4
131 PCI_CLASS_MULTIMEDIA_VIDEO = 0
132 PCI_CLASS_MULTIMEDIA_AUDIO = 1
133 PCI_CLASS_MULTIMEDIA_PHONE = 2
134 PCI_CLASS_MULTIMEDIA_HD_AUDIO = 3
135 PCI_CLASS_MULTIMEDIA_OTHER = 80
137 PCI_BASE_CLASS_BRIDGE = 6
138 PCI_CLASS_BRIDGE_HOST = 0
139 PCI_CLASS_BRIDGE_ISA = 1
140 PCI_CLASS_BRIDGE_EISA = 2
141 PCI_CLASS_BRIDGE_MC = 3
142 PCI_CLASS_BRIDGE_PCI = 4
143 PCI_CLASS_BRIDGE_PCMCIA = 5
144 PCI_CLASS_BRIDGE_NUBUS = 6
145 PCI_CLASS_BRIDGE_CARDBUS = 7
146 PCI_CLASS_BRIDGE_RACEWAY = 8
147 PCI_CLASS_BRIDGE_OTHER = 80
149 PCI_BASE_CLASS_COMMUNICATION = 7
150 PCI_CLASS_COMMUNICATION_SERIAL = 0
151 PCI_CLASS_COMMUNICATION_PARALLEL = 1
152 PCI_CLASS_COMMUNICATION_MULTISERIAL = 2
153 PCI_CLASS_COMMUNICATION_MODEM = 3
154 PCI_CLASS_COMMUNICATION_OTHER = 80
156 PCI_BASE_CLASS_INPUT = 9
157 PCI_CLASS_INPUT_KEYBOARD = 0
158 PCI_CLASS_INPUT_PEN = 1
159 PCI_CLASS_INPUT_MOUSE = 2
160 PCI_CLASS_INPUT_SCANNER = 3
161 PCI_CLASS_INPUT_GAMEPORT = 4
162 PCI_CLASS_INPUT_OTHER = 80
164 PCI_BASE_CLASS_SERIAL = 12
165 PCI_CLASS_SERIAL_FIREWIRE = 0
166 PCI_CLASS_SERIAL_ACCESS = 1
168 PCI_CLASS_SERIAL_SSA = 2
169 PCI_CLASS_SERIAL_USB = 3
170 PCI_CLASS_SERIAL_FIBER = 4
171 PCI_CLASS_SERIAL_SMBUS = 5
175 FORMFACTOR_LIST = [
"Unknown",
179 "Low Profile Desktop",
192 "Main Server Chassis",
195 "Bus Expansion Chassis",
196 "Peripheral Chassis",
198 "Rack Mount Chassis",
206 ''' This shouldn't even be required in python3 '''
208 if not isinstance(o, basestring):
211 if isinstance(o, unicode):
214 s =
unicode(o, current_encoding)
223 self.
os = gate.process(
'distro', software.read_os(), WITHHELD_MAGIC_STRING)
226 self.
bogomips = gate.process(
'cpu', cpuInfo.get(
'bogomips', 0), 0)
227 self.
cpuVendor = gate.process(
'cpu', cpuInfo.get(
'type',
''), WITHHELD_MAGIC_STRING)
228 self.
cpuModel = gate.process(
'cpu', cpuInfo.get(
'model',
''), WITHHELD_MAGIC_STRING)
229 self.
cpu_stepping = gate.process(
'cpu', cpuInfo.get(
'cpu_stepping', 0), 0)
230 self.
cpu_family = gate.process(
'cpu', cpuInfo.get(
'cpu_family',
''),
'')
231 self.
cpu_model_num = gate.process(
'cpu', cpuInfo.get(
'cpu_model_num', 0), 0)
232 self.
numCpus = gate.process(
'cpu', cpuInfo.get(
'count', 0), 0)
233 self.
cpuSpeed = gate.process(
'cpu', cpuInfo.get(
'speed', 0), 0)
237 self.
systemSwap = gate.process(
'swap_size', memory[
'swap'], 0)
242 self.
kernelVersion = gate.process(
'kernel', os.uname()[2], WITHHELD_MAGIC_STRING)
243 if gate.grants(
'language'):
248 lang = subprocess.run([
'grep',
'LANG',
'/etc/sysconfig/i18n'],
249 stdout=subprocess.PIPE)
250 if lang.returncode == 0:
251 self.
language = lang.stdout.strip().split(b
'"')[1]
254 except subprocess.CalledProcessError:
257 self.
language = WITHHELD_MAGIC_STRING
259 tempform = platform.machine()
260 self.
platform = gate.process(
'arch', tempform, WITHHELD_MAGIC_STRING)
262 if gate.grants(
'vendor'):
271 if gate.grants(
'model'):
273 self.
systemModel =
cat(
'/sys/devices/virtual/dmi/id/product_name')[0].strip() +
' ' +
cat(
'/sys/devices/virtual/dmi/id/product_version')[0].strip()
286 if gate.grants(
'form_factor'):
288 formfactor_id = int(
cat(
'/sys/devices/virtual/dmi/id/chassis_type')[0].strip())
295 if tempform ==
'ppc64':
318 if gate.grants(
'selinux'):
322 if selinux.is_selinux_enabled() == 1:
333 enforce = selinux.security_getenforce()
355 if not gate.grants(
'file_systems'):
359 file_systems = [fs
for fs
in get_fslist()
if fs.fs_type
in fs_types]
363 file_systems = [fs
for fs
in file_systems
if fs.mnt_dev.startswith(
'/dev/')]
366 for fs
in file_systems:
367 if not fs.mnt_pnt
in fs_mounts:
368 fs.mnt_pnt = WITHHELD_MAGIC_STRING
370 for fs
in file_systems:
371 fs.mnt_pnt = WITHHELD_MAGIC_STRING
377 if device.bus ==
'Unknown' or device.bus ==
'unknown':
379 if device.vendorid
in (0,
None)
and device.type
is None:
381 if device.bus ==
'usb' and device.driver ==
'hub':
383 if device.bus ==
'usb' and 'Hub' in device.description:
385 if device.bus ==
'sound' and device.driver ==
'Unknown':
387 if device.bus ==
'pnp' and device.driver
in (
'Unknown',
'system'):
389 if device.bus ==
'block' and device.type ==
'DISK':
391 if device.bus ==
'usb_device' and device.type
is None:
399 return repr(self.
value)
402 for line
in page.split(b
"\n"):
404 return line.strip()[6:]
405 if b
'ServerMessage:' in line:
406 if b
'Critical' in line:
407 raise ServerError(line.split(
'ServerMessage: ')[1])
409 print(
_(
'Server Message: "%s"') % line.split(b
'ServerMessage: ')[1])
420 '''Attempt to reset the system hostname resolver.
421 returns 0 on success, or -1 if an error occurs.'''
425 resolv = ctypes.CDLL(
"libresolv.so.2")
426 r = resolv.__res_init()
427 except (OSError, AttributeError):
428 print(
"Warning: could not find __res_init in libresolv.so.2")
474 if gate.grants(
'devices'):
542 self.
session.headers.update({
'USER-AGENT': user_agent})
551 for d
in distros.all.get():
554 logging.info(
'Distro "%s" detected' % (key))
555 d.gather(gate, debug=
True)
560 'rst_excerpt':d.rst_excerpt(),
587 VendorID = self.
devices[device].vendorid
588 DeviceID = self.
devices[device].deviceid
589 SubsysVendorID = self.
devices[device].subsysvendorid
590 SubsysDeviceID = self.
devices[device].subsysdeviceid
591 Driver = self.
devices[device].driver
592 Type = self.
devices[device].type
593 Description = self.
devices[device].description
598 my_devices.append({
"vendor_id": VendorID,
599 "device_id": DeviceID,
600 "subsys_vendor_id": SubsysVendorID,
601 "subsys_device_id": SubsysDeviceID,
605 "description": Description})
610 return {
'uuid' : self.
host.UUID,
612 'default_runlevel': self.
host.defaultRunlevel,
613 'language' : self.
host.language,
614 'platform' : self.
host.platform,
615 'bogomips' : self.
host.bogomips,
616 'cpu_vendor' : self.
host.cpuVendor,
617 'cpu_model' : self.
host.cpuModel,
618 'cpu_stepping' : self.
host.cpu_stepping,
619 'cpu_family' : self.
host.cpu_family,
620 'cpu_model_num' : self.
host.cpu_model_num,
621 'num_cpus': self.
host.numCpus,
622 'cpu_speed' : self.
host.cpuSpeed,
623 'system_memory' : self.
host.systemMemory,
624 'system_swap' : self.
host.systemSwap,
625 'vendor' : self.
host.systemVendor,
626 'system' : self.
host.systemModel,
627 'kernel_version' : self.
host.kernelVersion,
628 'formfactor' : self.
host.formfactor,
629 'selinux_enabled': self.
host.selinux_enabled,
630 'selinux_policy': self.
host.selinux_policy,
631 'selinux_enforce': self.
host.selinux_enforce
635 return [fs.to_dict()
for fs
in self.
fss]
638 smoonURLparsed=urlparse(smoonURL)
643 uuiddb.set_pub_uuid(uuid, smoonURLparsed.netloc, pub_uuid)
644 except Exception
as e:
645 sys.stderr.write(
_(
'\tYour pub_uuid could not be written: {}.\n\n'.format(e)))
649 smoonURLparsed=urlparse(smoonURL)
650 admin_token_file += (
"-"+smoonURLparsed.netloc)
652 with open(admin_token_file,
'w')
as at_file:
654 except Exception
as e:
655 sys.stderr.write(
_(
'\tYour admin token could not be cached: %s\n' % e))
662 send_host_obj[
'smolt_protocol'] = prefered_protocol
666 dist_data_dict[k] = v[
'data']
667 send_host_obj[
'distro_specific'] = dist_data_dict
674 lines.append(
_(
'No distribution-specific data yet'))
677 lines.append(v[
'html'])
678 return '\n'.join(lines)
680 def send(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, proxies=proxies, batch=False):
681 def serialize(object, human=False):
688 return JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
694 current_url = smoonURL +
'tokens/token_json?uuid=%s' % self.
host.UUID
695 token = self.
session.
get(current_url, proxies=proxies, timeout=timeout)
696 except EXCEPTIONS
as e:
697 error(
_(
'Error contacting Server (tokens): {}'.format(e)))
699 return (1,
None,
None)
700 tok_obj = token.json()
702 if tok_obj[
'prefered_protocol']
in supported_protocols:
703 prefered_protocol = tok_obj[
'prefered_protocol']
706 error(
_(
'Wrong version, server incapable of handling your client'))
707 return (1,
None,
None)
708 tok = tok_obj[
'token']
710 except ValueError
as e:
712 error(
_(
'Something went wrong fetching a token'))
717 debug(
'smoon server URL: %s' % smoonURL)
719 serialized_host_obj_machine = serialize(send_host_obj, human=
False)
723 '.json':serialize(send_host_obj, human=
True),
725 '.rst':
'\n'.join(map(to_ascii, self.
getProfile())),
727 logdir = os.path.expanduser(
'~/.smolt/')
729 if not os.path.exists(logdir):
730 os.mkdir(logdir, 0o0700)
732 for k, v
in log_matrix.items():
733 filename = os.path.expanduser(os.path.join(
734 logdir,
'submission%s' % k))
735 r = RotatingFileHandler(filename, \
736 maxBytes=1000000, backupCount=9)
747 debug(
'sendHostStr: %s' % serialized_host_obj_machine)
748 debug(
'Sending Host')
751 entry_point =
"client/batch_add_json"
752 logging.debug(
'Submitting in asynchronous mode')
754 entry_point =
"client/add_json"
755 logging.debug(
'Submitting in synchronous mode')
756 request_url = smoonURL + entry_point
757 logging.debug(
'Sending request to %s' % request_url)
760 params = {
'uuid':self.
host.UUID,
761 'host':serialized_host_obj_machine,
763 'smolt_protocol':smoltProtocol}
764 o = opener.open(request_url, params)
766 except Exception
as e:
767 error(
_(
'Error contacting Server ([batch_]add_json): {}'.format(e)))
768 return (1,
None,
None)
772 except ServerError
as e:
774 error(
_(
'Error contacting server: %s') % e)
775 return (1,
None,
None)
781 pub_uuid = server_response.decode(
'latin1')
785 admin_token = self.
session.
get(smoonURL +
'tokens/admin_token_json?uuid=%s' % self.
host.UUID,
786 proxies=proxies, timeout=timeout)
787 except EXCEPTIONS
as e:
789 error(
_(
'An error has occured while contacting the server: %s' % e))
793 admin_obj = admin_token.json()
794 except sje.JSONDecodeError:
796 error(
_(
'Incorrect server response. Expected a JSON string'))
797 return (1,
None,
None)
799 if admin_obj[
'prefered_protocol']
in supported_protocols:
800 prefered_protocol = admin_obj[
'prefered_protocol']
803 error(
_(
'Wrong version, server incapable of handling your client'))
804 return (1,
None,
None)
805 admin = admin_obj[
'token']
807 if not admin_token_file ==
'' :
810 return (0, pub_uuid, admin)
817 new_uuid = self.
session.
get(smoonURL +
'client/regenerate_pub_uuid?uuid=%s' % self.
host.UUID,
818 proxies=proxies, timeout=timeout)
819 except EXCEPTIONS
as e:
823 response_dict = new_uuid.json()
824 except Exception
as e:
827 raise ServerError(
_(
'Reply from server could not be interpreted'))
830 pub_uuid = response_dict[
'pub_uuid']
833 raise ServerError(
_(
'Reply from server could not be interpreted'))
840 _(
'OS'):self.
host.os,
841 _(
'Default run level'):self.
host.defaultRunlevel,
842 _(
'Language'):self.
host.language,
845 for k, v
in d.items():
846 lines.append(
'%s: %s' % (k, v))
848 return '\n'.join(lines)
852 for i, (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description) \
856 lines.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, \
857 SubsysDeviceID, Bus, Driver, Type, Description))
859 return '\n'.join(lines)
863 lines.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
864 for i, v
in enumerate(self.
fss):
869 return '\n'.join(lines)
873 return v[
'rst_excerpt']
874 return "No data, yet"
879 printBuffer.append(
'# ' +
_(
'This is a Smolt report shown within your default pager.'))
880 printBuffer.append(
'# ' +
_(
'Below you can see what data you will submit to the server.'))
881 printBuffer.append(
'# ' +
_(
'To get back to Smolt exit the pager (try hitting "q").'))
882 printBuffer.append(
'#')
883 printBuffer.append(
'# ' +
_(
'NOTE: Editing this file does not change the data submitted.'))
884 printBuffer.append(
'')
885 printBuffer.append(
'')
887 printBuffer.append(
_(
'General'))
888 printBuffer.append(
'=================================')
891 printBuffer.append(
'%s: %s' % (label, data))
892 except UnicodeDecodeError:
894 printBuffer.append(
'%s: %s' % (
unicode(label,
'utf-8'), data))
895 except UnicodeDecodeError:
896 printBuffer.append(
'%r: %r' % (label, data))
899 printBuffer.append(
'')
900 printBuffer.append(
'')
901 printBuffer.append(
_(
'Devices'))
902 printBuffer.append(
'=================================')
904 for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
in self.
deviceIter():
905 printBuffer.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description))
907 printBuffer.append(
'')
908 printBuffer.append(
'')
909 printBuffer.append(
_(
'Filesystem Information'))
910 printBuffer.append(
'=================================')
911 printBuffer.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
912 printBuffer.append(
'-------------------------------------------------------------------')
914 printBuffer.append(str(fs))
917 printBuffer.append(
'')
918 printBuffer.append(
'')
919 printBuffer.append(v[
'rst'])
921 printBuffer.append(
'')
926 '''Iterate over host information.'''
927 yield _(
'UUID'), self.
host.UUID
928 yield _(
'OS'), self.
host.os
929 yield _(
'Default run level'), self.
host.defaultRunlevel
930 yield _(
'Language'), self.
host.language
931 yield _(
'Platform'), self.
host.platform
932 yield _(
'BogoMIPS'), self.
host.bogomips
933 yield _(
'CPU Vendor'), self.
host.cpuVendor
934 yield _(
'CPU Model'), self.
host.cpuModel
935 yield _(
'CPU Stepping'), self.
host.cpu_stepping
936 yield _(
'CPU Family'), self.
host.cpu_family
937 yield _(
'CPU Model Num'), self.
host.cpu_model_num
938 yield _(
'Number of CPUs'), self.
host.numCpus
939 yield _(
'CPU Speed'), self.
host.cpuSpeed
940 yield _(
'System Memory'), self.
host.systemMemory
941 yield _(
'System Swap'), self.
host.systemSwap
942 yield _(
'Vendor'), self.
host.systemVendor
943 yield _(
'System'), self.
host.systemModel
944 yield _(
'Form factor'), self.
host.formfactor
945 yield _(
'Kernel'), self.
host.kernelVersion
946 yield _(
'SELinux Enabled'), self.
host.selinux_enabled
947 yield _(
'SELinux Policy'), self.
host.selinux_policy
948 yield _(
'SELinux Enforce'), self.
host.selinux_enforce
951 '''Iterate over our devices.'''
954 VendorID = self.
devices[device].vendorid
955 DeviceID = self.
devices[device].deviceid
956 SubsysVendorID = self.
devices[device].subsysvendorid
957 SubsysDeviceID = self.
devices[device].subsysdeviceid
958 Driver = self.
devices[device].driver
959 Type = self.
devices[device].type
960 Description = self.
devices[device].description
963 yield VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
968 def get_entry(a, entry):
974 if not os.access(
"/proc/cpuinfo", os.R_OK):
977 cpulist = open(
"/proc/cpuinfo",
"r").
read()
978 uname = os.uname()[4].lower()
986 hwdict = {
'class':
"CPU",
987 'desc' :
"Processor",
989 if uname[0] ==
"i" and uname[-2:] ==
"86" or (uname ==
"x86_64"):
993 for cpu
in cpulist.split(
"\n\n"):
999 for cpu_attr
in cpu.split(
"\n"):
1000 if not len(cpu_attr):
1002 vals = cpu_attr.split(
':')
1006 name, value = vals[0].strip(), vals[1].strip()
1007 tmpdict[name.lower()] = value
1009 if uname ==
"x86_64":
1010 hwdict[
'platform'] =
'x86_64'
1012 hwdict[
'platform'] =
"i386"
1014 hwdict[
'count'] = count
1015 hwdict[
'type'] = get_entry(tmpdict,
'vendor_id')
1016 hwdict[
'model'] = get_entry(tmpdict,
'model name')
1017 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu family')
1018 hwdict[
'model_ver'] = get_entry(tmpdict,
'model')
1019 hwdict[
'cpu_stepping'] = get_entry(tmpdict,
'stepping')
1020 hwdict[
'cpu_family'] = get_entry(tmpdict,
'cpu family')
1021 hwdict[
'cpu_model_num'] = get_entry(tmpdict,
'model')
1022 hwdict[
'cache'] = get_entry(tmpdict,
'cache size')
1023 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1024 hwdict[
'other'] = get_entry(tmpdict,
'flags')
1025 mhz_speed = get_entry(tmpdict,
'cpu mhz')
1030 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1032 hwdict[
'speed'] = -1
1035 elif uname
in[
"alpha",
"alphaev6"]:
1038 for cpu_attr
in cpulist.split(
"\n"):
1039 if not len(cpu_attr):
1041 vals = cpu_attr.split(
':')
1045 name, value = vals[0].strip(), vals[1].strip()
1046 tmpdict[name.lower()] = value.lower()
1048 hwdict[
'platform'] =
"alpha"
1049 hwdict[
'count'] = get_entry(tmpdict,
'cpus detected')
1050 hwdict[
'type'] = get_entry(tmpdict,
'cpu')
1051 hwdict[
'model'] = get_entry(tmpdict,
'cpu model')
1052 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu variation')
1053 hwdict[
'model_version'] =
"%s/%s" % (get_entry(tmpdict,
'system type'),
1054 get_entry(tmpdict,
'system variation'))
1055 hwdict[
'model_rev'] = get_entry(tmpdict,
'cpu revision')
1056 hwdict[
'cache'] =
""
1057 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1058 hwdict[
'other'] = get_entry(tmpdict,
'platform string')
1059 hz_speed = get_entry(tmpdict,
'cycle frequency [Hz]')
1061 hz_speed = hz_speed.split()
1063 hwdict[
'speed'] = int(round(float(hz_speed[0]))) / 1000000
1065 hwdict[
'speed'] = -1
1067 elif uname
in [
"ia64"]:
1070 for cpu
in cpulist.split(
"\n\n"):
1077 for cpu_attr
in cpu.split(
"\n"):
1078 if not len(cpu_attr):
1080 vals = cpu_attr.split(
":")
1084 name, value = vals[0].strip(), vals[1].strip()
1085 tmpdict[name.lower()] = value.lower()
1087 hwdict[
'platform'] = uname
1088 hwdict[
'count'] = count
1089 hwdict[
'type'] = get_entry(tmpdict,
'vendor')
1090 hwdict[
'model'] = get_entry(tmpdict,
'family')
1091 hwdict[
'model_ver'] = get_entry(tmpdict,
'archrev')
1092 hwdict[
'model_rev'] = get_entry(tmpdict,
'revision')
1093 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1094 mhz_speed = tmpdict[
'cpu mhz']
1096 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1098 hwdict[
'speed'] = -1
1099 hwdict[
'other'] = get_entry(tmpdict,
'features')
1101 elif uname
in [
'ppc64',
'ppc']:
1104 for cpu
in cpulist.split(
"processor"):
1111 for cpu_attr
in cpu.split(
"\n"):
1112 if not len(cpu_attr):
1114 vals = cpu_attr.split(
":")
1118 name, value = vals[0].strip(), vals[1].strip()
1119 tmpdict[name.lower()] = value.lower()
1121 hwdict[
'platform'] = uname
1122 hwdict[
'count'] = count
1123 hwdict[
'model'] = get_entry(tmpdict,
"cpu")
1124 hwdict[
'model_ver'] = get_entry(tmpdict,
'revision')
1125 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1126 hwdict[
'vendor'] = get_entry(tmpdict,
'machine')
1127 if get_entry(tmpdict,
'cpu').startswith(
'ppc970'):
1128 hwdict[
'type'] =
'IBM'
1130 hwdict[
'type'] = get_entry(tmpdict,
'platform')
1131 hwdict[
'system'] = get_entry(tmpdict,
'detected as')
1133 mhz_speed = get_entry(tmpdict,
'clock')[:-3]
1135 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1137 hwdict[
'speed'] = -1
1139 elif uname
in [
"sparc64",
"sparc"]:
1142 for cpu
in cpulist.split(
"\n\n"):
1146 for cpu_attr
in cpu.split(
"\n"):
1147 if not len(cpu_attr):
1149 vals = cpu_attr.split(
":")
1153 name, value = vals[0].strip(), vals[1].strip()
1154 if name.endswith(
'Bogo'):
1156 bogomips = int(round(float(value)) )
1159 tmpdict[name.lower()] = value.lower()
1161 if not os.access(
"/proc/openprom/banner-name", os.R_OK):
1163 if os.access(
"/proc/openprom/banner-name", os.R_OK):
1164 with open(
"/proc/openprom/banner-name",
"r")
as banner_name:
1166 hwdict[
'platform'] = uname
1167 hwdict[
'count'] = get_entry(tmpdict,
'ncpus probed')
1168 hwdict[
'model'] = get_entry(tmpdict,
'cpu')
1169 hwdict[
'type'] = get_entry(tmpdict,
'type')
1170 hwdict[
'model_ver'] = get_entry(tmpdict,
'type')
1171 hwdict[
'bogomips'] = bogomips
1172 hwdict[
'vendor'] =
'sun'
1173 hwdict[
'cache'] =
""
1174 speed = int(round(float(bogomips))) / 2
1175 hwdict[
'speed'] = speed
1176 hwdict[
'system'] = system
1180 hwdict[
'platform'] = uname
1182 hwdict[
'type'] = uname
1183 hwdict[
'model'] = uname
1184 hwdict[
'model_number'] =
""
1185 hwdict[
'model_ver'] =
""
1186 hwdict[
'model_rev'] =
""
1187 hwdict[
'cache'] =
""
1188 hwdict[
'bogomips'] =
""
1189 hwdict[
'other'] =
""
1193 if not hwdict[
"count"]:
1197 hwdict[
"count"] = int(hwdict[
"count"])
1201 if hwdict[
"count"] == 0:
1210 if os.path.exists(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq'):
1211 with open(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq')
as cpu_m_freq:
1212 hwdict[
'speed'] = int(cpu_m_freq.read().strip()) / 1000
1222 if kernel[:2] ==
"5.":
1224 if kernel[:2] ==
"4.":
1226 if kernel[:2] ==
"3.":
1228 if kernel[:3] ==
"2.6":
1230 if kernel[:3] ==
"2.4":
1234 if not os.access(
"/proc/meminfo", os.R_OK):
1237 with open(
"/proc/meminfo",
"r")
as m_info:
1238 meminfo = m_info.read()
1239 lines = meminfo.split(
"\n")
1241 memlist = curline.split()
1243 memdict[
'class'] =
"MEMORY"
1244 megs =
long(memlist[1])/(1024*1024)
1246 megs = megs + (4 - (megs % 4))
1248 megs = megs + (16 - (megs % 16))
1249 memdict[
'ram'] = str(megs)
1251 memlist = curline.split()
1253 megs =
long(memlist[1])/(1024*1024)
1254 memdict[
'swap'] = str(megs)
1258 if not os.access(
"/proc/meminfo", os.R_OK):
1260 with open(
"/proc/meminfo",
"r")
as m_info:
1261 meminfo = m_info.read()
1262 lines = meminfo.split(
"\n")
1265 blobs = line.split(
":", 1)
1270 value = blobs[1].strip()
1274 memdict[
"class"] =
"MEMORY"
1276 total_str = dict[
'MemTotal']
1277 blips = total_str.split(
" ")
1278 total_k =
long(blips[0])
1279 megs =
long(total_k/(1024))
1281 swap_str = dict[
'SwapTotal']
1282 blips = swap_str.split(
' ')
1283 swap_k =
long(blips[0])
1284 swap_megs =
long(swap_k/(1024))
1286 memdict[
'ram'] = str(megs)
1287 memdict[
'swap'] = str(swap_megs)
1301 except SystemBusError
as e:
1302 error(
_(
'Error:') +
' ' + e.msg)
1303 if e.hint
is not None:
1304 error(
'\t' +
_(
'Hint:') +
' ' + e.hint)
1309 return smoonURL +
'client/show/%s' % pub_uuid
1313 with open(hw_uuid_file)
as hw_uuid:
1314 UUID = hw_uuid.read().strip()
1315 except (FileNotFoundError, IOError):
1317 with open(
'/proc/sys/kernel/random/uuid')
as rand_uuid:
1318 UUID = rand_uuid.read().strip()
1319 with open(hw_uuid_file,
'w')
as write_uuid:
1320 write_uuid.write(UUID)
1321 except (FileNotFoundError, IOError):
1322 sys.stderr.write(
_(
'Unable to determine UUID of system!\n'))
1323 raise UUIDError(
'Unable to get/save UUID. file = %s. Please run once as root.' % hw_uuid_file)
1326 def read_pub_uuid(uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, silent=False):
1327 smoonURLparsed=urlparse(smoonURL)
1328 res = uuiddb.get_pub_uuid(uuid, smoonURLparsed.netloc)
1333 o = requests.get(smoonURL +
'client/pub_uuid?uuid=%s' % uuid,
1334 proxies=proxies, timeout=timeout)
1336 uuiddb.set_pub_uuid(uuid, smoonURLparsed.netloc, pudict[
"pub_uuid"])
1337 return pudict[
"pub_uuid"]
1338 except Exception
as e:
1340 error(
_(
'Error determining public UUID: %s') % e)
1341 sys.stderr.write(
_(
"Unable to determine Public UUID! This could be a network error or you've\n"))
1342 sys.stderr.write(
_(
"not submitted your profile yet.\n"))
1343 raise PubUUIDError(
'Could not determine Public UUID!\n')