import dmidecode import platform import os PLUGIN_PATH="/var/lib/n4d-hardware/" class Hardware: def __init__(self): self.productName="" self.motherBoard="" self.serialNumber="" self.kernelVersion="" self.architecture="" self.refresh() #__init__ def startup(self,options): is_boot=options["boot"] if(is_boot): self.run_boot_scripts() #pass def refresh(self): #extracting dmi information data=dmidecode.system() for handle in data: chunk=data[handle] if(chunk['dmi_type']==1): self.productName=chunk['data']['Product Name'] self.serialNumber=chunk['data']['Serial Number'] #Mother board information data=dmidecode.baseboard() for handle in data: chunk=data[handle] if(chunk['dmi_type']==2): self.motherBoard=chunk['data']['Product Name'] #platform information self.kernelVersion=platform.release() self.architecture=platform.architecture()[0] #refresh def get_product_name(self): return self.productName #get_product_name def get_serial_number(self): return self.serialNumber #get_serial_number def get_mother_board(self): return self.motherBoard #get_mother_board def get_kernel_version(self): return self.kernelVersion #get_kernel_version def get_architecture(self): return self.architecture #get_architecture def run_scripts(self,path,params=[]): if(os.path.exists(PLUGIN_PATH+"/"+path)==False): return product_name=self.get_product_name() serial_number=self.get_serial_number() mother_board=self.get_mother_board() architecture=self.get_architecture() version=self.get_kernel_version().split(".") major_version=int(version[0]) minor_version=int(version[1]) files=os.listdir(PLUGIN_PATH+"/"+path) files.sort() for f in files: cmd="{0} {1} {2} {3} {4} {5} {6}".format(PLUGIN_PATH+"/"+path+"/"+f,product_name,serial_number,mother_board,architecture,major_version,minor_version) for p in params: cmd=cmd+" "+p os.system(cmd) #run_scripts def run_boot_scripts(self): self.run_scripts("boot.d") #run_boot_scripts def run_xdg_scripts(self,display): self.run_scripts("xdg.d",[display]) #run_xdg_scripts def run_shutdown_scripts(self): self.run_scripts("shutdown.d") #run_shutdown_scripts if __name__=="__main__": pass