basic module parsing and threading
This commit is contained in:
		
							parent
							
								
									d3e2b6ec87
								
							
						
					
					
						commit
						89fd0c84b5
					
				
					 1 changed files with 24 additions and 0 deletions
				
			
		
							
								
								
									
										24
									
								
								modules.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								modules.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					from yaml import safe_load
 | 
				
			||||||
 | 
					from io import open
 | 
				
			||||||
 | 
					from threading import Thread
 | 
				
			||||||
 | 
					from subprocess import run
 | 
				
			||||||
 | 
					from time import sleep
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def module_thread(cmd, refresh, pre, post):
 | 
				
			||||||
 | 
					    while True:
 | 
				
			||||||
 | 
					        print(pre, end='')
 | 
				
			||||||
 | 
					        cmd_output = run(cmd, shell=True, capture_output=True, text=True).stdout
 | 
				
			||||||
 | 
					        print(cmd_output.strip(), end='')
 | 
				
			||||||
 | 
					        print(post)
 | 
				
			||||||
 | 
					        sleep(refresh/1000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					with open("./testing_config.yml", 'r', encoding='utf8') as file:
 | 
				
			||||||
 | 
					    config_file = safe_load(file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					modules = config_file['bar']['modules']
 | 
				
			||||||
 | 
					for module in modules:
 | 
				
			||||||
 | 
					    cmd = modules[module]['command']
 | 
				
			||||||
 | 
					    refresh = modules[module]['refresh']
 | 
				
			||||||
 | 
					    x = Thread(target=module_thread, args=(cmd, refresh, '', ''))
 | 
				
			||||||
 | 
					    x.start()
 | 
				
			||||||
		Loading…
	
		Reference in a new issue