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
"""
serviceItem = ServiceItem(self.plugin)
serviceItem.add_icon(self.plugin.icon_path)
serviceItem.add_icon(self.plugin.iconPath)
if self.generateSlideData(serviceItem, item, xmlVersion, remote):
return serviceItem
else:

View File

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

View File

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

View File

@ -28,10 +28,12 @@
The :mod:`upgrade` module provides a way for the database and schema that is the
backend for the Bibles plugin
"""
import logging
from sqlalchemy import Table, select, update, insert, or_
from sqlalchemy import Table, func, select, insert
__version__ = 1
log = logging.getLogger(__name__)
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..
"""
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)
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
session.execute(insert(metadata_table).values(
key=u'name',
value=select(metadata_table, metadata_table.c.key == u'Version')\
.as_scalar()
value=select(
[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"
# TODO: Clean up in a subsequent release of OpenLP (like 2.0 final)
session.execute(insert(metadata_table).values(
key=u'permissions',
value=select(metadata_table, metadata_table.c.key == u'Permissions')\
.as_scalar()
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'Permissions'
).as_scalar()
))
session.execute(update(metadata_table)\
.where(metadata_table.c.key == u'download source')\
.values(key=u'download_source'))
session.execute(update(metadata_table)\
.where(metadata_table.c.key == u'download name')\
.values(key=u'download_name'))
session.execute(update(metadata_table)\
.where(metadata_table.c.key == u'proxy server')\
.values(key=u'proxy_server'))
session.execute(update(metadata_table)\
.where(metadata_table.c.key == u'proxy username')\
.values(key=u'proxy_username'))
session.execute(update(metadata_table)\
.where(metadata_table.c.key == u'proxy password')\
.values(key=u'proxy_password'))
# Copy "Bookname language" to "book_name_language"
# 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'Bookname language'
)
).scalar()
if value_count > 0:
session.execute(insert(metadata_table).values(
key=u'book_name_language',
value=select(
[metadata_table.c.value],
metadata_table.c.key == u'Bookname language'
).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)
#session.execute(delete(metadata_table)\
# .where(metadata_table.c.key == u'dbversion'))