Public Member Functions | |
| def | __init__ |
| def | setup_ui |
| def | set_filename |
| def | configure_engine |
| def | engine_failure |
| def | configure_engine_sqlite3 |
| def | configure_engine_mysql |
| def | configure_engine_postgresql |
| def | configure_engine_ado_mssql |
| def | accept |
Public Attributes | |
| configured | |
Static Public Attributes | |
| list | backends = ["sqlite3", "mysql", "postgresql_psycopg2", "ado_mssql"] |
| dictionary | backend_module |
| dictionary | backend_homepage |
| dictionary | backend_dist |
| def py::gui::configure::datasource::__init__ | ( | self, | ||
parent = None | ||||
| ) |
| def py::gui::configure::datasource::setup_ui | ( | self | ) |
00275 : 00276 self.setupUi(self) 00277 QObject.connect(self.engine, SIGNAL("currentIndexChanged(int)"), self.configure_engine) 00278 self.engine.setCurrentIndex(self.backends.index(qocfg.get_db_engine())) 00279 QObject.connect(self.browse, SIGNAL("clicked()"), self.set_filename) 00280 self.configure_engine() 00281 def set_filename( self ) :
| def py::gui::configure::datasource::set_filename | ( | self | ) |
| def py::gui::configure::datasource::configure_engine | ( | self | ) |
00287 : 00288 backend = self.backends[self.engine.currentIndex()] 00289 print backend 00290 try : 00291 __import__(self.backend_module[backend]) 00292 except ImportError : 00293 self.okButton.setEnabled(False) 00294 self.engine_failure(backend) 00295 return 00296 getattr(self, "configure_engine_%s"%backend)() 00297 self.configured = True 00298 self.okButton.setEnabled(True) 00299 def engine_failure( self, backend ) :
| def py::gui::configure::datasource::engine_failure | ( | self, | ||
| backend | ||||
| ) |
00300 : 00301 self.stacked_widget.setCurrentIndex(0) 00302 self.err_module.setText(self.backend_module[backend]) 00303 self.err_homepage.setText(self.backend_homepage[backend]) 00304 dist = qocfg.get_distribution() 00305 if not dist or dist in ["win"] or not self.backend_dist[dist].has_key(backend) : 00306 self.err_package_intro.setVisible(False) 00307 self.err_package.setVisible(False) 00308 else : 00309 self.err_package_intro.setVisible(True) 00310 self.err_package.setVisible(True) 00311 self.err_package.setText(self.backend_dist[dist][backend]) 00312 def configure_engine_sqlite3( self ) :
| def py::gui::configure::datasource::configure_engine_sqlite3 | ( | self | ) |
| def py::gui::configure::datasource::configure_engine_mysql | ( | self | ) |
00320 : 00321 self.stacked_widget.setCurrentIndex(2) 00322 if not self.configured : 00323 self.host.setText(qocfg.get_db_host()) 00324 try : 00325 self.port.setValue(int(qocfg.get_db_port())) 00326 except ValueError : 00327 pass 00328 self.database.setText(qocfg.get_db_name()) 00329 self.user.setText(qocfg.get_db_user()) 00330 self.password.setText(qocfg.get_db_password()) 00331 def configure_engine_postgresql( self ) :
| def py::gui::configure::datasource::configure_engine_postgresql | ( | self | ) |
| def py::gui::configure::datasource::configure_engine_ado_mssql | ( | self | ) |
| def py::gui::configure::datasource::accept | ( | self | ) |
00338 : 00339 backend = self.backends[self.engine.currentIndex()] 00340 if backend != qocfg.get_db_engine() : 00341 00342 # 1. create savepoint 00343 import gui.dialog 00344 #gui.dialog.create_savepoint(self).exec_() 00345 00346 # 2. change db connection 00347 if backend == "sqlite3" : 00348 db_name = unicode(self.sqlite_filename.text()) 00349 db_host = "" 00350 db_port = "" 00351 db_user = "" 00352 db_password = "" 00353 else : 00354 db_name = unicode(self.database.text()) 00355 db_user = unicode(self.user.text()) 00356 db_password = unicode(self.password.text()) 00357 db_host = unicode(self.host.text()) 00358 db_port = self.port.value() 00359 if db_port : 00360 db_port = str(db_port) 00361 else : 00362 db_port = "" 00363 00364 import django.db 00365 import django.conf 00366 django.db.connection.close() 00367 00368 django.conf.settings.DATABASE_ENGINE = backend 00369 django.conf.settings.DATABASE_NAME = db_name 00370 django.conf.settings.DATABASE_USER = db_user 00371 django.conf.settings.DATABASE_PASSWORD = db_password 00372 django.conf.settings.DATABASE_HOST = db_host 00373 django.conf.settings.DATABASE_PORT = db_port 00374 django.conf.settings.DATABASE_OPTIONS = {} 00375 if backend == 'mysql' : 00376 django.conf.settings.DATABASE_OPTIONS["charset"] = "utf8" 00377 reload(django.db) 00378 00379 import django.db.models 00380 pmods = [ 00381 (django.db, ["transaction"]), 00382 (django.db.models, ["query", "base"]), 00383 ] 00384 mattrs = [ 00385 (django.db, ["connection", "backend"]), 00386 (django.conf, ["settings"]), 00387 ] 00388 for pmod, mods in pmods : 00389 for mod in mods : 00390 __import__(pmod.__name__+"."+mod) 00391 m = getattr(pmod, mod) 00392 for msrc, attrs in mattrs : 00393 for a in attrs : 00394 if hasattr(m, a) : 00395 setattr(m, a, getattr(msrc, a)) 00396 00397 # 3. restore savepoint 00398 import qodb.transaction 00399 00400 @qodb.transaction.commit_on_success 00401 def fill_db() : 00402 import qodb.admin 00403 qodb.admin.check_and_repair(qo.notifier.null_notifier) 00404 if not gui.dialog.step_notifier(self, _("Storing catalog"), qo.catalog.sync_with_xml).exec_() : 00405 raise Exception(_("Cannot store catalog into database")) 00406 qo.backup.restore(qo.backup.list_names()[-1]) 00407 fill_db() 00408 00409 # 4. apply settings 00410 qocfg.set_db_engine(backend) 00411 qocfg.set_db_name(db_name) 00412 qocfg.set_db_user(db_user) 00413 qocfg.set_db_password(db_password) 00414 qocfg.set_db_host(db_host) 00415 qocfg.set_db_port(db_port) 00416 00417 # 5. quit 00418 QMessageBox.information(self, _("Please restart Qomics"), _("Please restart Qomics to make changes apply")) 00419 import gui.main_window 00420 gui.main_window.instance.close() 00421 00422 QDialog.accept(self) 00423 00424
list py::gui::configure::datasource::backends = ["sqlite3", "mysql", "postgresql_psycopg2", "ado_mssql"] [static] |
dictionary py::gui::configure::datasource::backend_module [static] |
Initial value:
{
"sqlite3" : "pysqlite2",
"mysql" : "MySQLdb",
"postgresql_psycopg2" : "psycopg2",
"ado_mssql" : "adodbapi",
}
dictionary py::gui::configure::datasource::backend_homepage [static] |
Initial value:
{
"sqlite3" : "http://pysqlite.org",
"mysql" : "http://sourceforge.net/projects/mysql-python",
"postgresql_psycopg2" : "http://www.initd.org/tracker/psycopg",
"ado_mssql" : "http://sourceforge.net/projects/adodbapi",
}
dictionary py::gui::configure::datasource::backend_dist [static] |
Initial value:
{
"gentoo" : {
"sqlite3" : "pysqlite",
"mysql" : "mysql-python",
"postgresql_psycopg2" : "psycopg",
},
"debian" : {
"sqlite3" : "python-pysqlite2",
"mysql" : "python-mysqldb",
"postgresql_psycopg2" : "python-psycopg",
},
}
1.5.3