From 85661fe6e468f657552174785ace5d1fe5accad8 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 15 Jun 2010 16:42:52 +0100 Subject: [PATCH] RFC: Tweaks --- openlp/core/lib/__init__.py | 29 +++++++++++- openlp/migration/migratebibles.py | 3 +- openlp/migration/migratesongs.py | 5 +-- openlp/plugins/alerts/alertsplugin.py | 3 ++ openlp/plugins/bibles/lib/db.py | 63 +++++++++++++++++---------- openlp/plugins/custom/lib/db.py | 2 +- 6 files changed, 74 insertions(+), 31 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index ffc61cdcc..5e6547906 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -22,7 +22,6 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - """ The :mod:`lib` module contains most of the components and libraries that make OpenLP work. @@ -47,6 +46,10 @@ def translate(context, text, comment=None): ``text`` The text to put into the translation tables for translation. + + ``comment`` + An identifying string for when the same text is used in different roles + within the same context. """ return QtCore.QCoreApplication.translate(context, text, comment) @@ -115,6 +118,18 @@ def build_icon(icon): def context_menu_action(base, icon, text, slot): """ Utility method to help build context menus for plugins + + ``base`` + The parent menu to add this menu item to + + ``icon`` + An icon for this action + + ``text`` + The text to display for this action + + ``slot`` + The code to run when this action is triggered """ action = QtGui.QAction(text, base) if icon: @@ -125,6 +140,15 @@ def context_menu_action(base, icon, text, slot): def context_menu(base, icon, text): """ Utility method to help build context menus for plugins + + ``base`` + The parent object to add this menu to + + ``icon`` + An icon for this menu + + ``text`` + The text to display for this menu """ action = QtGui.QMenu(text, base) action.setIcon(build_icon(icon)) @@ -133,6 +157,9 @@ def context_menu(base, icon, text): def context_menu_separator(base): """ Add a separator to a context menu + + ``base`` + The menu object to add the separator to """ action = QtGui.QAction(u'', base) action.setSeparator(True) diff --git a/openlp/migration/migratebibles.py b/openlp/migration/migratebibles.py index b024343a4..411da0ce6 100644 --- a/openlp/migration/migratebibles.py +++ b/openlp/migration/migratebibles.py @@ -33,7 +33,7 @@ from sqlalchemy.orm import mapper from openlp.core.lib import SettingsManager from openlp.core.lib.db import BaseModel from openlp.core.utils import AppLocation -from openlp.plugins.bibles.lib.models import * +from openlp.plugins.bibles.lib.db import BibleMeta, Book, Testament, Verse class TBibleMeta(BaseModel): """ @@ -196,4 +196,3 @@ class MigrateBibles(object): conn.commit() conn.execute(u'vacuum;') conn.commit() - diff --git a/openlp/migration/migratesongs.py b/openlp/migration/migratesongs.py index c4cab00bc..0ede63387 100644 --- a/openlp/migration/migratesongs.py +++ b/openlp/migration/migratesongs.py @@ -34,10 +34,7 @@ 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.models import metadata, songs_table, Song, \ - Author, Topic, Book -from openlp.plugins.songs.lib.tables import * -from openlp.plugins.songs.lib.classes import * +from openlp.plugins.songs.lib.db import songs_table, Song, Author, Topic, Book def init_models(url): engine = create_engine(url) diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index 3c14e23b1..bd783a7cb 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -48,6 +48,9 @@ class alertsPlugin(Plugin): self.status = PluginStatus.Active def get_settings_tab(self): + """ + Return the settings tab for the Alerts plugin + """ self.alertsTab = AlertsTab(self) return self.alertsTab diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 7733261db..eee149320 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -197,18 +197,11 @@ class BibleDB(QtCore.QObject, Manager): The actual Qt wizard form. """ self.wizard = wizard - self.create_tables() - return self.name - - def create_tables(self): - """ - Create some initial metadata. - """ - log.debug(u'createTables') self.create_meta(u'dbversion', u'2') self.insert_object(Testament.populate(name=u'Old Testament')) self.insert_object(Testament.populate(name=u'New Testament')) self.insert_object(Testament.populate(name=u'Apocrypha')) + return self.name def create_book(self, name, abbrev, testament=1): """ @@ -284,26 +277,32 @@ class BibleDB(QtCore.QObject, Manager): return verse def create_meta(self, key, value): + """ + Utility method to save BibleMeta objects in a Bible database + + ``key`` + The key for this instance + + ``value`` + The value for this instance + """ log.debug(u'save_meta %s/%s', key, value) self.insert_object(BibleMeta.populate(key=key, value=value)) def get_book(self, book): - log.debug(u'BibleDb.get_book("%s")', book) - db_book = self.session.query(Book)\ - .filter(Book.name.like(book + u'%'))\ - .first() - if db_book is None: - db_book = self.session.query(Book)\ - .filter(Book.abbreviation.like(book + u'%'))\ - .first() - return db_book + """ + Return a book object from the database - def get_chapter(self, id, chapter): - log.debug(u'BibleDB.get_chapter("%s", %s)', id, chapter) - return self.session.query(Verse)\ - .filter_by(chapter=chapter)\ - .filter_by(book_id=id)\ - .first() + ``book`` + The name of the book to return + """ + log.debug(u'BibleDb.get_book("%s")', book) + db_book = self.session.query(Book).filter( + Book.name.like(book + u'%')).first() + if db_book is None: + db_book = self.session.query(Book).filter( + Book.abbreviation.like(book + u'%')).first() + return db_book def get_verses(self, reference_list): """ @@ -370,6 +369,12 @@ class BibleDB(QtCore.QObject, Manager): return verses def get_chapter_count(self, book): + """ + Return the number of chapters in a book + + ``book`` + The book to get the chapter count for + """ log.debug(u'BibleDB.get_chapter_count("%s")', book) count = self.session.query(Verse.chapter).join(Book)\ .filter(Book.name==book)\ @@ -380,6 +385,15 @@ class BibleDB(QtCore.QObject, Manager): return count def get_verse_count(self, book, chapter): + """ + Return the number of verses in a chapter + + ``book`` + The book containing the chapter + + ``chapter`` + The chapter to get the verse count for + """ log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter) count = self.session.query(Verse).join(Book)\ .filter(Book.name==book)\ @@ -391,6 +405,9 @@ class BibleDB(QtCore.QObject, Manager): return count def dump_bible(self): + """ + Utility debugging method to dump the contents of a bible + """ log.debug(u'.........Dumping Bible Database') log.debug('...............................Books ') books = self.session.query(Book).all() diff --git a/openlp/plugins/custom/lib/db.py b/openlp/plugins/custom/lib/db.py index 277f3a7e8..39d935d9a 100644 --- a/openlp/plugins/custom/lib/db.py +++ b/openlp/plugins/custom/lib/db.py @@ -34,7 +34,7 @@ from openlp.core.lib.db import BaseModel, init_db class CustomSlide(BaseModel): """ - Custom Slide model + CustomSlide model """ pass