From 299b80734583bc9c0c23b62a255cd2666ca95e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Wed, 29 Feb 2012 13:00:05 +0100 Subject: [PATCH 1/3] add language auto detection for osis bible files --- openlp/plugins/bibles/lib/osis.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 3fac48f19..400aaff7c 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -53,6 +53,7 @@ class OSISBible(BibleDB): self.filename = kwargs[u'filename'] fbibles = None self.books = {} + self.language_regex = re.compile(r'(.*?)') self.verse_regex = re.compile( r'(.*?)') self.note_regex = re.compile(r'(.*?)') @@ -107,14 +108,25 @@ class OSISBible(BibleDB): finally: if detect_file: detect_file.close() - # Set meta language_id - language_id = self.get_language(bible_name) - if not language_id: - log.exception(u'Importing books from "%s" failed' % self.filename) - return False try: osis = codecs.open(self.filename, u'r', details['encoding']) repl = replacement + # Set meta language_id + for file_record in osis: + if self.stop_import_flag: + break + match = self.language_regex.search(file_record) + if match: + language = BiblesResourcesDB.get_language(match.group(1)) + if language: + self.create_meta(u'language_id', language[u'id']) + else: + language_id = self.get_language(bible_name) + if not language_id: + log.exception(u'Importing books from "%s" failed' + % self.filename) + return False + break for file_record in osis: if self.stop_import_flag: break From 16d1125e84a22d70d6dc819a6b73f50a870abc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Wed, 29 Feb 2012 13:05:27 +0100 Subject: [PATCH 2/3] small fix --- openlp/plugins/bibles/lib/osis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 400aaff7c..defaca85c 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -119,7 +119,8 @@ class OSISBible(BibleDB): if match: language = BiblesResourcesDB.get_language(match.group(1)) if language: - self.create_meta(u'language_id', language[u'id']) + language_id = language[u'id'] + self.create_meta(u'language_id', language_id) else: language_id = self.get_language(bible_name) if not language_id: From 45e0d83600c65228f43b5fd96e7acc010bea41b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Thu, 1 Mar 2012 19:09:47 +0100 Subject: [PATCH 3/3] fix and improve auto detecting language in osis bible files --- openlp/plugins/bibles/lib/osis.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index defaca85c..4afee912d 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -111,28 +111,29 @@ class OSISBible(BibleDB): try: osis = codecs.open(self.filename, u'r', details['encoding']) repl = replacement - # Set meta language_id + language_id = False for file_record in osis: if self.stop_import_flag: break - match = self.language_regex.search(file_record) + # Try to find the bible language + if not language_id: + language_match = self.language_regex.search(file_record) + if language_match: + language = BiblesResourcesDB.get_language( + language_match.group(1)) + if language: + language_id = language[u'id'] + self.create_meta(u'language_id', language_id) + continue + match = self.verse_regex.search(file_record) if match: - language = BiblesResourcesDB.get_language(match.group(1)) - if language: - language_id = language[u'id'] - self.create_meta(u'language_id', language_id) - else: + # Set meta language_id if not detected till now + if not language_id: language_id = self.get_language(bible_name) if not language_id: log.exception(u'Importing books from "%s" failed' % self.filename) return False - break - for file_record in osis: - if self.stop_import_flag: - break - match = self.verse_regex.search(file_record) - if match: match_count += 1 book = match.group(1) chapter = int(match.group(2))