new function get_language in BibleDB which ask for the language a bible is and return a language_id

This commit is contained in:
Armin Köhler 2011-04-02 22:22:35 +02:00
parent 9de33cf194
commit fbce21baaa
7 changed files with 32 additions and 33 deletions

View File

@ -139,14 +139,11 @@ class CSVBible(BibleDB):
self.wizard.progressBar.setMinimum(0)
self.wizard.progressBar.setMaximum(66)
success = True
language = self.parent.manager.import_wizard.languageDialog()
if not language:
log.exception(u'Importing books from %s " '\
'failed' % self.booksfile)
language_id = self.get_language()
if not language_id:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)
return False
language = BiblesResourcesDB.get_language(language)
language_id = language[u'id']
self.create_meta(u'language_id', language_id)
books_file = None
book_list = {}
# Populate the Tables

View File

@ -489,6 +489,22 @@ class BibleDB(QtCore.QObject, Manager):
else:
return count
def get_language(self):
"""
Return the language of a bible.
``book``
The language the bible is.
"""
log.debug(u'BibleDB.get_language()')
language = self.bible_plugin.manager.import_wizard.languageDialog()
if not language:
return False
language = BiblesResourcesDB.get_language(language)
language_id = language[u'id']
self.create_meta(u'language_id', language_id)
return language_id
def dump_bible(self):
"""
Utility debugging method to dump the contents of a bible.

View File

@ -413,16 +413,13 @@ class HTTPBible(BibleDB):
self.download_source.lower())
if bible[u'language_id']:
language_id = bible[u'language_id']
self.create_meta(u'language_id', language_id)
else:
language = self.parent.manager.import_wizard.languageDialog()
if not language:
log.exception(u'Importing books from %s - download name: "%s" '\
'failed' % (self.download_source, self.download_name))
return False
language = BiblesResourcesDB.get_language(language)
language_id = language[u'id']
# Store the language_id.
self.create_meta(u'language_id', language_id)
language_id = self.get_language()
if not language_id:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)
return False
for book in books:
self.wizard.incrementProgressBar(unicode(translate(
'BiblesPlugin.HTTPBible', 'Importing %s...',

View File

@ -349,9 +349,7 @@ class BibleManager(object):
book, language_id)
else:
book_ref = self.import_wizard.bookNameDialog(book)
log.debug(book_ref)
book_temp = BiblesResourcesDB.get_book(book_ref)
log.debug(book_temp)
if book_temp:
book_id = book_temp[u'id']
else:

View File

@ -58,14 +58,11 @@ class OpenLP1Bible(BibleDB):
except:
return False
#Create the bible language
language = self.parent.manager.import_wizard.languageDialog()
if not language:
language_id = self.get_language()
if not language_id:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)
return False
language = BiblesResourcesDB.get_language(language)
language_id = language[u'id']
self.create_meta(u'language_id', language_id)
# Create all books.
cursor.execute(u'SELECT id, testament_id, name, abbreviation FROM book')
books = cursor.fetchall()

View File

@ -62,14 +62,11 @@ class OpenSongBible(BibleDB):
file = open(self.filename, u'r')
opensong = objectify.parse(file)
bible = opensong.getroot()
language = self.parent.manager.import_wizard.languageDialog()
if not language:
language_id = self.get_language()
if not language_id:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)
return False
language = BiblesResourcesDB.get_language(language)
language_id = language[u'id']
self.create_meta(u'language_id', language_id)
for book in bible.b:
if self.stop_import_flag:
break

View File

@ -107,14 +107,11 @@ class OSISBible(BibleDB):
if detect_file:
detect_file.close()
# Set meta language_id
language = self.parent.manager.import_wizard.languageDialog()
if not language:
language_id = self.get_language()
if not language_id:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)
return False
language = BiblesResourcesDB.get_language(language)
language_id = language[u'id']
self.create_meta(u'language_id', language_id)
try:
osis = codecs.open(self.filename, u'r', details['encoding'])
for file_record in osis: