Some more refactoring and renaming.

Changed the Bible upgrade to leave the old values behind so that older versions of OpenLP don't delete the "corrupted" databases.
This commit is contained in:
Raoul Snyman 2012-04-23 21:19:13 +02:00
parent 85d48705fc
commit 640e12d85e
4 changed files with 129 additions and 40 deletions

View File

@ -582,7 +582,7 @@ class MediaManagerItem(QtGui.QWidget):
Common method for generating a service item Common method for generating a service item
""" """
serviceItem = ServiceItem(self.plugin) serviceItem = ServiceItem(self.plugin)
serviceItem.add_icon(self.plugin.icon_path) serviceItem.add_icon(self.plugin.iconPath)
if self.generateSlideData(serviceItem, item, xmlVersion, remote): if self.generateSlideData(serviceItem, item, xmlVersion, remote):
return serviceItem return serviceItem
else: else:

View File

@ -272,7 +272,7 @@ class ServiceManager(QtGui.QWidget):
QtCore.SIGNAL(u'service_item_update'), self.serviceItemUpdate) QtCore.SIGNAL(u'service_item_update'), self.serviceItemUpdate)
# Last little bits of setting up # Last little bits of setting up
self.service_theme = unicode(QtCore.QSettings().value( self.service_theme = unicode(QtCore.QSettings().value(
self.mainwindow.servicemanagerSettingsSection + u'/service theme', self.mainwindow.serviceManagerSettingsSection + u'/service theme',
QtCore.QVariant(u'')).toString()) QtCore.QVariant(u'')).toString())
self.servicePath = AppLocation.get_section_data_path(u'servicemanager') self.servicePath = AppLocation.get_section_data_path(u'servicemanager')
# build the drag and drop context menu # build the drag and drop context menu
@ -411,7 +411,7 @@ class ServiceManager(QtGui.QWidget):
self.mainwindow, self.mainwindow,
translate('OpenLP.ServiceManager', 'Open File'), translate('OpenLP.ServiceManager', 'Open File'),
SettingsManager.get_last_dir( SettingsManager.get_last_dir(
self.mainwindow.servicemanagerSettingsSection), self.mainwindow.serviceManagerSettingsSection),
translate('OpenLP.ServiceManager', translate('OpenLP.ServiceManager',
'OpenLP Service Files (*.osz)'))) 'OpenLP Service Files (*.osz)')))
if not fileName: if not fileName:
@ -419,7 +419,7 @@ class ServiceManager(QtGui.QWidget):
else: else:
fileName = loadFile fileName = loadFile
SettingsManager.set_last_dir( SettingsManager.set_last_dir(
self.mainwindow.servicemanagerSettingsSection, self.mainwindow.serviceManagerSettingsSection,
split_filename(fileName)[0]) split_filename(fileName)[0])
self.loadFile(fileName) self.loadFile(fileName)
@ -469,7 +469,7 @@ class ServiceManager(QtGui.QWidget):
service_file_name = '%s.osd' % basename service_file_name = '%s.osd' % basename
log.debug(u'ServiceManager.saveFile - %s', path_file_name) log.debug(u'ServiceManager.saveFile - %s', path_file_name)
SettingsManager.set_last_dir( SettingsManager.set_last_dir(
self.mainwindow.servicemanagerSettingsSection, self.mainwindow.serviceManagerSettingsSection,
path) path)
service = [] service = []
write_list = [] write_list = []
@ -622,7 +622,7 @@ class ServiceManager(QtGui.QWidget):
else: else:
default_filename = u'' default_filename = u''
directory = unicode(SettingsManager.get_last_dir( directory = unicode(SettingsManager.get_last_dir(
self.mainwindow.servicemanagerSettingsSection)) self.mainwindow.serviceManagerSettingsSection))
path = os.path.join(directory, default_filename) path = os.path.join(directory, default_filename)
fileName = unicode(QtGui.QFileDialog.getSaveFileName(self.mainwindow, fileName = unicode(QtGui.QFileDialog.getSaveFileName(self.mainwindow,
UiStrings().SaveService, path, UiStrings().SaveService, path,
@ -1107,7 +1107,7 @@ class ServiceManager(QtGui.QWidget):
self.service_theme = unicode(self.themeComboBox.currentText()) self.service_theme = unicode(self.themeComboBox.currentText())
self.mainwindow.renderer.set_service_theme(self.service_theme) self.mainwindow.renderer.set_service_theme(self.service_theme)
QtCore.QSettings().setValue( QtCore.QSettings().setValue(
self.mainwindow.servicemanagerSettingsSection + self.mainwindow.serviceManagerSettingsSection +
u'/service theme', u'/service theme',
QtCore.QVariant(self.service_theme)) QtCore.QVariant(self.service_theme))
self.regenerateServiceItems(True) self.regenerateServiceItems(True)

View File

@ -80,7 +80,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
pos = self.stackedLayout.addWidget(tab) pos = self.stackedLayout.addWidget(tab)
if is_active: if is_active:
item_name = QtGui.QListWidgetItem(tab.tabTitleVisible) item_name = QtGui.QListWidgetItem(tab.tabTitleVisible)
icon = build_icon(tab.icon_path) icon = build_icon(tab.iconPath)
item_name.setIcon(icon) item_name.setIcon(icon)
self.settingListWidget.insertItem(location, item_name) self.settingListWidget.insertItem(location, item_name)
else: else:

View File

@ -28,10 +28,12 @@
The :mod:`upgrade` module provides a way for the database and schema that is the The :mod:`upgrade` module provides a way for the database and schema that is the
backend for the Bibles plugin backend for the Bibles plugin
""" """
import logging
from sqlalchemy import Table, select, update, insert, or_ from sqlalchemy import Table, func, select, insert
__version__ = 1 __version__ = 1
log = logging.getLogger(__name__)
def upgrade_setup(metadata): def upgrade_setup(metadata):
""" """
@ -55,47 +57,134 @@ def upgrade_1(session, metadata, tables):
This upgrade renames a number of keys to a single naming convention.. This upgrade renames a number of keys to a single naming convention..
""" """
metadata_table = metadata.tables[u'metadata'] metadata_table = metadata.tables[u'metadata']
# Rename "Bookname language" to "book_name_language"
session.execute(update(metadata_table)\
.where(or_(metadata_table.c.key == u'bookname language',
metadata_table.c.key == u'Bookname language'))\
.values(key=u'book_name_language'))
# Copy "Copyright" to "copyright"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
session.execute(insert(metadata_table).values(
key=u'copyright',
value=select(metadata_table, metadata_table.c.key == u'Copyright')\
.as_scalar()
))
# Copy "Version" to "name" ("version" used by upgrade system) # Copy "Version" to "name" ("version" used by upgrade system)
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final) # TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
session.execute(insert(metadata_table).values( session.execute(insert(metadata_table).values(
key=u'name', key=u'name',
value=select(metadata_table, metadata_table.c.key == u'Version')\ value=select(
.as_scalar() [metadata_table.c.value],
metadata_table.c.key == u'Version'
).as_scalar()
))
# Copy "Copyright" to "copyright"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
session.execute(insert(metadata_table).values(
key=u'copyright',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'Copyright'
).as_scalar()
)) ))
# Copy "Permissions" to "permissions" # Copy "Permissions" to "permissions"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final) # TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
session.execute(insert(metadata_table).values( session.execute(insert(metadata_table).values(
key=u'permissions', key=u'permissions',
value=select(metadata_table, metadata_table.c.key == u'Permissions')\ value=select(
.as_scalar() [metadata_table.c.value],
metadata_table.c.key == u'Permissions'
).as_scalar()
)) ))
session.execute(update(metadata_table)\ # Copy "Bookname language" to "book_name_language"
.where(metadata_table.c.key == u'download source')\ # TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
.values(key=u'download_source')) value_count = session.execute(
session.execute(update(metadata_table)\ select(
.where(metadata_table.c.key == u'download name')\ [func.count(metadata_table.c.value)],
.values(key=u'download_name')) metadata_table.c.key == u'Bookname language'
session.execute(update(metadata_table)\ )
.where(metadata_table.c.key == u'proxy server')\ ).scalar()
.values(key=u'proxy_server')) if value_count > 0:
session.execute(update(metadata_table)\ session.execute(insert(metadata_table).values(
.where(metadata_table.c.key == u'proxy username')\ key=u'book_name_language',
.values(key=u'proxy_username')) value=select(
session.execute(update(metadata_table)\ [metadata_table.c.value],
.where(metadata_table.c.key == u'proxy password')\ metadata_table.c.key == u'Bookname language'
.values(key=u'proxy_password')) ).as_scalar()
))
# Copy "download source" to "download_source"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == u'download source'
)
).scalar()
log.debug(u'download source: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key=u'download_source',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'download source'
).as_scalar()
))
# Copy "download name" to "download_name"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == u'download name'
)
).scalar()
log.debug(u'download name: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key=u'download_name',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'download name'
).as_scalar()
))
# Copy "proxy server" to "proxy_server"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == u'proxy server'
)
).scalar()
log.debug(u'proxy server: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key=u'proxy_server',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'proxy server'
).as_scalar()
))
# Copy "proxy username" to "proxy_username"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == u'proxy username'
)
).scalar()
log.debug(u'proxy username: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key=u'proxy_username',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'proxy username'
).as_scalar()
))
# Copy "proxy password" to "proxy_password"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == u'proxy password'
)
).scalar()
log.debug(u'proxy password: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key=u'proxy_password',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'proxy password'
).as_scalar()
))
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final) # TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
#session.execute(delete(metadata_table)\ #session.execute(delete(metadata_table)\
# .where(metadata_table.c.key == u'dbversion')) # .where(metadata_table.c.key == u'dbversion'))