def getHWInfos(self): try: import sysinfo except: dlg = wx.MessageDialog(self, "You must install pywin32 first.\nYou can find the setup in INSTALLDIR\\tools\\3rdparty\\pywin32-setup.exe (This means you must install it by hand!)\nPlease note that you must restart this program after the pywin installation.", "Error", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() self.Close() return "" txt = "==========================\n" txt += "Hardware Information:\n" txt += "==========================\n" try: dlg = wx.MessageDialog(self, "This program will now try to figure out some Hardware Information. That can take a minute or so.", "Notice", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() hw = sysinfo.hardware() except: pass try: txt += "Motherboard: %s\n" % hw.motherboard.product except: pass try: txt += "Motherboard Vendor: %s\n" % hw.motherboard.vendor except: pass try: txt += "CPU: %s\n" % hw.cpu.product except: pass try: txt += "CPU Vendor: %s\n" % hw.cpu.vendor except: pass try: txt += "CPU Speed: %s\n" % hw.cpu.frequency except: pass try: txt += "Video memory: %.2f MB\n" % (float(hw.video_board.memory) / 1024 / 1024) except: pass try: txt += "HW Memory: %.2f MB\n" % (float(hw.memory.size) / 1024) except: pass try: txt += "GFX card: %s\n" % hw.video_board.product except: pass try: txt += "Resolution: %s@%d\n" % (hw.video_board.resolution, int(hw.video_board.width)) except: pass try: txt += "Sound card: %s\n" % hw.sound_board.product except: pass return txt
def __init__(self, param_cfg): logger.debug("Instantiating config.load") net = sysinfo.network() interf = net.interface(cur_config['interface']) last_user = net.last_user self.remote_raw_cfg = get_config(self.config_info) logger.debug("remote_raw_cfg populated") logger.debug("LAST LOGON:" + last_user) #print "Remote raw config:", remote_raw_cfg self.remote_cfg['patrimony_collection'] = parse_remote_raw_cfg( 'patrimony_collection', '<cs_coleta_patrimonio>\s*s\s*<\/cs_coleta_patrimonio>', self.remote_raw_cfg, 'boolean') self.remote_cfg['hardware_collection'] = parse_remote_raw_cfg( 'hardware_collection', '<cs_coleta_hardware>\s*S\s*<\/cs_coleta_hardware>', self.remote_raw_cfg, 'boolean') self.remote_cfg['disk_collection'] = parse_remote_raw_cfg( 'disk_collection', '<cs_coleta_unid_disc>\s*S\s*<\/cs_coleta_unid_disc>', self.remote_raw_cfg, 'boolean') self.remote_cfg['ignore_macs'] = parse_remote_raw_cfg( 'ignore_macs', '<te_enderecos_mac_invalidos>(?P<mac_invalidos>[^<]*)<\/te_enderecos_mac_invalidos>', self.remote_raw_cfg, 'string') logger.debug("Getting network data from sysinfo.network()") if get_hard: logger.debug("Getting hardware data from sysinfo.hardware()") hw = sysinfo.hardware() # Necessary changes # Update: sysinfo does not provide the unit anymore, so we don't # need the .replace('', '') anymore. ram_size = str(int(hw.memory.size.replace(' bytes', '')) / 1048576) video_ram_size = str(int(hw.video_board.memory.replace(' bytes', '')) / 1048576) cpu_frequency = str(int(hw.cpu.frequency) / 1048576) # CACIC used - as a separator for MAC's mac_address = interf.mac_address.replace(':','-') logger.debug("Populating 'config_info' dictionary") self.config_info = { 'te_node_address' : mac_address, 'id_so' : '9', 'id_ip_rede' : interf.ip_network, 'te_nome_computador' : net.hostname, 'te_ip' : interf.ip_addresses[0], 'te_versao_cacic' : 'pyc', } # FIXME: use a "get_patrimony" config if param_cfg.get('get_patr', False): logger.debug( "Getting patrimony data from cacic.extensions.patrimony" ) patrim = patrimony() self.patr_info = patrim.ask(patrim.labels, patrim.uon1, patrim.uon2) self.patr_info.update(self.config_info) # FIXME: if mac_address is not in remote_cfg['ignore_macs'] if get_services: logger.debug("Getting smb data from sysinfo.services.smb()") smb = sysinfo.services.smb() #FIXME: are shares info defined by get_services too? smb_shares = smb.smb_shares share_xml = '<?xml version="1.0" encoding="ISO-8859-1"?><comparts>' for share in smb_shares: if share['type'] == 'printer': type = 'I' else: type = 'D' share_xml += '<compart><nm_compartilhamento>' + share['name']+\ '</nm_compartilhamento><nm_dir_compart></nm_dir_compart><cs_tipo_compart>' + \ type + '</cs_tipo_compart><te_comentario>' + share.get('comment', '') + \ '</te_comentario></compart>' share_xml += '</comparts>' self.share_info = { 'compartilhamentos' : share_xml } self.share_info.update(self.config_info) if get_software: logger.debug("Getting software packages data") pkgs = sysinfo.software.packages() packages = '' for p in pkgs.installed: packages += p + "#" env = sysinfo.misc.env() environ = '' for var, value in env.variables.iteritems(): environ += var + '=' + value + '#' logger.debug("Populating 'software_info' dictionary") self.software_info = self.config_info.copy() self.software_info['te_inventario_softwares'] = packages self.software_info['te_variaveis_ambiente'] = environ #print "PACKAGES:", packages if get_services and get_hard: logger.debug("Populating 'info' dictionary") # simulating ternary operator :) cdrom = len(hw.dvd_reader.product) > 0 and hw.dvd_reader.product \ or hw.dvd_ram_writer.product self.info = { 'te_node_address' : mac_address, 'id_so' : '9', 'id_ip_rede' : interf.ip_network, 'te_nome_computador' : net.hostname, 'te_ip' : interf.ip_addresses[0], 'te_versao_cacic' : 'pyc', 'te_mascara' : interf.netmask, 'te_gateway' : net.default_gateway, 'te_serv_dhcp' : interf.dhcp_server, 'te_nome_host' : net.hostname, 'te_origem_mac' : 'ifconfig', 'te_dns_primario' : net.dnsresolvers[0], 'te_dns_secundario' : net.dnsresolvers[1], 'te_dominio_dns' : net.dnsdomain, 'te_dominio_windows' : last_user, 'te_wins_primario' : smb.wins_servers[0], 'te_wins_secundario' : smb.wins_servers[1], 'te_workgroup' : smb.workgroup, #hardware 'te_placa_mae_desc' : hw.motherboard.product, 'te_placa_mae_fabricante' : hw.motherboard.vendor, 'te_cpu_serial' : '', 'te_cpu_desc' : hw.cpu.product, 'te_cpu_fabricante' : hw.cpu.vendor, 'te_cpu_freq' : cpu_frequency, 'te_placa_video_desc' : hw.video_board.product, 'qt_placa_video_mem' : video_ram_size, 'qt_placa_video_cores' : hw.video_board.width, 'te_placa_som_desc' : hw.sound_board.product, 'te_teclado_desc' : hw.keyboard.model, 'te_bios_desc' : hw.bios.vendor + hw.bios.version, 'te_bios_fabricante' : hw.bios.vendor, 'te_bios_data' : hw.bios.version, 'te_cdrom_desc' : cdrom, 'te_modem_desc' : hw.modem.vendor + hw.modem.product, 'te_mouse_desc' : hw.mouse.product + hw.mouse.vendor, 'qt_mem_ram' : ram_size, # 'te_mem_ram_desc' : 'te_placa_rede_desc' : hw.ethernet_board.vendor + hw.ethernet_board.product }
format = "%(asctime)s %(levelname)s %(message)s" sysinfo_log = logging.getLogger("sysinfo") sysinfo_log.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter(format) ch.setFormatter(formatter) sysinfo_log.addHandler(ch) net = sysinfo.network() interf = net.interface('eth0') last_user = net.last_user hw = sysinfo.hardware() smb = sysinfo.services.smb() pkgs = sysinfo.software.packages() env = sysinfo.misc.env() print hw.motherboard.product print hw.motherboard.vendor print hw.cpu.product print hw.cpu.vendor print hw.cpu.frequency print hw.video_board.memory print hw.memory.size print hw.video_board.product