first go at db maintenance window, turned off for now
This commit is contained in:
parent
141b88ecfd
commit
09801cd00e
|
@ -695,18 +695,8 @@ class Config:
|
||||||
try: db['db-server'] = self.supported_databases[name].db_server
|
try: db['db-server'] = self.supported_databases[name].db_server
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
if self.supported_databases[name].db_server== DATABASE_TYPE_MYSQL:
|
db['db-backend'] = self.get_backend(self.supported_databases[name].db_server)
|
||||||
db['db-backend'] = 2
|
|
||||||
elif self.supported_databases[name].db_server== DATABASE_TYPE_POSTGRESQL:
|
|
||||||
db['db-backend'] = 3
|
|
||||||
elif self.supported_databases[name].db_server== DATABASE_TYPE_SQLITE:
|
|
||||||
db['db-backend'] = 4
|
|
||||||
# sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252)
|
|
||||||
# feel free to remove or improve this if you understand the problems
|
|
||||||
# better than me (not hard!)
|
|
||||||
Charset.not_needed1, Charset.not_needed2, Charset.not_needed3 = True, True, True
|
|
||||||
else:
|
|
||||||
raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server)
|
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
||||||
|
@ -726,6 +716,23 @@ class Config:
|
||||||
if db_type is not None: self.supported_databases[db_name].dp_type = db_type
|
if db_type is not None: self.supported_databases[db_name].dp_type = db_type
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def get_backend(self, name):
|
||||||
|
"""Returns the number of the currently used backend"""
|
||||||
|
if name == DATABASE_TYPE_MYSQL:
|
||||||
|
ret = 2
|
||||||
|
elif name == DATABASE_TYPE_POSTGRESQL:
|
||||||
|
ret = 3
|
||||||
|
elif name == DATABASE_TYPE_SQLITE:
|
||||||
|
ret = 4
|
||||||
|
# sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252)
|
||||||
|
# feel free to remove or improve this if you understand the problems
|
||||||
|
# better than me (not hard!)
|
||||||
|
Charset.not_needed1, Charset.not_needed2, Charset.not_needed3 = True, True, True
|
||||||
|
else:
|
||||||
|
raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
def getDefaultSite(self):
|
def getDefaultSite(self):
|
||||||
"Returns first enabled site or None"
|
"Returns first enabled site or None"
|
||||||
for site_name,site in self.supported_sites.iteritems():
|
for site_name,site in self.supported_sites.iteritems():
|
||||||
|
|
|
@ -226,7 +226,7 @@ class Database:
|
||||||
# create index indexname on tablename (col);
|
# create index indexname on tablename (col);
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, c, sql = None):
|
def __init__(self, c, sql = None, autoconnect = True):
|
||||||
#log = Configuration.get_logger("logging.conf", "db", log_dir=c.dir_log)
|
#log = Configuration.get_logger("logging.conf", "db", log_dir=c.dir_log)
|
||||||
log.debug("Creating Database instance, sql = %s" % sql)
|
log.debug("Creating Database instance, sql = %s" % sql)
|
||||||
self.config = c
|
self.config = c
|
||||||
|
@ -247,6 +247,7 @@ class Database:
|
||||||
else:
|
else:
|
||||||
self.sql = sql
|
self.sql = sql
|
||||||
|
|
||||||
|
if autoconnect:
|
||||||
# connect to db
|
# connect to db
|
||||||
self.do_connect(c)
|
self.do_connect(c)
|
||||||
|
|
||||||
|
@ -313,7 +314,7 @@ class Database:
|
||||||
self.__connected = True
|
self.__connected = True
|
||||||
|
|
||||||
def connect(self, backend=None, host=None, database=None,
|
def connect(self, backend=None, host=None, database=None,
|
||||||
user=None, password=None):
|
user=None, password=None, create=False):
|
||||||
"""Connects a database with the given parameters"""
|
"""Connects a database with the given parameters"""
|
||||||
if backend is None:
|
if backend is None:
|
||||||
raise FpdbError('Database backend not defined')
|
raise FpdbError('Database backend not defined')
|
||||||
|
@ -384,13 +385,14 @@ class Database:
|
||||||
# log.warning("SQLite won't work well without 'sqlalchemy' installed.")
|
# log.warning("SQLite won't work well without 'sqlalchemy' installed.")
|
||||||
|
|
||||||
if database != ":memory:":
|
if database != ":memory:":
|
||||||
if not os.path.isdir(self.config.dir_database):
|
if not os.path.isdir(self.config.dir_database) and create:
|
||||||
print "Creating directory: '%s'" % (self.config.dir_database)
|
print "Creating directory: '%s'" % (self.config.dir_database)
|
||||||
log.info("Creating directory: '%s'" % (self.config.dir_database))
|
log.info("Creating directory: '%s'" % (self.config.dir_database))
|
||||||
os.mkdir(self.config.dir_database)
|
os.mkdir(self.config.dir_database)
|
||||||
database = os.path.join(self.config.dir_database, database)
|
database = os.path.join(self.config.dir_database, database)
|
||||||
self.db_path = database
|
self.db_path = database
|
||||||
log.info("Connecting to SQLite: %(database)s" % {'database':self.db_path})
|
log.info("Connecting to SQLite: %(database)s" % {'database':self.db_path})
|
||||||
|
if os.path.exists(database) or create:
|
||||||
self.connection = sqlite3.connect(self.db_path, detect_types=sqlite3.PARSE_DECLTYPES )
|
self.connection = sqlite3.connect(self.db_path, detect_types=sqlite3.PARSE_DECLTYPES )
|
||||||
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
||||||
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
||||||
|
@ -405,11 +407,13 @@ class Database:
|
||||||
self.cursor.execute('PRAGMA temp_store=2') # use memory for temp tables/indexes
|
self.cursor.execute('PRAGMA temp_store=2') # use memory for temp tables/indexes
|
||||||
self.cursor.execute('PRAGMA synchronous=0') # don't wait for file writes to finish
|
self.cursor.execute('PRAGMA synchronous=0') # don't wait for file writes to finish
|
||||||
else:
|
else:
|
||||||
raise FpdbError("unrecognised database backend:"+backend)
|
raise FpdbError("sqlite database "+database+" does not exist")
|
||||||
|
else:
|
||||||
|
raise FpdbError("unrecognised database backend:"+str(backend))
|
||||||
|
|
||||||
self.cursor = self.connection.cursor()
|
self.cursor = self.connection.cursor()
|
||||||
self.cursor.execute(self.sql.query['set tx level'])
|
self.cursor.execute(self.sql.query['set tx level'])
|
||||||
self.check_version(database=database, create=True)
|
self.check_version(database=database, create=create)
|
||||||
|
|
||||||
|
|
||||||
def check_version(self, database, create):
|
def check_version(self, database, create):
|
||||||
|
|
|
@ -97,6 +97,7 @@ except:
|
||||||
|
|
||||||
import GuiPrefs
|
import GuiPrefs
|
||||||
import GuiLogView
|
import GuiLogView
|
||||||
|
import GuiDatabase
|
||||||
import GuiBulkImport
|
import GuiBulkImport
|
||||||
import GuiPlayerStats
|
import GuiPlayerStats
|
||||||
import GuiPositionalStats
|
import GuiPositionalStats
|
||||||
|
@ -288,11 +289,32 @@ class fpdb:
|
||||||
|
|
||||||
dia.destroy()
|
dia.destroy()
|
||||||
|
|
||||||
def dia_create_del_database(self, widget, data=None):
|
def dia_maintain_dbs(self, widget, data=None):
|
||||||
self.warning_box("Unimplemented: Create/Delete Database")
|
self.warning_box("Unimplemented: Maintain Databases")
|
||||||
self.obtain_global_lock()
|
return
|
||||||
|
if len(self.tab_names) == 1:
|
||||||
|
if self.obtain_global_lock(): # returns true if successful
|
||||||
|
# only main tab has been opened, open dialog
|
||||||
|
dia = gtk.Dialog("Maintain Databases",
|
||||||
|
self.window,
|
||||||
|
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
||||||
|
gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
|
||||||
|
dia.set_default_size(700, 320)
|
||||||
|
|
||||||
|
prefs = GuiDatabase.GuiDatabase(self.config, self.window, dia)
|
||||||
|
response = dia.run()
|
||||||
|
if response == gtk.RESPONSE_ACCEPT:
|
||||||
|
# save updated config
|
||||||
|
self.config.save()
|
||||||
|
|
||||||
self.release_global_lock()
|
self.release_global_lock()
|
||||||
|
|
||||||
|
dia.destroy()
|
||||||
|
else:
|
||||||
|
self.warning_box("Cannot open Database Maintenance window because "
|
||||||
|
+ "other windows have been opened. Re-start fpdb to use this option.")
|
||||||
|
|
||||||
def dia_create_del_user(self, widget, data=None):
|
def dia_create_del_user(self, widget, data=None):
|
||||||
self.warning_box("Unimplemented: Create/Delete user")
|
self.warning_box("Unimplemented: Create/Delete user")
|
||||||
self.obtain_global_lock()
|
self.obtain_global_lock()
|
||||||
|
@ -620,7 +642,7 @@ class fpdb:
|
||||||
<menuitem action="tableviewer"/>
|
<menuitem action="tableviewer"/>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="database">
|
<menu action="database">
|
||||||
<menuitem action="createdb"/>
|
<menuitem action="maintaindbs"/>
|
||||||
<menuitem action="createuser"/>
|
<menuitem action="createuser"/>
|
||||||
<menuitem action="createtabs"/>
|
<menuitem action="createtabs"/>
|
||||||
<menuitem action="rebuildhudcache"/>
|
<menuitem action="rebuildhudcache"/>
|
||||||
|
@ -663,7 +685,7 @@ class fpdb:
|
||||||
('sessionreplay', None, '_Session Replayer (todo)', None, 'Session Replayer (todo)', self.not_implemented),
|
('sessionreplay', None, '_Session Replayer (todo)', None, 'Session Replayer (todo)', self.not_implemented),
|
||||||
('tableviewer', None, 'Poker_table Viewer (mostly obselete)', None, 'Poker_table Viewer (mostly obselete)', self.tab_table_viewer),
|
('tableviewer', None, 'Poker_table Viewer (mostly obselete)', None, 'Poker_table Viewer (mostly obselete)', self.tab_table_viewer),
|
||||||
('database', None, '_Database'),
|
('database', None, '_Database'),
|
||||||
('createdb', None, 'Create or Delete _Database (todo)', None, 'Create or Delete Database', self.dia_create_del_database),
|
('maintaindbs', None, '_Maintain Databases (todo)', None, 'Maintain Databases', self.dia_maintain_dbs),
|
||||||
('createuser', None, 'Create or Delete _User (todo)', None, 'Create or Delete User', self.dia_create_del_user),
|
('createuser', None, 'Create or Delete _User (todo)', None, 'Create or Delete User', self.dia_create_del_user),
|
||||||
('createtabs', None, 'Create or Recreate _Tables', None, 'Create or Recreate Tables ', self.dia_recreate_tables),
|
('createtabs', None, 'Create or Recreate _Tables', None, 'Create or Recreate Tables ', self.dia_recreate_tables),
|
||||||
('rebuildhudcache', None, 'Rebuild HUD Cache', None, 'Rebuild HUD Cache', self.dia_recreate_hudcache),
|
('rebuildhudcache', None, 'Rebuild HUD Cache', None, 'Rebuild HUD Cache', self.dia_recreate_hudcache),
|
||||||
|
@ -685,7 +707,7 @@ class fpdb:
|
||||||
window.add_accel_group(accel_group)
|
window.add_accel_group(accel_group)
|
||||||
return menubar
|
return menubar
|
||||||
|
|
||||||
def load_profile(self):
|
def load_profile(self, create_db = False):
|
||||||
"""Loads profile from the provided path name."""
|
"""Loads profile from the provided path name."""
|
||||||
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
||||||
if self.config.file_error:
|
if self.config.file_error:
|
||||||
|
@ -911,7 +933,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
||||||
self.tab_main_help(None, None)
|
self.tab_main_help(None, None)
|
||||||
|
|
||||||
self.window.show()
|
self.window.show()
|
||||||
self.load_profile()
|
self.load_profile(create_db = True)
|
||||||
|
|
||||||
if not options.errorsToConsole:
|
if not options.errorsToConsole:
|
||||||
fileName = os.path.join(self.config.dir_log, 'fpdb-errors.txt')
|
fileName = os.path.join(self.config.dir_log, 'fpdb-errors.txt')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user