43 from urllib2
import build_opener
45 from urllib.request
import build_opener
47 from urllib.parse
import urlparse
49 from urlparse
import urlparse
51 from json
import JSONEncoder
56 from smolt_config
import get_config_attr
57 from fs_util
import get_fslist
58 from devicelist
import cat
60 from devicelist
import get_device_list
62 from logging.handlers
import RotatingFileHandler
64 import MultipartPostHandler
68 except ImportError
as e:
76 WITHHELD_MAGIC_STRING =
'WITHHELD'
81 EXCEPTIONS = (requests.exceptions.HTTPError,
82 requests.exceptions.URLRequired,
83 requests.exceptions.Timeout,
84 requests.exceptions.ConnectionError,
85 requests.exceptions.InvalidURL)
88 fs_mounts = dict.fromkeys(
get_config_attr(
"FS_MOUNTS", [
"/",
"/home",
"/etc",
"/var",
"/boot"]),
True)
97 clientVersion =
'1.3.2'
98 smoltProtocol =
'0.97'
99 supported_protocols = [
'0.97',]
100 user_agent =
'smolt/%s' % smoltProtocol
106 PCI_BASE_CLASS_STORAGE = 1
107 PCI_CLASS_STORAGE_SCSI = 0
108 PCI_CLASS_STORAGE_IDE = 1
109 PCI_CLASS_STORAGE_FLOPPY = 2
110 PCI_CLASS_STORAGE_IPI = 3
111 PCI_CLASS_STORAGE_RAID = 4
112 PCI_CLASS_STORAGE_OTHER = 80
114 PCI_BASE_CLASS_NETWORK = 2
115 PCI_CLASS_NETWORK_ETHERNET = 0
116 PCI_CLASS_NETWORK_TOKEN_RING = 1
117 PCI_CLASS_NETWORK_FDDI = 2
118 PCI_CLASS_NETWORK_ATM = 3
119 PCI_CLASS_NETWORK_OTHER = 80
120 PCI_CLASS_NETWORK_WIRELESS = 128
122 PCI_BASE_CLASS_DISPLAY = 3
123 PCI_CLASS_DISPLAY_VGA = 0
124 PCI_CLASS_DISPLAY_XGA = 1
125 PCI_CLASS_DISPLAY_3D = 2
126 PCI_CLASS_DISPLAY_OTHER = 80
128 PCI_BASE_CLASS_MULTIMEDIA = 4
129 PCI_CLASS_MULTIMEDIA_VIDEO = 0
130 PCI_CLASS_MULTIMEDIA_AUDIO = 1
131 PCI_CLASS_MULTIMEDIA_PHONE = 2
132 PCI_CLASS_MULTIMEDIA_HD_AUDIO = 3
133 PCI_CLASS_MULTIMEDIA_OTHER = 80
135 PCI_BASE_CLASS_BRIDGE = 6
136 PCI_CLASS_BRIDGE_HOST = 0
137 PCI_CLASS_BRIDGE_ISA = 1
138 PCI_CLASS_BRIDGE_EISA = 2
139 PCI_CLASS_BRIDGE_MC = 3
140 PCI_CLASS_BRIDGE_PCI = 4
141 PCI_CLASS_BRIDGE_PCMCIA = 5
142 PCI_CLASS_BRIDGE_NUBUS = 6
143 PCI_CLASS_BRIDGE_CARDBUS = 7
144 PCI_CLASS_BRIDGE_RACEWAY = 8
145 PCI_CLASS_BRIDGE_OTHER = 80
147 PCI_BASE_CLASS_COMMUNICATION = 7
148 PCI_CLASS_COMMUNICATION_SERIAL = 0
149 PCI_CLASS_COMMUNICATION_PARALLEL = 1
150 PCI_CLASS_COMMUNICATION_MULTISERIAL = 2
151 PCI_CLASS_COMMUNICATION_MODEM = 3
152 PCI_CLASS_COMMUNICATION_OTHER = 80
154 PCI_BASE_CLASS_INPUT = 9
155 PCI_CLASS_INPUT_KEYBOARD = 0
156 PCI_CLASS_INPUT_PEN = 1
157 PCI_CLASS_INPUT_MOUSE = 2
158 PCI_CLASS_INPUT_SCANNER = 3
159 PCI_CLASS_INPUT_GAMEPORT = 4
160 PCI_CLASS_INPUT_OTHER = 80
162 PCI_BASE_CLASS_SERIAL = 12
163 PCI_CLASS_SERIAL_FIREWIRE = 0
164 PCI_CLASS_SERIAL_ACCESS = 1
166 PCI_CLASS_SERIAL_SSA = 2
167 PCI_CLASS_SERIAL_USB = 3
168 PCI_CLASS_SERIAL_FIBER = 4
169 PCI_CLASS_SERIAL_SMBUS = 5
173 FORMFACTOR_LIST = [
"Unknown",
177 "Low Profile Desktop",
190 "Main Server Chassis",
193 "Bus Expansion Chassis",
194 "Peripheral Chassis",
196 "Rack Mount Chassis",
204 ''' This shouldn't even be required in python3 '''
206 if not isinstance(o, basestring):
209 if isinstance(o, unicode):
212 s =
unicode(o, current_encoding)
221 self.
os = gate.process(
'distro', software.read_os(), WITHHELD_MAGIC_STRING)
224 self.
bogomips = gate.process(
'cpu', cpuInfo.get(
'bogomips', 0), 0)
225 self.
cpuVendor = gate.process(
'cpu', cpuInfo.get(
'type',
''), WITHHELD_MAGIC_STRING)
226 self.
cpuModel = gate.process(
'cpu', cpuInfo.get(
'model',
''), WITHHELD_MAGIC_STRING)
227 self.
cpu_stepping = gate.process(
'cpu', cpuInfo.get(
'cpu_stepping', 0), 0)
228 self.
cpu_family = gate.process(
'cpu', cpuInfo.get(
'cpu_family',
''),
'')
229 self.
cpu_model_num = gate.process(
'cpu', cpuInfo.get(
'cpu_model_num', 0), 0)
230 self.
numCpus = gate.process(
'cpu', cpuInfo.get(
'count', 0), 0)
231 self.
cpuSpeed = gate.process(
'cpu', cpuInfo.get(
'speed', 0), 0)
235 self.
systemSwap = gate.process(
'swap_size', memory[
'swap'], 0)
240 self.
kernelVersion = gate.process(
'kernel', os.uname()[2], WITHHELD_MAGIC_STRING)
241 if gate.grants(
'language'):
246 lang = subprocess.run([
'grep',
'LANG',
'/etc/sysconfig/i18n'],
247 stdout=subprocess.PIPE)
248 if lang.returncode == 0:
249 self.
language = lang.stdout.strip().split(b
'"')[1]
252 except subprocess.CalledProcessError:
255 self.
language = WITHHELD_MAGIC_STRING
257 tempform = platform.machine()
258 self.
platform = gate.process(
'arch', tempform, WITHHELD_MAGIC_STRING)
260 if gate.grants(
'vendor'):
269 if gate.grants(
'model'):
271 self.
systemModel =
cat(
'/sys/devices/virtual/dmi/id/product_name')[0].strip() +
' ' +
cat(
'/sys/devices/virtual/dmi/id/product_version')[0].strip()
284 if gate.grants(
'form_factor'):
286 formfactor_id = int(
cat(
'/sys/devices/virtual/dmi/id/chassis_type')[0].strip())
293 if tempform ==
'ppc64':
316 if gate.grants(
'selinux'):
320 if selinux.is_selinux_enabled() == 1:
331 enforce = selinux.security_getenforce()
353 if not gate.grants(
'file_systems'):
357 file_systems = [fs
for fs
in get_fslist()
if fs.fs_type
in fs_types]
361 file_systems = [fs
for fs
in file_systems
if fs.mnt_dev.startswith(
'/dev/')]
364 for fs
in file_systems:
365 if not fs.mnt_pnt
in fs_mounts:
366 fs.mnt_pnt = WITHHELD_MAGIC_STRING
368 for fs
in file_systems:
369 fs.mnt_pnt = WITHHELD_MAGIC_STRING
375 if device.bus ==
'Unknown' or device.bus ==
'unknown':
377 if device.vendorid
in (0,
None)
and device.type
is None:
379 if device.bus ==
'usb' and device.driver ==
'hub':
381 if device.bus ==
'usb' and 'Hub' in device.description:
383 if device.bus ==
'sound' and device.driver ==
'Unknown':
385 if device.bus ==
'pnp' and device.driver
in (
'Unknown',
'system'):
387 if device.bus ==
'block' and device.type ==
'DISK':
389 if device.bus ==
'usb_device' and device.type
is None:
397 return repr(self.
value)
400 for line
in page.split(b
"\n"):
402 return line.strip()[6:]
403 if b
'ServerMessage:' in line:
404 if b
'Critical' in line:
405 raise ServerError(line.split(
'ServerMessage: ')[1])
407 print(
_(
'Server Message: "%s"') % line.split(b
'ServerMessage: ')[1])
418 '''Attempt to reset the system hostname resolver.
419 returns 0 on success, or -1 if an error occurs.'''
423 resolv = ctypes.CDLL(
"libresolv.so.2")
424 r = resolv.__res_init()
425 except (OSError, AttributeError):
426 print(
"Warning: could not find __res_init in libresolv.so.2")
472 if gate.grants(
'devices'):
540 self.
session.headers.update({
'USER-AGENT': user_agent})
549 for d
in distros.all.get():
552 logging.info(
'Distro "%s" detected' % (key))
553 d.gather(gate, debug=
True)
558 'rst_excerpt':d.rst_excerpt(),
585 VendorID = self.
devices[device].vendorid
586 DeviceID = self.
devices[device].deviceid
587 SubsysVendorID = self.
devices[device].subsysvendorid
588 SubsysDeviceID = self.
devices[device].subsysdeviceid
589 Driver = self.
devices[device].driver
590 Type = self.
devices[device].type
591 Description = self.
devices[device].description
596 my_devices.append({
"vendor_id": VendorID,
597 "device_id": DeviceID,
598 "subsys_vendor_id": SubsysVendorID,
599 "subsys_device_id": SubsysDeviceID,
603 "description": Description})
608 return {
'uuid' : self.
host.UUID,
610 'default_runlevel': self.
host.defaultRunlevel,
611 'language' : self.
host.language,
612 'platform' : self.
host.platform,
613 'bogomips' : self.
host.bogomips,
614 'cpu_vendor' : self.
host.cpuVendor,
615 'cpu_model' : self.
host.cpuModel,
616 'cpu_stepping' : self.
host.cpu_stepping,
617 'cpu_family' : self.
host.cpu_family,
618 'cpu_model_num' : self.
host.cpu_model_num,
619 'num_cpus': self.
host.numCpus,
620 'cpu_speed' : self.
host.cpuSpeed,
621 'system_memory' : self.
host.systemMemory,
622 'system_swap' : self.
host.systemSwap,
623 'vendor' : self.
host.systemVendor,
624 'system' : self.
host.systemModel,
625 'kernel_version' : self.
host.kernelVersion,
626 'formfactor' : self.
host.formfactor,
627 'selinux_enabled': self.
host.selinux_enabled,
628 'selinux_policy': self.
host.selinux_policy,
629 'selinux_enforce': self.
host.selinux_enforce
633 return [fs.to_dict()
for fs
in self.
fss]
636 smoonURLparsed=urlparse(smoonURL)
641 uuiddb.set_pub_uuid(uuid, smoonURLparsed.netloc, pub_uuid)
642 except Exception
as e:
643 sys.stderr.write(
_(
'\tYour pub_uuid could not be written: {}.\n\n'.format(e)))
647 smoonURLparsed=urlparse(smoonURL)
648 admin_token_file += (
"-"+smoonURLparsed.netloc)
650 with open(admin_token_file,
'w')
as at_file:
652 except Exception
as e:
653 sys.stderr.write(
_(
'\tYour admin token could not be cached: %s\n' % e))
660 send_host_obj[
'smolt_protocol'] = prefered_protocol
664 dist_data_dict[k] = v[
'data']
665 send_host_obj[
'distro_specific'] = dist_data_dict
672 lines.append(
_(
'No distribution-specific data yet'))
675 lines.append(v[
'html'])
676 return '\n'.join(lines)
678 def send(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, proxies=proxies, batch=False):
679 def serialize(object, human=False):
686 return JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
692 current_url = smoonURL +
'tokens/token_json?uuid=%s' % self.
host.UUID
693 token = self.
session.
get(current_url, proxies=proxies, timeout=timeout)
694 except EXCEPTIONS
as e:
695 error(
_(
'Error contacting Server (tokens): {}'.format(e)))
697 return (1,
None,
None)
698 tok_obj = token.json()
700 if tok_obj[
'prefered_protocol']
in supported_protocols:
701 prefered_protocol = tok_obj[
'prefered_protocol']
704 error(
_(
'Wrong version, server incapable of handling your client'))
705 return (1,
None,
None)
706 tok = tok_obj[
'token']
708 except ValueError
as e:
710 error(
_(
'Something went wrong fetching a token'))
715 debug(
'smoon server URL: %s' % smoonURL)
717 serialized_host_obj_machine = serialize(send_host_obj, human=
False)
721 '.json':serialize(send_host_obj, human=
True),
723 '.rst':
'\n'.join(map(to_ascii, self.
getProfile())),
725 logdir = os.path.expanduser(
'~/.smolt/')
727 if not os.path.exists(logdir):
728 os.mkdir(logdir, 0o0700)
730 for k, v
in log_matrix.items():
731 filename = os.path.expanduser(os.path.join(
732 logdir,
'submission%s' % k))
733 r = RotatingFileHandler(filename, \
734 maxBytes=1000000, backupCount=9)
745 debug(
'sendHostStr: %s' % serialized_host_obj_machine)
746 debug(
'Sending Host')
749 entry_point =
"client/batch_add_json"
750 logging.debug(
'Submitting in asynchronous mode')
752 entry_point =
"client/add_json"
753 logging.debug(
'Submitting in synchronous mode')
754 request_url = smoonURL + entry_point
755 logging.debug(
'Sending request to %s' % request_url)
758 params = {
'uuid':self.
host.UUID,
759 'host':serialized_host_obj_machine,
761 'smolt_protocol':smoltProtocol}
762 o = opener.open(request_url, params)
764 except Exception
as e:
765 error(
_(
'Error contacting Server ([batch_]add_json): {}'.format(e)))
766 return (1,
None,
None)
770 except ServerError
as e:
772 error(
_(
'Error contacting server: %s') % e)
773 return (1,
None,
None)
779 pub_uuid = server_response.decode(
'latin1')
783 admin_token = self.
session.
get(smoonURL +
'tokens/admin_token_json?uuid=%s' % self.
host.UUID,
784 proxies=proxies, timeout=timeout)
785 except EXCEPTIONS
as e:
787 error(
_(
'An error has occured while contacting the server: %s' % e))
791 admin_obj = json.loads(admin_token.content)
792 except json.JSONDecodeError:
794 error(
_(
'Incorrect server response. Expected a JSON string'))
795 return (1,
None,
None)
797 if admin_obj[
'prefered_protocol']
in supported_protocols:
798 prefered_protocol = admin_obj[
'prefered_protocol']
801 error(
_(
'Wrong version, server incapable of handling your client'))
802 return (1,
None,
None)
803 admin = admin_obj[
'token']
805 if not admin_token_file ==
'' :
808 return (0, pub_uuid, admin)
815 new_uuid = self.
session.
get(smoonURL +
'client/regenerate_pub_uuid?uuid=%s' % self.
host.UUID,
816 proxies=proxies, timeout=timeout)
817 except EXCEPTIONS
as e:
821 response_dict = new_uuid.json()
822 except Exception
as e:
825 raise ServerError(
_(
'Reply from server could not be interpreted'))
828 pub_uuid = response_dict[
'pub_uuid']
831 raise ServerError(
_(
'Reply from server could not be interpreted'))
838 _(
'OS'):self.
host.os,
839 _(
'Default run level'):self.
host.defaultRunlevel,
840 _(
'Language'):self.
host.language,
843 for k, v
in d.items():
844 lines.append(
'%s: %s' % (k, v))
846 return '\n'.join(lines)
850 for i, (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description) \
854 lines.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, \
855 SubsysDeviceID, Bus, Driver, Type, Description))
857 return '\n'.join(lines)
861 lines.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
862 for i, v
in enumerate(self.
fss):
867 return '\n'.join(lines)
871 return v[
'rst_excerpt']
872 return "No data, yet"
877 printBuffer.append(
'# ' +
_(
'This is a Smolt report shown within your default pager.'))
878 printBuffer.append(
'# ' +
_(
'Below you can see what data you will submit to the server.'))
879 printBuffer.append(
'# ' +
_(
'To get back to Smolt exit the pager (try hitting "q").'))
880 printBuffer.append(
'#')
881 printBuffer.append(
'# ' +
_(
'NOTE: Editing this file does not change the data submitted.'))
882 printBuffer.append(
'')
883 printBuffer.append(
'')
885 printBuffer.append(
_(
'General'))
886 printBuffer.append(
'=================================')
889 printBuffer.append(
'%s: %s' % (label, data))
890 except UnicodeDecodeError:
892 printBuffer.append(
'%s: %s' % (
unicode(label,
'utf-8'), data))
893 except UnicodeDecodeError:
894 printBuffer.append(
'%r: %r' % (label, data))
897 printBuffer.append(
'')
898 printBuffer.append(
'')
899 printBuffer.append(
_(
'Devices'))
900 printBuffer.append(
'=================================')
902 for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
in self.
deviceIter():
903 printBuffer.append(
'(%s:%s:%s:%s) %s, %s, %s, %s' % (VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description))
905 printBuffer.append(
'')
906 printBuffer.append(
'')
907 printBuffer.append(
_(
'Filesystem Information'))
908 printBuffer.append(
'=================================')
909 printBuffer.append(
'device mtpt type bsize frsize blocks bfree bavail file ffree favail')
910 printBuffer.append(
'-------------------------------------------------------------------')
912 printBuffer.append(str(fs))
915 printBuffer.append(
'')
916 printBuffer.append(
'')
917 printBuffer.append(v[
'rst'])
919 printBuffer.append(
'')
924 '''Iterate over host information.'''
925 yield _(
'UUID'), self.
host.UUID
926 yield _(
'OS'), self.
host.os
927 yield _(
'Default run level'), self.
host.defaultRunlevel
928 yield _(
'Language'), self.
host.language
929 yield _(
'Platform'), self.
host.platform
930 yield _(
'BogoMIPS'), self.
host.bogomips
931 yield _(
'CPU Vendor'), self.
host.cpuVendor
932 yield _(
'CPU Model'), self.
host.cpuModel
933 yield _(
'CPU Stepping'), self.
host.cpu_stepping
934 yield _(
'CPU Family'), self.
host.cpu_family
935 yield _(
'CPU Model Num'), self.
host.cpu_model_num
936 yield _(
'Number of CPUs'), self.
host.numCpus
937 yield _(
'CPU Speed'), self.
host.cpuSpeed
938 yield _(
'System Memory'), self.
host.systemMemory
939 yield _(
'System Swap'), self.
host.systemSwap
940 yield _(
'Vendor'), self.
host.systemVendor
941 yield _(
'System'), self.
host.systemModel
942 yield _(
'Form factor'), self.
host.formfactor
943 yield _(
'Kernel'), self.
host.kernelVersion
944 yield _(
'SELinux Enabled'), self.
host.selinux_enabled
945 yield _(
'SELinux Policy'), self.
host.selinux_policy
946 yield _(
'SELinux Enforce'), self.
host.selinux_enforce
949 '''Iterate over our devices.'''
952 VendorID = self.
devices[device].vendorid
953 DeviceID = self.
devices[device].deviceid
954 SubsysVendorID = self.
devices[device].subsysvendorid
955 SubsysDeviceID = self.
devices[device].subsysdeviceid
956 Driver = self.
devices[device].driver
957 Type = self.
devices[device].type
958 Description = self.
devices[device].description
961 yield VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description
966 def get_entry(a, entry):
972 if not os.access(
"/proc/cpuinfo", os.R_OK):
975 cpulist = open(
"/proc/cpuinfo",
"r").
read()
976 uname = os.uname()[4].lower()
984 hwdict = {
'class':
"CPU",
985 'desc' :
"Processor",
987 if uname[0] ==
"i" and uname[-2:] ==
"86" or (uname ==
"x86_64"):
991 for cpu
in cpulist.split(
"\n\n"):
997 for cpu_attr
in cpu.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
1007 if uname ==
"x86_64":
1008 hwdict[
'platform'] =
'x86_64'
1010 hwdict[
'platform'] =
"i386"
1012 hwdict[
'count'] = count
1013 hwdict[
'type'] = get_entry(tmpdict,
'vendor_id')
1014 hwdict[
'model'] = get_entry(tmpdict,
'model name')
1015 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu family')
1016 hwdict[
'model_ver'] = get_entry(tmpdict,
'model')
1017 hwdict[
'cpu_stepping'] = get_entry(tmpdict,
'stepping')
1018 hwdict[
'cpu_family'] = get_entry(tmpdict,
'cpu family')
1019 hwdict[
'cpu_model_num'] = get_entry(tmpdict,
'model')
1020 hwdict[
'cache'] = get_entry(tmpdict,
'cache size')
1021 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1022 hwdict[
'other'] = get_entry(tmpdict,
'flags')
1023 mhz_speed = get_entry(tmpdict,
'cpu mhz')
1028 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1030 hwdict[
'speed'] = -1
1033 elif uname
in[
"alpha",
"alphaev6"]:
1036 for cpu_attr
in cpulist.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'] =
"alpha"
1047 hwdict[
'count'] = get_entry(tmpdict,
'cpus detected')
1048 hwdict[
'type'] = get_entry(tmpdict,
'cpu')
1049 hwdict[
'model'] = get_entry(tmpdict,
'cpu model')
1050 hwdict[
'model_number'] = get_entry(tmpdict,
'cpu variation')
1051 hwdict[
'model_version'] =
"%s/%s" % (get_entry(tmpdict,
'system type'),
1052 get_entry(tmpdict,
'system variation'))
1053 hwdict[
'model_rev'] = get_entry(tmpdict,
'cpu revision')
1054 hwdict[
'cache'] =
""
1055 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1056 hwdict[
'other'] = get_entry(tmpdict,
'platform string')
1057 hz_speed = get_entry(tmpdict,
'cycle frequency [Hz]')
1059 hz_speed = hz_speed.split()
1061 hwdict[
'speed'] = int(round(float(hz_speed[0]))) / 1000000
1063 hwdict[
'speed'] = -1
1065 elif uname
in [
"ia64"]:
1068 for cpu
in cpulist.split(
"\n\n"):
1075 for cpu_attr
in cpu.split(
"\n"):
1076 if not len(cpu_attr):
1078 vals = cpu_attr.split(
":")
1082 name, value = vals[0].strip(), vals[1].strip()
1083 tmpdict[name.lower()] = value.lower()
1085 hwdict[
'platform'] = uname
1086 hwdict[
'count'] = count
1087 hwdict[
'type'] = get_entry(tmpdict,
'vendor')
1088 hwdict[
'model'] = get_entry(tmpdict,
'family')
1089 hwdict[
'model_ver'] = get_entry(tmpdict,
'archrev')
1090 hwdict[
'model_rev'] = get_entry(tmpdict,
'revision')
1091 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1092 mhz_speed = tmpdict[
'cpu mhz']
1094 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1096 hwdict[
'speed'] = -1
1097 hwdict[
'other'] = get_entry(tmpdict,
'features')
1099 elif uname
in [
'ppc64',
'ppc']:
1102 for cpu
in cpulist.split(
"processor"):
1109 for cpu_attr
in cpu.split(
"\n"):
1110 if not len(cpu_attr):
1112 vals = cpu_attr.split(
":")
1116 name, value = vals[0].strip(), vals[1].strip()
1117 tmpdict[name.lower()] = value.lower()
1119 hwdict[
'platform'] = uname
1120 hwdict[
'count'] = count
1121 hwdict[
'model'] = get_entry(tmpdict,
"cpu")
1122 hwdict[
'model_ver'] = get_entry(tmpdict,
'revision')
1123 hwdict[
'bogomips'] = get_entry(tmpdict,
'bogomips')
1124 hwdict[
'vendor'] = get_entry(tmpdict,
'machine')
1125 if get_entry(tmpdict,
'cpu').startswith(
'ppc970'):
1126 hwdict[
'type'] =
'IBM'
1128 hwdict[
'type'] = get_entry(tmpdict,
'platform')
1129 hwdict[
'system'] = get_entry(tmpdict,
'detected as')
1131 mhz_speed = get_entry(tmpdict,
'clock')[:-3]
1133 hwdict[
'speed'] = int(round(float(mhz_speed)) - 1)
1135 hwdict[
'speed'] = -1
1137 elif uname
in [
"sparc64",
"sparc"]:
1140 for cpu
in cpulist.split(
"\n\n"):
1144 for cpu_attr
in cpu.split(
"\n"):
1145 if not len(cpu_attr):
1147 vals = cpu_attr.split(
":")
1151 name, value = vals[0].strip(), vals[1].strip()
1152 if name.endswith(
'Bogo'):
1154 bogomips = int(round(float(value)) )
1157 tmpdict[name.lower()] = value.lower()
1159 if not os.access(
"/proc/openprom/banner-name", os.R_OK):
1161 if os.access(
"/proc/openprom/banner-name", os.R_OK):
1162 with open(
"/proc/openprom/banner-name",
"r")
as banner_name:
1164 hwdict[
'platform'] = uname
1165 hwdict[
'count'] = get_entry(tmpdict,
'ncpus probed')
1166 hwdict[
'model'] = get_entry(tmpdict,
'cpu')
1167 hwdict[
'type'] = get_entry(tmpdict,
'type')
1168 hwdict[
'model_ver'] = get_entry(tmpdict,
'type')
1169 hwdict[
'bogomips'] = bogomips
1170 hwdict[
'vendor'] =
'sun'
1171 hwdict[
'cache'] =
""
1172 speed = int(round(float(bogomips))) / 2
1173 hwdict[
'speed'] = speed
1174 hwdict[
'system'] = system
1178 hwdict[
'platform'] = uname
1180 hwdict[
'type'] = uname
1181 hwdict[
'model'] = uname
1182 hwdict[
'model_number'] =
""
1183 hwdict[
'model_ver'] =
""
1184 hwdict[
'model_rev'] =
""
1185 hwdict[
'cache'] =
""
1186 hwdict[
'bogomips'] =
""
1187 hwdict[
'other'] =
""
1191 if not hwdict[
"count"]:
1195 hwdict[
"count"] = int(hwdict[
"count"])
1199 if hwdict[
"count"] == 0:
1208 if os.path.exists(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq'):
1209 with open(
'/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq')
as cpu_m_freq:
1210 hwdict[
'speed'] = int(cpu_m_freq.read().strip()) / 1000
1220 if kernel[:2] ==
"5.":
1222 if kernel[:2] ==
"4.":
1224 if kernel[:2] ==
"3.":
1226 if kernel[:3] ==
"2.6":
1228 if kernel[:3] ==
"2.4":
1232 if not os.access(
"/proc/meminfo", os.R_OK):
1235 with open(
"/proc/meminfo",
"r")
as m_info:
1236 meminfo = m_info.read()
1237 lines = meminfo.split(
"\n")
1239 memlist = curline.split()
1241 memdict[
'class'] =
"MEMORY"
1242 megs =
long(memlist[1])/(1024*1024)
1244 megs = megs + (4 - (megs % 4))
1246 megs = megs + (16 - (megs % 16))
1247 memdict[
'ram'] = str(megs)
1249 memlist = curline.split()
1251 megs =
long(memlist[1])/(1024*1024)
1252 memdict[
'swap'] = str(megs)
1256 if not os.access(
"/proc/meminfo", os.R_OK):
1258 with open(
"/proc/meminfo",
"r")
as m_info:
1259 meminfo = m_info.read()
1260 lines = meminfo.split(
"\n")
1263 blobs = line.split(
":", 1)
1268 value = blobs[1].strip()
1272 memdict[
"class"] =
"MEMORY"
1274 total_str = dict[
'MemTotal']
1275 blips = total_str.split(
" ")
1276 total_k =
long(blips[0])
1277 megs =
long(total_k/(1024))
1279 swap_str = dict[
'SwapTotal']
1280 blips = swap_str.split(
' ')
1281 swap_k =
long(blips[0])
1282 swap_megs =
long(swap_k/(1024))
1284 memdict[
'ram'] = str(megs)
1285 memdict[
'swap'] = str(swap_megs)
1299 except SystemBusError
as e:
1300 error(
_(
'Error:') +
' ' + e.msg)
1301 if e.hint
is not None:
1302 error(
'\t' +
_(
'Hint:') +
' ' + e.hint)
1307 return smoonURL +
'client/show/%s' % pub_uuid
1311 with open(hw_uuid_file)
as hw_uuid:
1312 UUID = hw_uuid.read().strip()
1313 except (FileNotFoundError, IOError):
1315 with open(
'/proc/sys/kernel/random/uuid')
as rand_uuid:
1316 UUID = rand_uuid.read().strip()
1317 with open(hw_uuid_file,
'w')
as write_uuid:
1318 write_uuid.write(UUID)
1319 except (FileNotFoundError, IOError):
1320 sys.stderr.write(
_(
'Unable to determine UUID of system!\n'))
1321 raise UUIDError(
'Unable to get/save UUID. file = %s. Please run once as root.' % hw_uuid_file)
1324 def read_pub_uuid(uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeout=timeout, silent=False):
1325 smoonURLparsed=urlparse(smoonURL)
1326 res = uuiddb.get_pub_uuid(uuid, smoonURLparsed.netloc)
1331 o = requests.get(smoonURL +
'client/pub_uuid?uuid=%s' % uuid,
1332 proxies=proxies, timeout=timeout)
1334 uuiddb.set_pub_uuid(uuid, smoonURLparsed.netloc, pudict[
"pub_uuid"])
1335 return pudict[
"pub_uuid"]
1336 except Exception
as e:
1338 error(
_(
'Error determining public UUID: %s') % e)
1339 sys.stderr.write(
_(
"Unable to determine Public UUID! This could be a network error or you've\n"))
1340 sys.stderr.write(
_(
"not submitted your profile yet.\n"))
1341 raise PubUUIDError(
'Could not determine Public UUID!\n')