1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- """
- Factory to create Database instances
- A Generic interface for all DB engines.
- Usage:
- import pwman.data.factory as DBFactory
- db = DBFactory.create(params)
- db.open()
- .....
- """
- from pwman.data.database import DatabaseException
- from pwman.data.drivers import sqlite
- from pwman.data.drivers import osqlite
- def check_db_version(type):
- if type == "SQLite":
- ver = sqlite.check_db_version()
- return ver
-
- def create(dbtype, version=None, filename=None):
- """
- create(params) -> Database
- Create a Database instance.
- 'type' can only be 'SQLite' at the moment
- """
- if dbtype == "SQLite":
- from pwman.data.drivers import sqlite
- if version == 0.4 and filename:
- db = sqlite.SQLiteDatabaseNewForm(filename)
- elif version == 0.4:
- db = sqlite.SQLiteDatabaseNewForm()
- elif dbtype == "Postgresql":
- try:
- from pwman.data.drivers import postgresql
- db = postgresql.PostgresqlDatabase()
- except ImportError:
- raise DatabaseException("python-pygresql not installed")
- elif dbtype == "MySQL":
- try:
- from pwman.data.drivers import mysql
- db = mysql.MySQLDatabase()
- except ImportError:
- raise DatabaseException("python-mysqldb not installed")
- else:
- raise DatabaseException("Unknown database type specified")
- return db
|