fixed bug #804747; clean ups

Fixes: https://launchpad.net/bugs/804747
This commit is contained in:
Andreas Preikschat 2011-08-12 15:11:30 +02:00
parent ccaa1bdf92
commit 0924bfc246
6 changed files with 79 additions and 112 deletions

View File

@ -247,7 +247,7 @@ class EventReceiver(QtCore.QObject):
``msg`` ``msg``
Defaults to *None*. The message to send with the event. Defaults to *None*. The message to send with the event.
""" """
log.debug(u'Event %s passed with payload %s' % (event, msg)) #log.debug(u'Event %s passed with payload %s' % (event, msg))
self.emit(QtCore.SIGNAL(event), msg) self.emit(QtCore.SIGNAL(event), msg)

View File

@ -28,6 +28,7 @@
import logging import logging
import os import os
import sys import sys
import shutil
from tempfile import gettempdir from tempfile import gettempdir
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -721,11 +722,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
plugin.firstTime() plugin.firstTime()
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
temp_dir = os.path.join(unicode(gettempdir()), u'openlp') temp_dir = os.path.join(unicode(gettempdir()), u'openlp')
if not os.path.exists(temp_dir): shutil.rmtree(temp_dir, True)
return
for filename in os.listdir(temp_dir):
delete_file(os.path.join(temp_dir, filename))
os.removedirs(temp_dir)
def onFirstTimeWizardClicked(self): def onFirstTimeWizardClicked(self):
""" """

View File

@ -29,6 +29,7 @@ The bible import functions for OpenLP
import logging import logging
import os import os
import shutil import shutil
from tempfile import gettempdir
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -124,7 +125,7 @@ class BibleUpgradeForm(OpenLPWizard):
self.preWizard() self.preWizard()
self.performWizard() self.performWizard()
self.postWizard() self.postWizard()
elif self.page(pageId) == self.selectPage and self.maxBibles == 0: elif self.page(pageId) == self.selectPage and not self.files:
self.next() self.next()
def onBackupBrowseButtonClicked(self): def onBackupBrowseButtonClicked(self):
@ -425,9 +426,13 @@ class BibleUpgradeForm(OpenLPWizard):
return False return False
return True return True
elif self.currentPage() == self.selectPage: elif self.currentPage() == self.selectPage:
temp_dir = os.path.join(gettempdir(), u'openlp')
check_directory_exists(temp_dir)
for number, filename in enumerate(self.files): for number, filename in enumerate(self.files):
if not self.checkBox[number].checkState() == QtCore.Qt.Checked: if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
continue continue
# Move bibles to temp dir.
shutil.move(os.path.join(self.path, filename[0]), temp_dir)
version_name = unicode(self.versionNameEdit[number].text()) version_name = unicode(self.versionNameEdit[number].text())
if not version_name: if not version_name:
critical_error_message_box(UiStrings().EmptyField, critical_error_message_box(UiStrings().EmptyField,
@ -435,37 +440,6 @@ class BibleUpgradeForm(OpenLPWizard):
'You need to specify a version name for your Bible.')) 'You need to specify a version name for your Bible.'))
self.versionNameEdit[number].setFocus() self.versionNameEdit[number].setFocus()
return False return False
elif self.manager.exists(version_name):
critical_error_message_box(
translate('BiblesPlugin.UpgradeWizardForm',
'Bible Exists'),
translate('BiblesPlugin.UpgradeWizardForm',
'This Bible already exists. Please upgrade '
'a different Bible, delete the existing one or '
'uncheck.'))
self.versionNameEdit[number].setFocus()
return False
elif os.path.exists(os.path.join(self.path, clean_filename(
version_name))) and version_name == filename[1]:
newfilename = u'old_database_%s' % filename[0]
if not os.path.exists(os.path.join(self.path,
newfilename)):
os.rename(os.path.join(self.path, filename[0]),
os.path.join(self.path, newfilename))
self.files[number] = [newfilename, filename[1]]
continue
else:
critical_error_message_box(
translate('BiblesPlugin.UpgradeWizardForm',
'Bible Exists'),
translate('BiblesPlugin.UpgradeWizardForm',
'This Bible already exists. Please upgrade '
'a different Bible, delete the existing one or '
'uncheck.'))
self.verticalWidget[number].show()
self.formWidget[number].show()
self.versionNameEdit[number].setFocus()
return False
elif os.path.exists(os.path.join(self.path, elif os.path.exists(os.path.join(self.path,
clean_filename(version_name))): clean_filename(version_name))):
critical_error_message_box( critical_error_message_box(
@ -495,7 +469,6 @@ class BibleUpgradeForm(OpenLPWizard):
self.files = self.manager.old_bible_databases self.files = self.manager.old_bible_databases
self.addScrollArea() self.addScrollArea()
self.retranslateUi() self.retranslateUi()
self.maxBibles = len(self.files)
for number, filename in enumerate(self.files): for number, filename in enumerate(self.files):
self.checkBox[number].setCheckState(QtCore.Qt.Checked) self.checkBox[number].setCheckState(QtCore.Qt.Checked)
oldname = filename[1] oldname = filename[1]
@ -516,9 +489,8 @@ class BibleUpgradeForm(OpenLPWizard):
Prepare the UI for the upgrade. Prepare the UI for the upgrade.
""" """
OpenLPWizard.preWizard(self) OpenLPWizard.preWizard(self)
self.progressLabel.setText(translate( self.progressLabel.setText(
'BiblesPlugin.UpgradeWizardForm', translate('BiblesPlugin.UpgradeWizardForm', 'Starting upgrade...'))
'Starting upgrade...'))
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
def performWizard(self): def performWizard(self):
@ -527,46 +499,47 @@ class BibleUpgradeForm(OpenLPWizard):
""" """
self.include_webbible = False self.include_webbible = False
proxy_server = None proxy_server = None
if self.maxBibles == 0: if not self.files:
self.progressLabel.setText( self.progressLabel.setText(
translate('BiblesPlugin.UpgradeWizardForm', 'There are no ' translate('BiblesPlugin.UpgradeWizardForm', 'There are no '
'Bibles that need to be upgraded.')) 'Bibles that need to be upgraded.'))
self.progressBar.hide() self.progressBar.hide()
return return
self.maxBibles = 0 max_bibles = 0
for number, file in enumerate(self.files): for number, file in enumerate(self.files):
if self.checkBox[number].checkState() == QtCore.Qt.Checked: if self.checkBox[number].checkState() == QtCore.Qt.Checked:
self.maxBibles += 1 max_bibles += 1
number = 0 temp_dir = os.path.join(gettempdir(), u'openlp')
for biblenumber, filename in enumerate(self.files): for number, filename in enumerate(self.files):
if self.stop_import_flag: if self.stop_import_flag:
bible_failed = True bible_failed = True
break break
bible_failed = False bible_failed = False
self.success[biblenumber] = False self.success[number] = False
if not self.checkBox[biblenumber].checkState() == QtCore.Qt.Checked: if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
continue continue
self.progressBar.reset() self.progressBar.reset()
oldbible = OldBibleDB(self.mediaItem, path=self.path, oldbible = OldBibleDB(self.mediaItem, path=temp_dir,
file=filename[0]) file=filename[0])
name = filename[1] name = filename[1]
if name is None: if name is None:
print u'no Name!!!'
# FIXME: ?
delete_file(os.path.join(self.path, filename[0])) delete_file(os.path.join(self.path, filename[0]))
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) % 'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, self.maxBibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
number += 1
continue continue
self.progressLabel.setText(unicode(translate( self.progressLabel.setText(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nUpgrading ...')) % 'Upgrading Bible %s of %s: "%s"\nUpgrading ...')) %
(number + 1, self.maxBibles, name)) (number + 1, max_bibles, name))
if os.path.exists(os.path.join(self.path, filename[0])): if os.path.exists(os.path.join(self.path, filename[0])):
name = unicode(self.versionNameEdit[biblenumber].text()) name = unicode(self.versionNameEdit[number].text())
self.newbibles[number] = BibleDB(self.mediaItem, path=self.path, self.newbibles[number] = BibleDB(self.mediaItem, path=self.path,
name=name) name=name, file=filename[0])
self.newbibles[number].register(self.plugin.upgrade_wizard) self.newbibles[number].register(self.plugin.upgrade_wizard)
metadata = oldbible.get_metadata() metadata = oldbible.get_metadata()
webbible = False webbible = False
@ -595,7 +568,7 @@ class BibleUpgradeForm(OpenLPWizard):
u'name: "%s" failed' % ( u'name: "%s" failed' % (
meta_data[u'download source'], meta_data[u'download source'],
meta_data[u'download name'])) meta_data[u'download name']))
delete_database(self.path, clean_filename(name)) delete_database(temp_dir, clean_filename(name))
del self.newbibles[number] del self.newbibles[number]
critical_error_message_box( critical_error_message_box(
translate('BiblesPlugin.UpgradeWizardForm', translate('BiblesPlugin.UpgradeWizardForm',
@ -606,9 +579,8 @@ class BibleUpgradeForm(OpenLPWizard):
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) % 'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, self.maxBibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
number += 1
continue continue
bible = BiblesResourcesDB.get_webbible( bible = BiblesResourcesDB.get_webbible(
meta_data[u'download name'], meta_data[u'download name'],
@ -621,14 +593,13 @@ class BibleUpgradeForm(OpenLPWizard):
language_id = self.newbibles[number].get_language(name) language_id = self.newbibles[number].get_language(name)
if not language_id: if not language_id:
log.warn(u'Upgrading from "%s" failed' % filename[0]) log.warn(u'Upgrading from "%s" failed' % filename[0])
delete_database(self.path, clean_filename(name)) delete_database(temp_dir, clean_filename(name))
del self.newbibles[number] del self.newbibles[number]
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) % 'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, self.maxBibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
number += 1
continue continue
self.progressBar.setMaximum(len(books)) self.progressBar.setMaximum(len(books))
for book in books: for book in books:
@ -639,7 +610,7 @@ class BibleUpgradeForm(OpenLPWizard):
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\n' 'Upgrading Bible %s of %s: "%s"\n'
'Upgrading %s ...')) % 'Upgrading %s ...')) %
(number + 1, self.maxBibles, name, book)) (number + 1, max_bibles, name, book))
book_ref_id = self.newbibles[number].\ book_ref_id = self.newbibles[number].\
get_book_ref_id_by_name(book, len(books), language_id) get_book_ref_id_by_name(book, len(books), language_id)
if not book_ref_id: if not book_ref_id:
@ -647,7 +618,7 @@ class BibleUpgradeForm(OpenLPWizard):
u'name: "%s" aborted by user' % ( u'name: "%s" aborted by user' % (
meta_data[u'download source'], meta_data[u'download source'],
meta_data[u'download name'])) meta_data[u'download name']))
delete_database(self.path, clean_filename(name)) delete_database(temp_dir, clean_filename(name))
del self.newbibles[number] del self.newbibles[number]
bible_failed = True bible_failed = True
break break
@ -678,14 +649,13 @@ class BibleUpgradeForm(OpenLPWizard):
language_id = self.newbibles[number].get_language(name) language_id = self.newbibles[number].get_language(name)
if not language_id: if not language_id:
log.warn(u'Upgrading books from "%s" failed' % name) log.warn(u'Upgrading books from "%s" failed' % name)
delete_database(self.path, clean_filename(name)) delete_database(temp_dir, clean_filename(name))
del self.newbibles[number] del self.newbibles[number]
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) % 'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, self.maxBibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
number += 1
continue continue
books = oldbible.get_books() books = oldbible.get_books()
self.progressBar.setMaximum(len(books)) self.progressBar.setMaximum(len(books))
@ -697,14 +667,14 @@ class BibleUpgradeForm(OpenLPWizard):
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\n' 'Upgrading Bible %s of %s: "%s"\n'
'Upgrading %s ...')) % 'Upgrading %s ...')) %
(number + 1, self.maxBibles, name, book[u'name'])) (number + 1, max_bibles, name, book[u'name']))
book_ref_id = self.newbibles[number].\ book_ref_id = self.newbibles[number].\
get_book_ref_id_by_name(book[u'name'], len(books), get_book_ref_id_by_name(book[u'name'], len(books),
language_id) language_id)
if not book_ref_id: if not book_ref_id:
log.warn(u'Upgrading books from %s " '\ log.warn(u'Upgrading books from %s " '\
'failed - aborted by user' % name) 'failed - aborted by user' % name)
delete_database(self.path, clean_filename(name)) delete_database(temp_dir, clean_filename(name))
del self.newbibles[number] del self.newbibles[number]
bible_failed = True bible_failed = True
break break
@ -729,21 +699,21 @@ class BibleUpgradeForm(OpenLPWizard):
if not bible_failed: if not bible_failed:
self.newbibles[number].create_meta(u'Version', name) self.newbibles[number].create_meta(u'Version', name)
oldbible.close_connection() oldbible.close_connection()
delete_file(os.path.join(self.path, filename[0])) delete_file(os.path.join(temp_dir, filename[0]))
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\n' 'Upgrading Bible %s of %s: "%s"\n'
'Complete')) % 'Complete')) %
(number + 1, self.maxBibles, name)) (number + 1, max_bibles, name))
self.success[biblenumber] = True self.success[number] = True
else: else:
self.incrementProgressBar(unicode(translate( self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm', 'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) % 'Upgrading Bible %s of %s: "%s"\nFailed')) %
(number + 1, self.maxBibles, name), (number + 1, max_bibles, name),
self.progressBar.maximum() - self.progressBar.value()) self.progressBar.maximum() - self.progressBar.value())
delete_database(self.path, clean_filename(name)) delete_database(temp_dir, clean_filename(name))
number += 1 shutil.rmtree(temp_dir, True)
def postWizard(self): def postWizard(self):
""" """
@ -752,7 +722,7 @@ class BibleUpgradeForm(OpenLPWizard):
successful_import = 0 successful_import = 0
failed_import = 0 failed_import = 0
for number, filename in enumerate(self.files): for number, filename in enumerate(self.files):
if number in self.success and self.success[number] == True: if self.success.has_key(number) and self.success[number]:
successful_import += 1 successful_import += 1
elif self.checkBox[number].checkState() == QtCore.Qt.Checked: elif self.checkBox[number].checkState() == QtCore.Qt.Checked:
failed_import += 1 failed_import += 1
@ -776,7 +746,6 @@ class BibleUpgradeForm(OpenLPWizard):
'Bible(s): %s successful%s')) % (successful_import, 'Bible(s): %s successful%s')) % (successful_import,
failed_import_text)) failed_import_text))
else: else:
self.progressLabel.setText( self.progressLabel.setText(translate(
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade ' 'BiblesPlugin.UpgradeWizardForm', 'Upgrade failed.'))
'failed.'))
OpenLPWizard.postWizard(self) OpenLPWizard.postWizard(self)

View File

@ -169,6 +169,7 @@ class BibleDB(QtCore.QObject, Manager):
self.wizard = None self.wizard = None
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
print kwargs, (self.file, self.path)
def stop_import(self): def stop_import(self):
""" """
@ -210,7 +211,7 @@ class BibleDB(QtCore.QObject, Manager):
The book_reference_id from bibles_resources.sqlite of the book. The book_reference_id from bibles_resources.sqlite of the book.
``testament`` ``testament``
*Defaults to 1.* The testament_reference_id from *Defaults to 1.* The testament_reference_id from
bibles_resources.sqlite of the testament this book belongs to. bibles_resources.sqlite of the testament this book belongs to.
""" """
log.debug(u'BibleDB.create_book("%s", "%s")', name, bk_ref_id) log.debug(u'BibleDB.create_book("%s", "%s")', name, bk_ref_id)
@ -329,7 +330,7 @@ class BibleDB(QtCore.QObject, Manager):
return self.get_object_filtered(Book, Book.book_reference_id.like(id)) return self.get_object_filtered(Book, Book.book_reference_id.like(id))
def get_book_ref_id_by_name(self, book, maxbooks, language_id=None): def get_book_ref_id_by_name(self, book, maxbooks, language_id=None):
log.debug(u'BibleDB.get_book_ref_id_by_name:("%s", "%s")', book, log.debug(u'BibleDB.get_book_ref_id_by_name:("%s", "%s")', book,
language_id) language_id)
if BiblesResourcesDB.get_book(book, True): if BiblesResourcesDB.get_book(book, True):
book_temp = BiblesResourcesDB.get_book(book, True) book_temp = BiblesResourcesDB.get_book(book, True)
@ -471,7 +472,7 @@ class BibleDB(QtCore.QObject, Manager):
def get_language(self, bible_name=None): def get_language(self, bible_name=None):
""" """
If no language is given it calls a dialog window where the user could If no language is given it calls a dialog window where the user could
select the bible language. select the bible language.
Return the language id of a bible. Return the language id of a bible.
@ -521,9 +522,9 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
some resources which are used in the Bibles plugin. some resources which are used in the Bibles plugin.
A wrapper class around a small SQLite database which contains the download A wrapper class around a small SQLite database which contains the download
resources, a biblelist from the different download resources, the books, resources, a biblelist from the different download resources, the books,
chapter counts and verse counts for the web download Bibles, a language chapter counts and verse counts for the web download Bibles, a language
reference, the testament reference and some alternative book names. This reference, the testament reference and some alternative book names. This
class contains a singleton "cursor" so that only one connection to the class contains a singleton "cursor" so that only one connection to the
SQLite database is ever used. SQLite database is ever used.
""" """
cursor = None cursor = None
@ -582,7 +583,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
``name`` ``name``
The name or abbreviation of the book. The name or abbreviation of the book.
``lower`` ``lower``
True if the comparsion should be only lowercase True if the comparsion should be only lowercase
""" """
@ -592,7 +593,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
if lower: if lower:
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM book_reference WHERE ' u'abbreviation, chapters FROM book_reference WHERE '
u'LOWER(name) = ? OR LOWER(abbreviation) = ?', u'LOWER(name) = ? OR LOWER(abbreviation) = ?',
(name.lower(), name.lower())) (name.lower(), name.lower()))
else: else:
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
@ -621,7 +622,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
if not isinstance(id, int): if not isinstance(id, int):
id = int(id) id = int(id)
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM book_reference WHERE id = ?', u'abbreviation, chapters FROM book_reference WHERE id = ?',
(id, )) (id, ))
if books: if books:
return { return {
@ -645,12 +646,12 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
``chapter`` ``chapter``
The chapter number. The chapter number.
""" """
log.debug(u'BiblesResourcesDB.get_chapter("%s", "%s")', book_id, log.debug(u'BiblesResourcesDB.get_chapter("%s", "%s")', book_id,
chapter) chapter)
if not isinstance(chapter, int): if not isinstance(chapter, int):
chapter = int(chapter) chapter = int(chapter)
chapters = BiblesResourcesDB.run_sql(u'SELECT id, book_reference_id, ' chapters = BiblesResourcesDB.run_sql(u'SELECT id, book_reference_id, '
u'chapter, verse_count FROM chapters WHERE book_reference_id = ?', u'chapter, verse_count FROM chapters WHERE book_reference_id = ?',
(book_id,)) (book_id,))
if chapters: if chapters:
return { return {
@ -687,7 +688,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
``chapter`` ``chapter``
The number of the chapter. The number of the chapter.
""" """
log.debug(u'BiblesResourcesDB.get_verse_count("%s", "%s")', book_id, log.debug(u'BiblesResourcesDB.get_verse_count("%s", "%s")', book_id,
chapter) chapter)
details = BiblesResourcesDB.get_chapter(book_id, chapter) details = BiblesResourcesDB.get_chapter(book_id, chapter)
if details: if details:
@ -715,7 +716,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
} }
else: else:
return None return None
@staticmethod @staticmethod
def get_webbibles(source): def get_webbibles(source):
""" """
@ -737,7 +738,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
u'id': bible[0], u'id': bible[0],
u'name': bible[1], u'name': bible[1],
u'abbreviation': bible[2], u'abbreviation': bible[2],
u'language_id': bible[3], u'language_id': bible[3],
u'download_source_id': bible[4] u'download_source_id': bible[4]
} }
for bible in bibles for bible in bibles
@ -752,11 +753,11 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
``abbreviation`` ``abbreviation``
The abbreviation of the webbible. The abbreviation of the webbible.
``source`` ``source``
The source of the webbible. The source of the webbible.
""" """
log.debug(u'BiblesResourcesDB.get_webbibles("%s", "%s")', abbreviation, log.debug(u'BiblesResourcesDB.get_webbibles("%s", "%s")', abbreviation,
source) source)
if not isinstance(abbreviation, unicode): if not isinstance(abbreviation, unicode):
abbreviation = unicode(abbreviation) abbreviation = unicode(abbreviation)
@ -765,14 +766,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
source = BiblesResourcesDB.get_download_source(source) source = BiblesResourcesDB.get_download_source(source)
bible = BiblesResourcesDB.run_sql(u'SELECT id, name, abbreviation, ' bible = BiblesResourcesDB.run_sql(u'SELECT id, name, abbreviation, '
u'language_id, download_source_id FROM webbibles WHERE ' u'language_id, download_source_id FROM webbibles WHERE '
u'download_source_id = ? AND abbreviation = ?', (source[u'id'], u'download_source_id = ? AND abbreviation = ?', (source[u'id'],
abbreviation)) abbreviation))
if bible: if bible:
return { return {
u'id': bible[0][0], u'id': bible[0][0],
u'name': bible[0][1], u'name': bible[0][1],
u'abbreviation': bible[0][2], u'abbreviation': bible[0][2],
u'language_id': bible[0][3], u'language_id': bible[0][3],
u'download_source_id': bible[0][4] u'download_source_id': bible[0][4]
} }
else: else:
@ -785,11 +786,11 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
``name`` ``name``
The name to search the id. The name to search the id.
``language_id`` ``language_id``
The language_id for which language should be searched The language_id for which language should be searched
""" """
log.debug(u'BiblesResourcesDB.get_alternative_book_name("%s", "%s")', log.debug(u'BiblesResourcesDB.get_alternative_book_name("%s", "%s")',
name, language_id) name, language_id)
if language_id: if language_id:
books = BiblesResourcesDB.run_sql(u'SELECT book_reference_id, name ' books = BiblesResourcesDB.run_sql(u'SELECT book_reference_id, name '
@ -806,7 +807,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
@staticmethod @staticmethod
def get_language(name): def get_language(name):
""" """
Return a dict containing the language id, name and code by name or Return a dict containing the language id, name and code by name or
abbreviation. abbreviation.
``name`` ``name``
@ -865,7 +866,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
class AlternativeBookNamesDB(QtCore.QObject, Manager): class AlternativeBookNamesDB(QtCore.QObject, Manager):
""" """
This class represents a database-bound alternative book names system. This class represents a database-bound alternative book names system.
""" """
cursor = None cursor = None
conn = None conn = None
@ -874,7 +875,7 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
def get_cursor(): def get_cursor():
""" """
Return the cursor object. Instantiate one if it doesn't exist yet. Return the cursor object. Instantiate one if it doesn't exist yet.
If necessary loads up the database and creates the tables if the If necessary loads up the database and creates the tables if the
database doesn't exist. database doesn't exist.
""" """
if AlternativeBookNamesDB.cursor is None: if AlternativeBookNamesDB.cursor is None:
@ -904,7 +905,7 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
``parameters`` ``parameters``
Any variable parameters to add to the query Any variable parameters to add to the query
``commit`` ``commit``
If a commit statement is necessary this should be True. If a commit statement is necessary this should be True.
""" """
@ -921,11 +922,11 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
``name`` ``name``
The name to search the id. The name to search the id.
``language_id`` ``language_id``
The language_id for which language should be searched The language_id for which language should be searched
""" """
log.debug(u'AlternativeBookNamesDB.get_book_reference_id("%s", "%s")', log.debug(u'AlternativeBookNamesDB.get_book_reference_id("%s", "%s")',
name, language_id) name, language_id)
if language_id: if language_id:
books = AlternativeBookNamesDB.run_sql(u'SELECT book_reference_id, ' books = AlternativeBookNamesDB.run_sql(u'SELECT book_reference_id, '
@ -962,11 +963,11 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
class OldBibleDB(QtCore.QObject, Manager): class OldBibleDB(QtCore.QObject, Manager):
""" """
This class conects to the old bible databases to reimport them to the new This class conects to the old bible databases to reimport them to the new
database scheme. database scheme.
""" """
cursor = None cursor = None
def __init__(self, parent, **kwargs): def __init__(self, parent, **kwargs):
""" """
The constructor loads up the database and creates and initialises the The constructor loads up the database and creates and initialises the

View File

@ -153,7 +153,7 @@ class BibleManager(object):
if name is None: if name is None:
delete_file(os.path.join(self.path, filename)) delete_file(os.path.join(self.path, filename))
continue continue
# Find old database versions # Find old database versions.
if bible.is_old_database(): if bible.is_old_database():
self.old_bible_databases.append([filename, name]) self.old_bible_databases.append([filename, name])
bible.session.close() bible.session.close()
@ -220,7 +220,7 @@ class BibleManager(object):
return [ return [
{ {
u'name': book.name, u'name': book.name,
u'book_reference_id': book.book_reference_id, u'book_reference_id': book.book_reference_id,
u'chapters': self.db_cache[bible].get_chapter_count(book) u'chapters': self.db_cache[bible].get_chapter_count(book)
} }
for book in self.db_cache[bible].get_books() for book in self.db_cache[bible].get_books()
@ -229,10 +229,10 @@ class BibleManager(object):
def get_chapter_count(self, bible, book): def get_chapter_count(self, bible, book):
""" """
Returns the number of Chapters for a given book. Returns the number of Chapters for a given book.
``bible`` ``bible``
Unicode. The Bible to get the list of books from. Unicode. The Bible to get the list of books from.
``book`` ``book``
The book object to get the chapter count for. The book object to get the chapter count for.
""" """
@ -295,7 +295,7 @@ class BibleManager(object):
if db_book: if db_book:
book_id = db_book.book_reference_id book_id = db_book.book_reference_id
log.debug(u'Book name corrected to "%s"', db_book.name) log.debug(u'Book name corrected to "%s"', db_book.name)
new_reflist.append((book_id, item[1], item[2], new_reflist.append((book_id, item[1], item[2],
item[3])) item[3]))
else: else:
log.debug(u'OpenLP failed to find book %s', item[0]) log.debug(u'OpenLP failed to find book %s', item[0])

View File

@ -612,7 +612,7 @@ class BibleMediaItem(MediaManagerItem):
if restore: if restore:
old_text = unicode(combo.currentText()) old_text = unicode(combo.currentText())
combo.clear() combo.clear()
combo.addItems([unicode(i) for i in range(range_from, range_to + 1)]) combo.addItems(map(unicode, range(range_from, range_to + 1)))
if restore and combo.findText(old_text) != -1: if restore and combo.findText(old_text) != -1:
combo.setCurrentIndex(combo.findText(old_text)) combo.setCurrentIndex(combo.findText(old_text))