forked from openlp/openlp
RFC: Cleanups
This commit is contained in:
parent
d395438173
commit
7f88043177
@ -26,6 +26,7 @@
|
||||
The :mod:`db` module provides the core database functionality for OpenLP
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
from PyQt4 import QtCore
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
@ -55,11 +56,34 @@ def init_db(url, auto_flush=True, auto_commit=False):
|
||||
autocommit=auto_commit, bind=engine))
|
||||
return session, metadata
|
||||
|
||||
def delete_database(plugin_name, db_file_name=None):
|
||||
"""
|
||||
Remove a database file from the system.
|
||||
|
||||
``plugin_name``
|
||||
The name of the plugin to remove the database for
|
||||
|
||||
``db_file_name``
|
||||
The database file name. Defaults to None resulting in the
|
||||
plugin_name being used.
|
||||
"""
|
||||
db_file_path = None
|
||||
if db_file_name:
|
||||
db_file_path = os.path.join(
|
||||
AppLocation.get_section_data_path(plugin_name), db_file_name)
|
||||
else:
|
||||
db_file_path = os.path.join(
|
||||
AppLocation.get_section_data_path(plugin_name), plugin_name)
|
||||
try:
|
||||
os.remove(db_file_path)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
class BaseModel(object):
|
||||
"""
|
||||
BaseModel provides a base object with a set of generic functions
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def populate(cls, **kwargs):
|
||||
"""
|
||||
@ -111,30 +135,6 @@ class Manager(object):
|
||||
settings.endGroup()
|
||||
self.session = init_schema(self.db_url)
|
||||
|
||||
def delete_database(self, plugin_name, db_file_name=None):
|
||||
"""
|
||||
Remove a database file from the system.
|
||||
|
||||
``plugin_name``
|
||||
The name of the plugin to remove the database for
|
||||
|
||||
``db_file_name``
|
||||
The database file name. Defaults to None resulting in the
|
||||
plugin_name being used.
|
||||
"""
|
||||
db_file_path = None
|
||||
if db_file_name:
|
||||
db_file_path = os.path.join(
|
||||
AppLocation.get_section_data_path(plugin_name), db_file_name)
|
||||
else:
|
||||
db_file_path = os.path.join(
|
||||
AppLocation.get_section_data_path(plugin_name), plugin_name)
|
||||
try:
|
||||
os.remove(db_file_path)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
def insert_object(self, object_instance):
|
||||
"""
|
||||
Save an object to the database
|
||||
@ -151,20 +151,20 @@ class Manager(object):
|
||||
log.exception(u'Object save failed')
|
||||
return False
|
||||
|
||||
def get_object(self, object_class, id=None):
|
||||
def get_object(self, object_class, key=None):
|
||||
"""
|
||||
Return the details of an object
|
||||
|
||||
``object_class``
|
||||
The type of object to return
|
||||
|
||||
``id``
|
||||
The unique reference for the class instance to return
|
||||
``key``
|
||||
The unique reference or primary key for the instance to return
|
||||
"""
|
||||
if not id:
|
||||
if not key:
|
||||
return object_class()
|
||||
else:
|
||||
return self.session.query(object_class).get(id)
|
||||
return self.session.query(object_class).get(key)
|
||||
|
||||
def get_object_filtered(self, object_class, filter_string):
|
||||
"""
|
||||
@ -204,20 +204,20 @@ class Manager(object):
|
||||
"""
|
||||
return self.session.query(object_class).filter(filter_string).all()
|
||||
|
||||
def delete_object(self, object_class, id):
|
||||
def delete_object(self, object_class, key):
|
||||
"""
|
||||
Delete an object from the database
|
||||
|
||||
``object_class``
|
||||
The type of object to delete
|
||||
|
||||
``id``
|
||||
The unique reference for the class instance to be deleted
|
||||
``key``
|
||||
The unique reference or primary key for the instance to be deleted
|
||||
"""
|
||||
if id != 0:
|
||||
object = self.get_object(object_class, id)
|
||||
if key != 0:
|
||||
object_instance = self.get_object(object_class, key)
|
||||
try:
|
||||
self.session.delete(object)
|
||||
self.session.delete(object_instance)
|
||||
self.session.commit()
|
||||
return True
|
||||
except InvalidRequestError:
|
||||
|
@ -27,6 +27,7 @@ import os
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
from sqlalchemy import Column, MetaData, Table, types
|
||||
from sqlalchemy.exceptions import InvalidRequestError
|
||||
from sqlalchemy.orm import mapper
|
||||
|
||||
@ -34,7 +35,9 @@ from openlp.core.lib import SettingsManager
|
||||
from openlp.core.lib.db import BaseModel
|
||||
from openlp.core.utils import AppLocation
|
||||
from openlp.plugins.bibles.lib.db import BibleMeta, Book, Testament, Verse
|
||||
|
||||
|
||||
metadata = MetaData()
|
||||
|
||||
class TBibleMeta(BaseModel):
|
||||
"""
|
||||
Bible Meta Data
|
||||
|
@ -27,14 +27,16 @@ import os
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import Column, create_engine, MetaData, Table, types
|
||||
from sqlalchemy.exceptions import InvalidRequestError
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation
|
||||
|
||||
from openlp.core.lib import SettingsManager
|
||||
from openlp.core.lib.db import BaseModel
|
||||
from openlp.core.utils import AppLocation
|
||||
from openlp.plugins.songs.lib.db import songs_table, Song, Author, Topic, Book
|
||||
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic
|
||||
|
||||
metadata = MetaData()
|
||||
|
||||
def init_models(url):
|
||||
engine = create_engine(url)
|
||||
@ -57,14 +59,14 @@ def init_models(url):
|
||||
|
||||
temp_authors_table = Table(u'authors_temp', metadata,
|
||||
Column(u'authorid', types.Integer, primary_key=True),
|
||||
Column(u'authorname', String(40))
|
||||
Column(u'authorname', types.Unicode(40))
|
||||
)
|
||||
|
||||
temp_songs_table = Table(u'songs_temp', metadata,
|
||||
Column(u'songid', types.Integer, primary_key=True),
|
||||
Column(u'songtitle', String(60)),
|
||||
Column(u'songtitle', types.Unicode(60)),
|
||||
Column(u'lyrics', types.UnicodeText),
|
||||
Column(u'copyrightinfo', String(255)),
|
||||
Column(u'copyrightinfo', types.Unicode(255)),
|
||||
Column(u'settingsid', types.Integer)
|
||||
)
|
||||
|
||||
@ -101,8 +103,8 @@ class MigrateSongs(object):
|
||||
|
||||
def process(self):
|
||||
self.display.output(u'Songs processing started')
|
||||
for f in self.database_files:
|
||||
self.v_1_9_0(f)
|
||||
for data_file in self.database_files:
|
||||
self.v_1_9_0(data_file)
|
||||
self.display.output(u'Songs processing finished')
|
||||
|
||||
def v_1_9_0(self, database):
|
||||
|
@ -32,6 +32,7 @@ from PyQt4 import QtCore, QtGui
|
||||
|
||||
from bibleimportwizard import Ui_BibleImportWizard
|
||||
from openlp.core.lib import Receiver, SettingsManager, translate
|
||||
from openlp.core.lib.db import delete_database
|
||||
from openlp.core.utils import AppLocation
|
||||
from openlp.plugins.bibles.lib.manager import BibleFormat
|
||||
|
||||
@ -449,8 +450,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
self.ImportProgressLabel.setText(
|
||||
translate(u'BiblesPlugin.ImportWizardForm',
|
||||
u'Your Bible import failed.'))
|
||||
importer.delete_database(self.bibleplugin.settingsSection,
|
||||
importer.file)
|
||||
delete_database(self.bibleplugin.settingsSection, importer.file)
|
||||
|
||||
def postImport(self):
|
||||
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
||||
|
@ -154,6 +154,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
Manager.__init__(self, u'bibles', init_schema, self.file)
|
||||
if u'file' in kwargs:
|
||||
self.get_name()
|
||||
self.wizard = None
|
||||
|
||||
def stop_import(self):
|
||||
"""
|
||||
|
@ -26,6 +26,7 @@
|
||||
import logging
|
||||
|
||||
from forms import EditCustomForm
|
||||
|
||||
from openlp.core.lib import Plugin, build_icon, PluginStatus, translate
|
||||
from openlp.core.lib.db import Manager
|
||||
from openlp.plugins.custom.lib import CustomMediaItem, CustomTab
|
||||
@ -77,7 +78,8 @@ class CustomPlugin(Plugin):
|
||||
return about_text
|
||||
|
||||
def can_delete_theme(self, theme):
|
||||
filter = u'theme_name=%s' % theme
|
||||
if not self.custommanager.get_all_objects_filtered(CustomSlide, filter):
|
||||
filter_string = u'theme_name=%s' % theme
|
||||
if not self.custommanager.get_all_objects_filtered(CustomSlide,
|
||||
filter_string):
|
||||
return True
|
||||
return False
|
||||
|
@ -167,8 +167,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
|
||||
u'utf-8')
|
||||
self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText(),
|
||||
u'utf-8')
|
||||
self.custommanager.insert_object(self.customSlide)
|
||||
return True
|
||||
return self.custommanager.insert_object(self.customSlide)
|
||||
|
||||
def onUpButtonPressed(self):
|
||||
selectedRow = self.VerseListView.currentRow()
|
||||
|
@ -197,7 +197,7 @@ class SongsPlugin(Plugin):
|
||||
return about_text
|
||||
|
||||
def can_delete_theme(self, theme):
|
||||
filter = u'theme_name=%s' % theme
|
||||
if not self.manager.get_all_objects_filtered(Song, filter):
|
||||
filter_string = u'theme_name=%s' % theme
|
||||
if not self.manager.get_all_objects_filtered(Song, filter_string):
|
||||
return True
|
||||
return False
|
||||
|
@ -22,5 +22,7 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
|
||||
from manager import SongUsageManager
|
||||
"""
|
||||
The :mod:`lib` module contains the library functions for the songusage plugin.
|
||||
"""
|
||||
from openlp.plugins.songusage.lib.manager import SongUsageManager
|
||||
|
Loading…
Reference in New Issue
Block a user