allow additional db parameters when setting up storage
This commit is contained in:
		
							parent
							
								
									1eff3d2c8b
								
							
						
					
					
						commit
						efd47419a0
					
				
					 2 changed files with 12 additions and 3 deletions
				
			
		|  | @ -69,9 +69,13 @@ class StorageFactory(object): | ||||||
|          return self.engine.connect |          return self.engine.connect | ||||||
| 
 | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def getEngine(dbtype, dbname, user, pw, host='localhost', port=5432, **kw): |     def getEngine(dbtype, dbname, user, pw, **kw): | ||||||
|         return create_engine('%s:///%s' % (dbtype, dbname), **kw) |         return create_engine('%s:///%s' % (dbtype, dbname), **kw) | ||||||
| 
 | 
 | ||||||
|  |     def engineFromConfig(self, config): | ||||||
|  |         return self.getEngine(config.dbengine, config.dbname,  | ||||||
|  |                               config.dbuser, config.dbpassword)  | ||||||
|  | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def mark_changed(session): |     def mark_changed(session): | ||||||
|         pass |         pass | ||||||
|  | @ -86,8 +90,7 @@ class StorageFactory(object): | ||||||
|     storageClass = Storage |     storageClass = Storage | ||||||
| 
 | 
 | ||||||
|     def __init__(self, config, storageClass=None): |     def __init__(self, config, storageClass=None): | ||||||
|         self.engine = self.getEngine(config.dbengine, config.dbname,  |         self.engine = self.engineFromConfig(config) | ||||||
|                                      config.dbuser, config.dbpassword)  |  | ||||||
|         self.Session = self.sessionFactory() |         self.Session = self.sessionFactory() | ||||||
|         if storageClass is not None: |         if storageClass is not None: | ||||||
|             self.storageClass = storageClass |             self.storageClass = storageClass | ||||||
|  |  | ||||||
|  | @ -24,6 +24,12 @@ class StorageFactory(StorageFactory): | ||||||
|         return create_engine('%s://%s:%s@%s:%s/%s' % ( |         return create_engine('%s://%s:%s@%s:%s/%s' % ( | ||||||
|             dbtype, user, pw, host, port, dbname), **kw) |             dbtype, user, pw, host, port, dbname), **kw) | ||||||
| 
 | 
 | ||||||
|  |     def engineFromConfig(self, config): | ||||||
|  |         return self.getEngine(config.dbengine, config.dbname,  | ||||||
|  |                               config.dbuser, config.dbpassword, | ||||||
|  |                               host=getattr(config, 'dbhost', 'localhost'), | ||||||
|  |                               port=getattr(config, 'dbport', 5432)) | ||||||
|  | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def mark_changed(session): |     def mark_changed(session): | ||||||
|         return mark_changed(session) |         return mark_changed(session) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue