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
57 from smolt_config
import get_config_attr
58 from fs_util
import get_fslist
59 from devicelist
import cat
61 from devicelist
import get_device_list
63 from logging.handlers
import RotatingFileHandler
65 import MultipartPostHandler
69 except ImportError
as e:
77 WITHHELD_MAGIC_STRING =
'WITHHELD'
82 EXCEPTIONS = (requests.exceptions.HTTPError,
83 requests.exceptions.URLRequired,
84 requests.exceptions.Timeout,
85 requests.exceptions.ConnectionError,
86 requests.exceptions.InvalidURL)
89 fs_mounts = dict.fromkeys(
get_config_attr(
"FS_MOUNTS", [
"/",
"/home",
"/etc",
"/var",
"/boot"]),
True)
98 clientVersion =
'1.3.2'
99 smoltProtocol =
'0.97'
100 supported_protocols = [
'0.97',]
101 user_agent =
'smolt/%s' % smoltProtocol
107 PCI_BASE_CLASS_STORAGE = 1
108 PCI_CLASS_STORAGE_SCSI = 0
109 PCI_CLASS_STORAGE_IDE = 1
110 PCI_CLASS_STORAGE_FLOPPY = 2
111 PCI_CLASS_STORAGE_IPI = 3
112 PCI_CLASS_STORAGE_RAID = 4
113 PCI_CLASS_STORAGE_OTHER = 80
115 PCI_BASE_CLASS_NETWORK = 2
116 PCI_CLASS_NETWORK_ETHERNET = 0
117 PCI_CLASS_NETWORK_TOKEN_RING = 1
118 PCI_CLASS_NETWORK_FDDI = 2
119 PCI_CLASS_NETWORK_ATM = 3
120 PCI_CLASS_NETWORK_OTHER = 80
121 PCI_CLASS_NETWORK_WIRELESS = 128
123 PCI_BASE_CLASS_DISPLAY = 3
124 PCI_CLASS_DISPLAY_VGA = 0
125 PCI_CLASS_DISPLAY_XGA = 1
126 PCI_CLASS_DISPLAY_3D = 2
127 PCI_CLASS_DISPLAY_OTHER = 80
129 PCI_BASE_CLASS_MULTIMEDIA = 4
130 PCI_CLASS_MULTIMEDIA_VIDEO = 0
131 PCI_CLASS_MULTIMEDIA_AUDIO = 1
132 PCI_CLASS_MULTIMEDIA_PHONE = 2
133 PCI_CLASS_MULTIMEDIA_HD_AUDIO = 3
134 PCI_CLASS_MULTIMEDIA_OTHER = 80
136 PCI_BASE_CLASS_BRIDGE = 6
137 PCI_CLASS_BRIDGE_HOST = 0
138 PCI_CLASS_BRIDGE_ISA = 1
139 PCI_CLASS_BRIDGE_EISA = 2
140 PCI_CLASS_BRIDGE_MC = 3
141 PCI_CLASS_BRIDGE_PCI = 4
142 PCI_CLASS_BRIDGE_PCMCIA = 5
143 PCI_CLASS_BRIDGE_NUBUS = 6
144 PCI_CLASS_BRIDGE_CARDBUS = 7
145 PCI_CLASS_BRIDGE_RACEWAY = 8
146 PCI_CLASS_BRIDGE_OTHER = 80
148 PCI_BASE_CLASS_COMMUNICATION = 7
149 PCI_CLASS_COMMUNICATION_SERIAL = 0
150 PCI_CLASS_COMMUNICATION_PARALLEL = 1
151 PCI_CLASS_COMMUNICATION_MULTISERIAL = 2
152 PCI_CLASS_COMMUNICATION_MODEM = 3
153 PCI_CLASS_COMMUNICATION_OTHER = 80
155 PCI_BASE_CLASS_INPUT = 9
156 PCI_CLASS_INPUT_KEYBOARD = 0
157 PCI_CLASS_INPUT_PEN = 1
158 PCI_CLASS_INPUT_MOUSE = 2
159 PCI_CLASS_INPUT_SCANNER = 3
160 PCI_CLASS_INPUT_GAMEPORT = 4
161 PCI_CLASS_INPUT_OTHER = 80
163 PCI_BASE_CLASS_SERIAL = 12
164 PCI_CLASS_SERIAL_FIREWIRE = 0
165 PCI_CLASS_SERIAL_ACCESS = 1
167 PCI_CLASS_SERIAL_SSA = 2
168 PCI_CLASS_SERIAL_USB = 3
169 PCI_CLASS_SERIAL_FIBER = 4
170 PCI_CLASS_SERIAL_SMBUS = 5
174 FORMFACTOR_LIST = [
"Unknown",
178 "Low Profile Desktop",
191 "Main Server Chassis",
194 "Bus Expansion Chassis",
195 "Peripheral Chassis",
197 "Rack Mount Chassis",
205 ''' This shouldn't even be required in python3 '''
207 if not isinstance(o, basestring):
210 if isinstance(o, unicode):
213 s =
unicode(o, current_encoding)
222 self.
os = gate.process(
'distro', software.read_os(), WITHHELD_MAGIC_STRING)
225 self.
bogomips = gate.process(
'cpu', cpuInfo.get(
'bogomips', 0), 0)
226 self.
cpuVendor = gate.process(
'cpu', cpuInfo.get(
'type',
''), WITHHELD_MAGIC_STRING)
227 self.
cpuModel = gate.process(
'cpu', cpuInfo.get(
'model',
''), WITHHELD_MAGIC_STRING)
228 self.
cpu_stepping = gate.process(
'cpu', cpuInfo.get(
'cpu_stepping', 0), 0)
229 self.
cpu_family = gate.process(
'cpu', cpuInfo.get(
'cpu_family',
''),
'')
230 self.
cpu_model_num = gate.process(
'cpu', cpuInfo.get(
'cpu_model_num', 0), 0)
231 self.
numCpus = gate.process(
'cpu', cpuInfo.get(
'count', 0), 0)
232 self.
cpuSpeed = gate.process(
'cpu', cpuInfo.get(
'speed', 0), 0)
236 self.
systemSwap = gate.process(
'swap_size', memory[
'swap'], 0)
241 self.
kernelVersion = gate.process(
'kernel', os.uname()[2], WITHHELD_MAGIC_STRING)
242 if gate.grants(
'language'):
247 lang = subprocess.run([
'grep',
'LANG',
'/etc/sysconfig/i18n'],
248 stdout=subprocess.PIPE)
249 if lang.returncode == 0:
250 self.
language = lang.stdout.strip().split(b
'"')[1]
253 except subprocess.CalledProcessError:
256 self.
language = WITHHELD_MAGIC_STRING
258 tempform = platform.machine()
259 self.
platform = gate.process(
'arch', tempform, WITHHELD_MAGIC_STRING)
261 if gate.grants(
'vendor'):
270 if gate.grants(
'model'):
272 self.
systemModel =
cat(
'/sys/devices/virtual/dmi/id/product_name')[0].strip() +
' ' +
cat(
'/sys/devices/virtual/dmi/id/product_version')[0].strip()
285 if gate.grants(
'form_factor'):
287 formfactor_id = int(
cat(
'/sys/devices/virtual/dmi/id/chassis_type')[0].strip())
294 if tempform ==
'ppc64':
317 if gate.grants(
'selinux'):
321 if selinux.is_selinux_enabled() == 1:
332 enforce = selinux.security_getenforce()
354 if not gate.grants(
'file_systems'):
358 file_systems = [fs
for fs
in get_fslist()
if fs.fs_type
in fs_types]
362 file_systems = [fs
for fs
in file_systems
if fs.mnt_dev.startswith(
'/dev/')]
365 for fs
in file_systems:
366 if not fs.mnt_pnt
in fs_mounts:
367 fs.mnt_pnt = WITHHELD_MAGIC_STRING
369 for fs
in file_systems:
370 fs.mnt_pnt = WITHHELD_MAGIC_STRING
376 if device.bus ==
'Unknown' or device.bus ==
'unknown':
378 if device.vendorid
in (0,
None)
and device.type
is None:
380 if device.bus ==
'usb' and device.driver ==
'hub':
382 if device.bus ==
'usb' and 'Hub' in device.description:
384 if device.bus ==
'sound' and device.driver ==
'Unknown':
386 if device.bus ==
'pnp' and device.driver
in (
'Unknown',
'system'):
388 if device.bus ==
'block' and device.type ==
'DISK':
390 if device.bus ==
'usb_device' and device.type
is None:
398 return repr(self.
value)
401 for line
in page.split(b
"\n"):
403 return line.strip()[6:]
404 if b
'ServerMessage:' in line:
405 if b
'Critical' in line:
406 raise ServerError(line.split(
'ServerMessage: ')[1])
408 print(
_(
'Server Message: "%s"') % line.split(b
'ServerMessage: ')[1])
419 '''Attempt to reset the system hostname resolver.
420 returns 0 on success, or -1 if an error occurs.'''
424 resolv = ctypes.CDLL(
"libresolv.so.2")
425 r = resolv.__res_init()
426 except (OSError, AttributeError):
427 print(
"Warning: could not find __res_init in libresolv.so.2")
473 if gate.grants(
'devices'):
541 self.
session.headers.update({
'USER-AGENT': user_agent})
550 for d
in distros.all.get():
553 logging.info(
'Distro "%s" detected' % (key))
554 d.gather(gate, debug=
True)
559 'rst_excerpt':d.rst_excerpt(),
586 VendorID = self.
devices[device].vendorid
587 DeviceID = self.
devices[device].deviceid
588 SubsysVendorID = self.
devices[device].subsysvendorid
589 SubsysDeviceID = self.
devices[device].subsysdeviceid
590 Driver = self.
devices[device].driver
591 Type = self.
devices[device].type
592 Description = self.
devices[device].description
597 my_devices.append({
"vendor_id": VendorID,
598 "device_id": DeviceID,
599 "subsys_vendor_id": SubsysVendorID,
600 "subsys_device_id": SubsysDeviceID,
604 "description": Description})
609 return {
'uuid' : self.
host.UUID,
611 'default_runlevel': self.
host.defaultRunlevel,
612 'language' : self.
host.language,
613 'platform' : self.
host.platform,
614 'bogomips' : self.
host.bogomips,
615 'cpu_vendor' : self.
host.cpuVendor,
616 'cpu_model' : self.
host.cpuModel,
617 'cpu_stepping' : self.
host.cpu_stepping,
618 'cpu_family' : self.
host.cpu_family,
619 'cpu_model_num' : self.
host.cpu_model_num,
620 'num_cpus': self.
host.numCpus,
621 'cpu_speed' : self.
host.cpuSpeed,
622 'system_memory' : self.
host.systemMemory,
623 'system_swap' : self.
host.systemSwap,
624 'vendor' : self.
host.systemVendor,
625 'system' : self.
host.systemModel,
626 'kernel_version' : self.
host.kernelVersion,
627 'formfactor' : self.
host.formfactor,
628 'selinux_enabled': self.
host.selinux_enabled,
629 'selinux_policy': self.
host.selinux_policy,
630 'selinux_enforce': self.
host.selinux_enforce
634 return [fs.to_dict()
for fs
in self.
fss]
637 smoonURLparsed=urlparse(smoonURL)
642 uuiddb.set_pub_uuid(uuid, smoonURLparsed.netloc, pub_uuid)
643 except Exception
as e:
644 sys.stderr.write(
_(
'\tYour pub_uuid could not be written: {}.\n\n'.format(e)))
648 smoonURLparsed=urlparse(smoonURL)
649 admin_token_file += (
"-"+smoonURLparsed.netloc)
651 with open(admin_token_file,
'w')
as at_file:
653 except Exception
as e:
654 sys.stderr.write(
_(
'\tYour admin token could not be cached: %s\n' % e))
661 send_host_obj[
'smolt_protocol'] = prefered_protocol
665 dist_data_dict[k] = v[
'data']
666 send_host_obj[
'distro_specific'] = dist_data_dict
673 lines.append(
_(
'No distribution-specific data yet'))
676 lines.append(v[
'html'])
677 return '\n'.join(lines)
679 def send(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, proxies=proxies, batch=False):
680 def serialize(object, human=False):
687 return JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
693 current_url = smoonURL +
'tokens/token_json?uuid=%s' % self.
host.UUID
694 token = self.
session.
get(current_url, proxies=proxies, timeout=timeout)
695 except EXCEPTIONS
as e:
696 error(
_(
'Error contacting Server (tokens): {}'.format(e)))
698 return (1,
None,
None)
699 tok_obj = token.json()
701 if tok_obj[
'prefered_protocol']
in supported_protocols:
702 prefered_protocol = tok_obj[
'prefered_protocol']
705 error(
_(
'Wrong version, server incapable of handling your client'))
706 return (1,
None,
None)
707 tok = tok_obj[
'token']
709 except ValueError
as e:
711 error(
_(
'Something went wrong fetching a token'))
716 debug(
'smoon server URL: %s' % smoonURL)
718 serialized_host_obj_machine = serialize(send_host_obj, human=
False)
722 '.json':serialize(send_host_obj, human=
True),
724 '.rst':
'\n'.join(map(to_ascii, self.
getProfile())),
726 logdir = os.path.expanduser(
'~/.smolt/')
728 if not os.path.exists(logdir):
729 os.mkdir(logdir, 0o0700)
731 for k, v
in log_matrix.items():
732 filename = os.path.expanduser(os.path.join(
733 logdir,
'submission%s' % k))
734 r = RotatingFileHandler(filename, \
735 maxBytes=1000000, backupCount=9)
746 debug(
'sendHostStr: %s' % serialized_host_obj_machine)
747 debug(
'Sending Host')
750 entry_point =
"client/batch_add_json"
751 logging.debug(
'Submitting in asynchronous mode')
753 entry_point =
"client/add_json"
754 logging.debug(
'Submitting in synchronous mode')
755 request_url = smoonURL + entry_point
756 logging.debug(
'Sending request to %s' % request_url)
759 params = {
'uuid':self.
host.UUID,
760 'host':serialized_host_obj_machine,
762 'smolt_protocol':smoltProtocol}
763 o = opener.open(request_url, params)
765 except Exception
as e:
766 error(
_(
'Error contacting Server ([batch_]add_json): {}'.format(e)))
767 return (1,
None,
None)
771 except ServerError
as e:
773 error(
_(
'Error contacting server: %s') % e)
774 return (1,
None,
None)
780 pub_uuid = server_response.decode(
'latin1')
784 admin_token = self.
session.
get(smoonURL +
'tokens/admin_token_json?uuid=%s' % self.
host.UUID,
785 proxies=proxies, timeout=timeout)
786 except EXCEPTIONS
as e:
788 error(
_(
'An error has occured while contacting the server: %s' % e))
792 admin_obj = json.loads(admin_token.content)
793 except json.JSONDecodeError:
795 error(
_(
'Incorrect server response. Expected a JSON string'))
796 return (1,
None,
None)
798 if admin_obj[
'prefered_protocol']
in supported_protocols:
799 prefered_protocol = admin_obj[
'prefered_protocol']
802 error(
_(
'Wrong version, server incapable of handling your client'))
803 return (1,
None,
None)
804 admin = admin_obj[
'token']
806 if not admin_token_file ==
'' :
809 return (0, pub_uuid, admin)
816 new_uuid = self.
session.
get(smoonURL +
'client/regenerate_pub_uuid?uuid=%s' % self.
host.UUID,
817 proxies=proxies, timeout=timeout)
818 except EXCEPTIONS
as e:
822 response_dict = new_uuid.json()
823 except Exception
as e:
826 raise ServerError(
_(
'Reply from server could not be interpreted'))
829 pub_uuid = response_dict[
'pub_uuid']
832 raise ServerError(
_(
'Reply from server could not be interpreted'))
839 _(
'OS'):self.
host.os,
840 _(
'Default run level'):self.
host.defaultRunlevel,
841 _(
'Language'):self.
host.language,
844 for k, v
in d.items():
845 lines.append(
'%s: %s' % (k, v))
847 return '\n'.join(lines)
851 for i, (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description) \
855 lines.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, \
856 SubsysDeviceID, Bus, Driver, Type, Description))
858 return '\n'.join(lines)
862 lines.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
863 for i, v
in enumerate(self.
fss):
868 return '\n'.join(lines)
872 return v[
'rst_excerpt']
873 return "No data, yet"
878 printBuffer.append(
'# ' +
_(
'This is a Smolt report shown within your default pager.'))
879 printBuffer.append(
'# ' +
_(
'Below you can see what data you will submit to the server.'))
880 printBuffer.append(
'# ' +
_(
'To get back to Smolt exit the pager (try hitting "q").'))
881 printBuffer.append(
'#')
882 printBuffer.append(
'# ' +
_(
'NOTE: Editing this file does not change the data submitted.'))
883 printBuffer.append(
'')
884 printBuffer.append(
'')
886 printBuffer.append(
_(
'General'))
887 printBuffer.append(
'=================================')
890 printBuffer.append(
'%s: %s' % (label, data))
891 except UnicodeDecodeError:
893 printBuffer.append(
'%s: %s' % (
unicode(label,
'utf-8'), data))
894 except UnicodeDecodeError:
895 printBuffer.append(
'%r: %r' % (label, data))
898 printBuffer.append(
'')
899 printBuffer.append(
'')
900 printBuffer.append(
_(
'Devices'))
901 printBuffer.append(
'=================================')
903 for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
in self.
deviceIter():
904 printBuffer.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description))
906 printBuffer.append(
'')
907 printBuffer.append(
'')
908 printBuffer.append(
_(
'Filesystem Information'))
909 printBuffer.append(
'=================================')
910 printBuffer.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
911 printBuffer.append(
'-------------------------------------------------------------------')
913 printBuffer.append(str(fs))
916 printBuffer.append(
'')
917 printBuffer.append(
'')
918 printBuffer.append(v[
'rst'])
920 printBuffer.append(
'')
925 '''Iterate over host information.'''
926 yield _(
'UUID'), self.
host.UUID
927 yield _(
'OS'), self.
host.os
928 yield _(
'Default run level'), self.
host.defaultRunlevel
929 yield _(
'Language'), self.
host.language
930 yield _(
'Platform'), self.
host.platform
931 yield _(
'BogoMIPS'), self.
host.bogomips
932 yield _(
'CPU Vendor'), self.
host.cpuVendor
933 yield _(
'CPU Model'), self.
host.cpuModel
934 yield _(
'CPU Stepping'), self.
host.cpu_stepping
935 yield _(
'CPU Family'), self.
host.cpu_family
936 yield _(
'CPU Model Num'), self.
host.cpu_model_num
937 yield _(
'Number of CPUs'), self.
host.numCpus
938 yield _(
'CPU Speed'), self.
host.cpuSpeed
939 yield _(
'System Memory'), self.
host.systemMemory
940 yield _(
'System Swap'), self.
host.systemSwap
941 yield _(
'Vendor'), self.
host.systemVendor
942 yield _(
'System'), self.
host.systemModel
943 yield _(
'Form factor'), self.
host.formfactor
944 yield _(
'Kernel'), self.
host.kernelVersion
945 yield _(
'SELinux Enabled'), self.
host.selinux_enabled
946 yield _(
'SELinux Policy'), self.
host.selinux_policy
947 yield _(
'SELinux Enforce'), self.
host.selinux_enforce
950 '''Iterate over our devices.'''
953 VendorID = self.
devices[device].vendorid
954 DeviceID = self.
devices[device].deviceid
955 SubsysVendorID = self.
devices[device].subsysvendorid
956 SubsysDeviceID = self.
devices[device].subsysdeviceid
957 Driver = self.
devices[device].driver
958 Type = self.
devices[device].type
959 Description = self.
devices[device].description
962 yield VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
967 def get_entry(a, entry):
973 if not os.access(
"/proc/cpuinfo", os.R_OK):
976 cpulist = open(
"/proc/cpuinfo",
"r").
read()
977 uname = os.uname()[4].lower()
985 hwdict = {
'class':
"CPU",
986 'desc' :
"Processor",
988 if uname[0] ==
"i" and uname[-2:] ==
"86" or (uname ==
"x86_64"):
992 for cpu
in cpulist.split(
"\n\n"):
998 for cpu_attr
in cpu.split(
"\n"):
999 if not len(cpu_attr):
1001 vals = cpu_attr.split(
':')
1005 name, value = vals[0].strip(), vals[1].strip()
1006 tmpdict[name.lower()] = value
1008 if uname ==
"x86_64":
1009 hwdict[
'platform'] =
'x86_64'
1011 hwdict[
'platform'] =
"i386"
1013 hwdict[
'count'] = count
1014 hwdict[
'type'] = get_entry(tmpdict,
'vendor_id')
1015 hwdict[
'model'] = get_entry(tmpdict,
'model name')
1016 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu family')
1017 hwdict[
'model_ver'] = get_entry(tmpdict,
'model')
1018 hwdict[
'cpu_stepping'] = get_entry(tmpdict,
'stepping')
1019 hwdict[
'cpu_family'] = get_entry(tmpdict,
'cpu family')
1020 hwdict[
'cpu_model_num'] = get_entry(tmpdict,
'model')
1021 hwdict[
'cache'] = get_entry(tmpdict,
'cache size')
1022 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1023 hwdict[
'other'] = get_entry(tmpdict,
'flags')
1024 mhz_speed = get_entry(tmpdict,
'cpu mhz')
1029 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1031 hwdict[
'speed'] = -1
1034 elif uname
in[
"alpha",
"alphaev6"]:
1037 for cpu_attr
in cpulist.split(
"\n"):
1038 if not len(cpu_attr):
1040 vals = cpu_attr.split(
':')
1044 name, value = vals[0].strip(), vals[1].strip()
1045 tmpdict[name.lower()] = value.lower()
1047 hwdict[
'platform'] =
"alpha"
1048 hwdict[
'count'] = get_entry(tmpdict,
'cpus detected')
1049 hwdict[
'type'] = get_entry(tmpdict,
'cpu')
1050 hwdict[
'model'] = get_entry(tmpdict,
'cpu model')
1051 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu variation')
1052 hwdict[
'model_version'] =
"%s/%s" % (get_entry(tmpdict,
'system type'),
1053 get_entry(tmpdict,
'system variation'))
1054 hwdict[
'model_rev'] = get_entry(tmpdict,
'cpu revision')
1055 hwdict[
'cache'] =
""
1056 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1057 hwdict[
'other'] = get_entry(tmpdict,
'platform string')
1058 hz_speed = get_entry(tmpdict,
'cycle frequency [Hz]')
1060 hz_speed = hz_speed.split()
1062 hwdict[
'speed'] = int(round(float(hz_speed[0]))) / 1000000
1064 hwdict[
'speed'] = -1
1066 elif uname
in [
"ia64"]:
1069 for cpu
in cpulist.split(
"\n\n"):
1076 for cpu_attr
in cpu.split(
"\n"):
1077 if not len(cpu_attr):
1079 vals = cpu_attr.split(
":")
1083 name, value = vals[0].strip(), vals[1].strip()
1084 tmpdict[name.lower()] = value.lower()
1086 hwdict[
'platform'] = uname
1087 hwdict[
'count'] = count
1088 hwdict[
'type'] = get_entry(tmpdict,
'vendor')
1089 hwdict[
'model'] = get_entry(tmpdict,
'family')
1090 hwdict[
'model_ver'] = get_entry(tmpdict,
'archrev')
1091 hwdict[
'model_rev'] = get_entry(tmpdict,
'revision')
1092 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1093 mhz_speed = tmpdict[
'cpu mhz']
1095 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1097 hwdict[
'speed'] = -1
1098 hwdict[
'other'] = get_entry(tmpdict,
'features')
1100 elif uname
in [
'ppc64',
'ppc']:
1103 for cpu
in cpulist.split(
"processor"):
1110 for cpu_attr
in cpu.split(
"\n"):
1111 if not len(cpu_attr):
1113 vals = cpu_attr.split(
":")
1117 name, value = vals[0].strip(), vals[1].strip()
1118 tmpdict[name.lower()] = value.lower()
1120 hwdict[
'platform'] = uname
1121 hwdict[
'count'] = count
1122 hwdict[
'model'] = get_entry(tmpdict,
"cpu")
1123 hwdict[
'model_ver'] = get_entry(tmpdict,
'revision')
1124 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1125 hwdict[
'vendor'] = get_entry(tmpdict,
'machine')
1126 if get_entry(tmpdict,
'cpu').startswith(
'ppc970'):
1127 hwdict[
'type'] =
'IBM'
1129 hwdict[
'type'] = get_entry(tmpdict,
'platform')
1130 hwdict[
'system'] = get_entry(tmpdict,
'detected as')
1132 mhz_speed = get_entry(tmpdict,
'clock')[:-3]
1134 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1136 hwdict[
'speed'] = -1
1138 elif uname
in [
"sparc64",
"sparc"]:
1141 for cpu
in cpulist.split(
"\n\n"):
1145 for cpu_attr
in cpu.split(
"\n"):
1146 if not len(cpu_attr):
1148 vals = cpu_attr.split(
":")
1152 name, value = vals[0].strip(), vals[1].strip()
1153 if name.endswith(
'Bogo'):
1155 bogomips = int(round(float(value)) )
1158 tmpdict[name.lower()] = value.lower()
1160 if not os.access(
"/proc/openprom/banner-name", os.R_OK):
1162 if os.access(
"/proc/openprom/banner-name", os.R_OK):
1163 with open(
"/proc/openprom/banner-name",
"r")
as banner_name:
1165 hwdict[
'platform'] = uname
1166 hwdict[
'count'] = get_entry(tmpdict,
'ncpus probed')
1167 hwdict[
'model'] = get_entry(tmpdict,
'cpu')
1168 hwdict[
'type'] = get_entry(tmpdict,
'type')
1169 hwdict[
'model_ver'] = get_entry(tmpdict,
'type')
1170 hwdict[
'bogomips'] = bogomips
1171 hwdict[
'vendor'] =
'sun'
1172 hwdict[
'cache'] =
""
1173 speed = int(round(float(bogomips))) / 2
1174 hwdict[
'speed'] = speed
1175 hwdict[
'system'] = system
1179 hwdict[
'platform'] = uname
1181 hwdict[
'type'] = uname
1182 hwdict[
'model'] = uname
1183 hwdict[
'model_number'] =
""
1184 hwdict[
'model_ver'] =
""
1185 hwdict[
'model_rev'] =
""
1186 hwdict[
'cache'] =
""
1187 hwdict[
'bogomips'] =
""
1188 hwdict[
'other'] =
""
1192 if not hwdict[
"count"]:
1196 hwdict[
"count"] = int(hwdict[
"count"])
1200 if hwdict[
"count"] == 0:
1209 if os.path.exists(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq'):
1210 with open(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq')
as cpu_m_freq:
1211 hwdict[
'speed'] = int(cpu_m_freq.read().strip()) / 1000
1221 if kernel[:2] ==
"5.":
1223 if kernel[:2] ==
"4.":
1225 if kernel[:2] ==
"3.":
1227 if kernel[:3] ==
"2.6":
1229 if kernel[:3] ==
"2.4":
1233 if not os.access(
"/proc/meminfo", os.R_OK):
1236 with open(
"/proc/meminfo",
"r")
as m_info:
1237 meminfo = m_info.read()
1238 lines = meminfo.split(
"\n")
1240 memlist = curline.split()
1242 memdict[
'class'] =
"MEMORY"
1243 megs =
long(memlist[1])/(1024*1024)
1245 megs = megs + (4 - (megs % 4))
1247 megs = megs + (16 - (megs % 16))
1248 memdict[
'ram'] = str(megs)
1250 memlist = curline.split()
1252 megs =
long(memlist[1])/(1024*1024)
1253 memdict[
'swap'] = str(megs)
1257 if not os.access(
"/proc/meminfo", os.R_OK):
1259 with open(
"/proc/meminfo",
"r")
as m_info:
1260 meminfo = m_info.read()
1261 lines = meminfo.split(
"\n")
1264 blobs = line.split(
":", 1)
1269 value = blobs[1].strip()
1273 memdict[
"class"] =
"MEMORY"
1275 total_str = dict[
'MemTotal']
1276 blips = total_str.split(
" ")
1277 total_k =
long(blips[0])
1278 megs =
long(total_k/(1024))
1280 swap_str = dict[
'SwapTotal']
1281 blips = swap_str.split(
' ')
1282 swap_k =
long(blips[0])
1283 swap_megs =
long(swap_k/(1024))
1285 memdict[
'ram'] = str(megs)
1286 memdict[
'swap'] = str(swap_megs)
1300 except SystemBusError
as e:
1301 error(
_(
'Error:') +
' ' + e.msg)
1302 if e.hint
is not None:
1303 error(
'\t' +
_(
'Hint:') +
' ' + e.hint)
1308 return smoonURL +
'client/show/%s' % pub_uuid
1312 with open(hw_uuid_file)
as hw_uuid:
1313 UUID = hw_uuid.read().strip()
1314 except (FileNotFoundError, IOError):
1316 with open(
'/proc/sys/kernel/random/uuid')
as rand_uuid:
1317 UUID = rand_uuid.read().strip()
1318 with open(hw_uuid_file,
'w')
as write_uuid:
1319 write_uuid.write(UUID)
1320 except (FileNotFoundError, IOError):
1321 sys.stderr.write(
_(
'Unable to determine UUID of system!\n'))
1322 raise UUIDError(
'Unable to get/save UUID. file = %s. Please run once as root.' % hw_uuid_file)
1325 def read_pub_uuid(uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, silent=False):
1326 smoonURLparsed=urlparse(smoonURL)
1327 res = uuiddb.get_pub_uuid(uuid, smoonURLparsed.netloc)
1332 o = requests.get(smoonURL +
'client/pub_uuid?uuid=%s' % uuid,
1333 proxies=proxies, timeout=timeout)
1335 uuiddb.set_pub_uuid(uuid, smoonURLparsed.netloc, pudict[
"pub_uuid"])
1336 return pudict[
"pub_uuid"]
1337 except Exception
as e:
1339 error(
_(
'Error determining public UUID: %s') % e)
1340 sys.stderr.write(
_(
"Unable to determine Public UUID! This could be a network error or you've\n"))
1341 sys.stderr.write(
_(
"not submitted your profile yet.\n"))
1342 raise PubUUIDError(
'Could not determine Public UUID!\n')