Add Vacuum to databases on exit

Tidy up custom plugin naming

Fixes: https://launchpad.net/bugs/636835
This commit is contained in:
Tim Bentley 2010-10-27 16:30:30 +01:00
parent 901b9d98c5
commit 8d31844ee0
9 changed files with 89 additions and 33 deletions

View File

@ -246,3 +246,10 @@ class Manager(object):
self.session.rollback()
log.exception(u'Failed to delete %s records', object_class.__name__)
return False
def finalise(self):
"""
VACUUM the database on exit.
"""
engine = create_engine(self.db_url)
engine.execute("vacuum")

View File

@ -117,3 +117,11 @@ class AlertsPlugin(Plugin):
self.textStrings[StringContent.VisibleName] = {
u'title': translate('AlertsPlugin', 'Alerts')
}
def finalise(self):
"""
Time to tidy up on exit
"""
log.info(u'Alerts Finalising')
self.manager.finalise()
Plugin.finalise(self)

View File

@ -172,3 +172,11 @@ class BiblePlugin(Plugin):
u'tooltip': translate('BiblesPlugin',
'Add the selected Bible to the service')
}
def finalise(self):
"""
Time to tidy up on exit
"""
log.info(u'Bible Finalising')
self.manager.finalise()
Plugin.finalise(self)

View File

@ -310,3 +310,11 @@ class BibleManager(object):
if bible == name:
return True
return False
def finalise(self):
"""
Loop through the databases to VACUUM them.
"""
for bible in self.db_cache:
self.db_cache[bible].finalise

View File

@ -49,8 +49,8 @@ class CustomPlugin(Plugin):
def __init__(self, plugin_helpers):
Plugin.__init__(self, u'Custom', u'1.9.3', plugin_helpers)
self.weight = -5
self.custommanager = Manager(u'custom', init_schema)
self.edit_custom_form = EditCustomForm(self.custommanager)
self.manager = Manager(u'custom', init_schema)
self.edit_custom_form = EditCustomForm(self.manager)
self.icon_path = u':/plugins/plugin_custom.png'
self.icon = build_icon(self.icon_path)
@ -160,3 +160,11 @@ class CustomPlugin(Plugin):
u'tooltip': translate('CustomsPlugin',
'Add the selected Custom to the service')
}
def finalise(self):
"""
Time to tidy up on exit
"""
log.info(u'Custom Finalising')
self.manager.finalise()
Plugin.finalise(self)

View File

@ -41,7 +41,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
Class documentation goes here.
"""
log.info(u'Custom Editor loaded')
def __init__(self, custommanager, parent=None):
def __init__(self, manager, parent=None):
"""
Constructor
"""
@ -74,7 +74,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
# Create other objects and forms.
self.custommanager = custommanager
self.manager = manager
self.editSlideForm = EditCustomSlideForm(self)
self.initialise()
@ -115,7 +115,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.customSlide = CustomSlide()
self.initialise()
if id != 0:
self.customSlide = self.custommanager.get_object(CustomSlide, id)
self.customSlide = self.manager.get_object(CustomSlide, id)
self.titleEdit.setText(self.customSlide.title)
self.creditEdit.setText(self.customSlide.credits)
customXML = CustomXMLParser(self.customSlide.text)
@ -168,7 +168,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
u'utf-8')
self.customSlide.theme_name = unicode(self.themeComboBox.currentText(),
u'utf-8')
return self.custommanager.save_object(self.customSlide)
return self.manager.save_object(self.customSlide)
def onUpButtonPressed(self):
selectedRow = self.slideListView.currentRow()

View File

@ -56,6 +56,7 @@ class CustomMediaItem(MediaManagerItem):
# Holds information about whether the edit is remotly triggered and
# which Custom is required.
self.remoteCustom = -1
self.manager = parent.manager
def addEndHeaderBar(self):
QtCore.QObject.connect(Receiver.get_receiver(),
@ -71,7 +72,7 @@ class CustomMediaItem(MediaManagerItem):
MediaManagerItem.requiredIcons(self)
def initialise(self):
self.loadCustomListView(self.parent.custommanager.get_all_objects(
self.loadCustomListView(self.manager.get_all_objects(
CustomSlide, order_by_ref=CustomSlide.title))
#Called to redisplay the song list screen edith from a search
#or from the exit of the Song edit dialog. If remote editing is active
@ -106,7 +107,7 @@ class CustomMediaItem(MediaManagerItem):
type of display is required.
"""
fields = customid.split(u':')
valid = self.parent.custommanager.get_object(CustomSlide, fields[1])
valid = self.manager.get_object(CustomSlide, fields[1])
if valid:
self.remoteCustom = fields[1]
self.remoteTriggered = fields[0]

View File

@ -199,3 +199,11 @@ class SongsPlugin(Plugin):
u'tooltip': translate('SongsPlugin',
'Add the selected Song to the service')
}
def finalise(self):
"""
Time to tidy up on exit
"""
log.info(u'Songs Finalising')
self.manager.finalise()
Plugin.finalise(self)

View File

@ -176,3 +176,11 @@ class SongUsagePlugin(Plugin):
self.textStrings[StringContent.VisibleName] = {
u'title': translate('SongUsagePlugin', 'SongUsage')
}
def finalise(self):
"""
Time to tidy up on exit
"""
log.info(u'SongUsage Finalising')
self.manager.finalise()
Plugin.finalise(self)