implement a save() for modules, use it in MegaHAL to sync brain to disk
This commit is contained in:
		
							parent
							
								
									5c0323fc26
								
							
						
					
					
						commit
						0878c8809d
					
				| @ -92,6 +92,13 @@ class Module(object): | ||||
|         self.server.remove_global_handler('pubmsg', self.on_pubmsg) | ||||
|         self.server.remove_global_handler('privmsg', self.on_privmsg) | ||||
| 
 | ||||
|     def save(self): | ||||
|         """ | ||||
|         Save whatever the module may need to save. Sync files, etc. | ||||
| 
 | ||||
|         Implement this if you need it. | ||||
|         """ | ||||
| 
 | ||||
|     def shutdown(self): | ||||
|         """ | ||||
|         Do pre-deletion type cleanup. | ||||
|  | ||||
| @ -143,7 +143,11 @@ class IrcAdmin(Module): | ||||
|     def sub_save_config(self, connection, event, nick, userhost, replypath, what, admin_unlocked): | ||||
|         with open('dr.botzo.cfg', 'w') as cfg: | ||||
|             self.config.write(cfg) | ||||
|         replystr = 'Saved config file.' | ||||
| 
 | ||||
|         for module in self.modlist: | ||||
|             module.save() | ||||
| 
 | ||||
|         replystr = 'Saved.' | ||||
|         return self.reply(connection, replypath, replystr) | ||||
| 
 | ||||
|     def sub_change_nick(self, connection, event, nick, userhost, replypath, what, admin_unlocked): | ||||
|  | ||||
| @ -37,9 +37,15 @@ class MegaHAL(Module): | ||||
| 
 | ||||
|         mh_python.initbrain() | ||||
| 
 | ||||
|     def save(self): | ||||
|         """ | ||||
|         Sync the megahal brain. | ||||
|         """ | ||||
|         mh_python.cleanup() | ||||
| 
 | ||||
|     def shutdown(self): | ||||
|         """ | ||||
|         Close the megahal brain. | ||||
|         Sync the megahal brain. | ||||
|         """ | ||||
|         mh_python.cleanup() | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user