Exemplo n.º 1
0
    def __init__(self, parent, **kwargs):
        """
        Finds all the bibles defined for the system. Creates an Interface Object for each bible containing connection
        information.

        Throws Exception if no Bibles are found.

        Init confirms the bible exists and stores the database path.
        """
        BibleDB.__init__(self, parent, **kwargs)
        self.download_source = kwargs['download_source']
        self.download_name = kwargs['download_name']
        # TODO: Clean up proxy stuff. We probably want one global proxy per connection type (HTTP and HTTPS) at most.
        self.proxy_server = None
        self.proxy_username = None
        self.proxy_password = None
        self.language_id = None
        if 'path' in kwargs:
            self.path = kwargs['path']
        if 'proxy_server' in kwargs:
            self.proxy_server = kwargs['proxy_server']
        if 'proxy_username' in kwargs:
            self.proxy_username = kwargs['proxy_username']
        if 'proxy_password' in kwargs:
            self.proxy_password = kwargs['proxy_password']
        if 'language_id' in kwargs:
            self.language_id = kwargs['language_id']
Exemplo n.º 2
0
 def __init__(self, parent, **kwargs):
     """
     Constructor.
     """
     log.debug(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.filename = kwargs[u'filename']
Exemplo n.º 3
0
    def __init__(self, parent, **kwargs):
        """
        Finds all the bibles defined for the system. Creates an Interface Object for each bible containing connection
        information.

        Throws Exception if no Bibles are found.

        Init confirms the bible exists and stores the database path.
        """
        BibleDB.__init__(self, parent, **kwargs)
        self.download_source = kwargs["download_source"]
        self.download_name = kwargs["download_name"]
        # TODO: Clean up proxy stuff. We probably want one global proxy per connection type (HTTP and HTTPS) at most.
        self.proxy_server = None
        self.proxy_username = None
        self.proxy_password = None
        self.language_id = None
        if "path" in kwargs:
            self.path = kwargs["path"]
        if "proxy_server" in kwargs:
            self.proxy_server = kwargs["proxy_server"]
        if "proxy_username" in kwargs:
            self.proxy_username = kwargs["proxy_username"]
        if "proxy_password" in kwargs:
            self.proxy_password = kwargs["proxy_password"]
        if "language_id" in kwargs:
            self.language_id = kwargs["language_id"]
Exemplo n.º 4
0
 def __init__(self, parent, **kwargs):
     log.debug(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.filename = kwargs[u'filename']
     self.language_regex = re.compile(r'<language.*>(.*?)</language>')
     self.verse_regex = re.compile(
         r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
     self.note_regex = re.compile(r'<note(.*?)>(.*?)</note>')
     self.title_regex = re.compile(r'<title(.*?)>(.*?)</title>')
     self.milestone_regex = re.compile(r'<milestone(.*?)/>')
     self.fi_regex = re.compile(r'<FI>(.*?)<Fi>')
     self.rf_regex = re.compile(r'<RF>(.*?)<Rf>')
     self.lb_regex = re.compile(r'<lb(.*?)>')
     self.lg_regex = re.compile(r'<lg(.*?)>')
     self.l_regex = re.compile(r'<l (.*?)>')
     self.w_regex = re.compile(r'<w (.*?)>')
     self.q_regex = re.compile(r'<q(.*?)>')
     self.q1_regex = re.compile(r'<q(.*?)level="1"(.*?)>')
     self.q2_regex = re.compile(r'<q(.*?)level="2"(.*?)>')
     self.trans_regex = re.compile(r'<transChange(.*?)>(.*?)</transChange>')
     self.divine_name_regex = re.compile(
         r'<divineName(.*?)>(.*?)</divineName>')
     self.spaces_regex = re.compile(r'([ ]{2,})')
     filepath = os.path.join(
         AppLocation.get_directory(AppLocation.PluginsDir), u'bibles', u'resources', u'osisbooks.csv')
Exemplo n.º 5
0
 def __init__(self, parent, **kwargs):
     """
     Constructor to create and set up an instance of the OpenSongBible class. This class is used to import Bibles
     from OpenSong's XML format.
     """
     log.debug(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.filename = kwargs['filename']
Exemplo n.º 6
0
 def __init__(self, parent, **kwargs):
     """
     Constructor to create and set up an instance of the ZefaniaBible class. This class is used to import Bibles
     from ZefaniaBible's XML format.
     """
     log.debug(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.filename = kwargs['filename']
Exemplo n.º 7
0
 def __init__(self, parent, **kwargs):
     """
     Loads a Bible from a set of CSV files. This class assumes the files contain all the information and a clean
     bible is being loaded.
     """
     log.info(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.booksfile = kwargs['booksfile']
     self.versesfile = kwargs['versefile']
Exemplo n.º 8
0
 def __init__(self, parent, **kwargs):
     """
     Loads a Bible from a set of CSV files. This class assumes the files contain all the information and a clean
     bible is being loaded.
     """
     log.info(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.books_file = kwargs['booksfile']
     self.verses_file = kwargs['versefile']
Exemplo n.º 9
0
    def get_verses(self, reference_list, show_error=True):
        """
        A reimplementation of the ``BibleDB.get_verses`` method, this one is specifically for web Bibles. It first
        checks to see if the particular chapter exists in the DB, and if not it pulls it from the web. If the chapter
        DOES exist, it simply pulls the verses from the DB using the ancestor method.

        ``reference_list``
            This is the list of references the media manager item wants. It is a list of tuples, with the following
            format::

                (book_reference_id, chapter, start_verse, end_verse)

            Therefore, when you are looking for multiple items, simply break them up into references like this, bundle
            them into a list. This function then runs through the list, and returns an amalgamated list of ``Verse``
            objects. For example::

                [('35', 1, 1, 1), ('35', 2, 2, 3)]
        """
        log.debug('HTTPBible.get_verses("%s")', reference_list)
        for reference in reference_list:
            book_id = reference[0]
            db_book = self.get_book_by_book_ref_id(book_id)
            if not db_book:
                if show_error:
                    critical_error_message_box(
                        translate("BiblesPlugin", "No Book Found"),
                        translate(
                            "BiblesPlugin",
                            "No matching book could be found in this Bible. Check that you have "
                            "spelled the name of the book correctly.",
                        ),
                    )
                return []
            book = db_book.name
            if BibleDB.get_verse_count(self, book_id, reference[1]) == 0:
                self.application.set_busy_cursor()
                search_results = self.get_chapter(book, reference[1])
                if search_results and search_results.has_verse_list():
                    # We have found a book of the bible lets check to see
                    # if it was there. By reusing the returned book name
                    # we get a correct book. For example it is possible
                    # to request ac and get Acts back.
                    book_name = search_results.book
                    self.application.process_events()
                    # Check to see if book/chapter exists.
                    db_book = self.get_book(book_name)
                    self.create_chapter(db_book.id, search_results.chapter, search_results.verse_list)
                    self.application.process_events()
                self.application.set_normal_cursor()
            self.application.process_events()
        return BibleDB.get_verses(self, reference_list, show_error)
Exemplo n.º 10
0
    def get_verses(self, reference_list, show_error=True):
        """
        A reimplementation of the ``BibleDB.get_verses`` method, this one is specifically for web Bibles. It first
        checks to see if the particular chapter exists in the DB, and if not it pulls it from the web. If the chapter
        DOES exist, it simply pulls the verses from the DB using the ancestor method.

        ``reference_list``
            This is the list of references the media manager item wants. It is a list of tuples, with the following
            format::

                (book_reference_id, chapter, start_verse, end_verse)

            Therefore, when you are looking for multiple items, simply break them up into references like this, bundle
            them into a list. This function then runs through the list, and returns an amalgamated list of ``Verse``
            objects. For example::

                [('35', 1, 1, 1), ('35', 2, 2, 3)]
        """
        log.debug('HTTPBible.get_verses("{ref}")'.format(ref=reference_list))
        for reference in reference_list:
            book_id = reference[0]
            db_book = self.get_book_by_book_ref_id(book_id)
            if not db_book:
                if show_error:
                    critical_error_message_box(
                        translate('BiblesPlugin', 'No Book Found'),
                        translate(
                            'BiblesPlugin',
                            'No matching book could be found in this Bible. Check that you have '
                            'spelled the name of the book correctly.'))
                return []
            book = db_book.name
            if BibleDB.get_verse_count(self, book_id, reference[1]) == 0:
                self.application.set_busy_cursor()
                search_results = self.get_chapter(book, reference[1])
                if search_results and search_results.has_verse_list():
                    # We have found a book of the bible lets check to see
                    # if it was there. By reusing the returned book name
                    # we get a correct book. For example it is possible
                    # to request ac and get Acts back.
                    book_name = search_results.book
                    self.application.process_events()
                    # Check to see if book/chapter exists.
                    db_book = self.get_book(book_name)
                    self.create_chapter(db_book.id, search_results.chapter,
                                        search_results.verse_list)
                    self.application.process_events()
                self.application.set_normal_cursor()
            self.application.process_events()
        return BibleDB.get_verses(self, reference_list, show_error)
Exemplo n.º 11
0
 def reload_bibles(self):
     """
     Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance
     of HTTPBible is loaded instead of the BibleDB class.
     """
     log.debug('Reload bibles')
     files = AppLocation.get_files(self.settings_section, self.suffix)
     if 'alternative_book_names.sqlite' in files:
         files.remove('alternative_book_names.sqlite')
     log.debug('Bible Files %s', files)
     self.db_cache = {}
     self.old_bible_databases = []
     for filename in files:
         bible = BibleDB(self.parent, path=self.path, file=filename)
         if not bible.session:
             continue
         name = bible.get_name()
         # Remove corrupted files.
         if name is None:
             bible.session.close()
             delete_file(os.path.join(self.path, filename))
             continue
         # Find old database versions.
         if bible.is_old_database():
             self.old_bible_databases.append([filename, name])
             bible.session.close()
             continue
         log.debug('Bible Name: "%s"', name)
         self.db_cache[name] = bible
         # Look to see if lazy load bible exists and get create getter.
         source = self.db_cache[name].get_object(BibleMeta,
                                                 'download_source')
         if source:
             download_name = self.db_cache[name].get_object(
                 BibleMeta, 'download_name').value
             meta_proxy = self.db_cache[name].get_object(
                 BibleMeta, 'proxy_server')
             web_bible = HTTPBible(self.parent,
                                   path=self.path,
                                   file=filename,
                                   download_source=source.value,
                                   download_name=download_name)
             if meta_proxy:
                 web_bible.proxy_server = meta_proxy.value
             self.db_cache[name] = web_bible
     log.debug('Bibles reloaded')
Exemplo n.º 12
0
 def reload_bibles(self):
     """
     Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance
     of HTTPBible is loaded instead of the BibleDB class.
     """
     log.debug('Reload bibles')
     files = AppLocation.get_files(self.settings_section, self.suffix)
     if 'alternative_book_names.sqlite' in files:
         files.remove('alternative_book_names.sqlite')
     log.debug('Bible Files %s', files)
     self.db_cache = {}
     self.old_bible_databases = []
     for filename in files:
         bible = BibleDB(self.parent, path=self.path, file=filename)
         if not bible.session:
             continue
         name = bible.get_name()
         # Remove corrupted files.
         if name is None:
             bible.session.close()
             delete_file(os.path.join(self.path, filename))
             continue
         # Find old database versions.
         if bible.is_old_database():
             self.old_bible_databases.append([filename, name])
             bible.session.close()
             continue
         log.debug('Bible Name: "%s"', name)
         self.db_cache[name] = bible
         # Look to see if lazy load bible exists and get create getter.
         source = self.db_cache[name].get_object(BibleMeta, 'download_source')
         if source:
             download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value
             meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server')
             web_bible = HTTPBible(self.parent, path=self.path, file=filename, download_source=source.value,
                                   download_name=download_name)
             if meta_proxy:
                 web_bible.proxy_server = meta_proxy.value
             self.db_cache[name] = web_bible
     log.debug('Bibles reloaded')
Exemplo n.º 13
0
 def reload_bibles(self):
     """
     Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance
     of HTTPBible is loaded instead of the BibleDB class.
     """
     log.debug('Reload bibles')
     file_paths = AppLocation.get_files(self.settings_section, self.suffix)
     if Path('alternative_book_names.sqlite') in file_paths:
         file_paths.remove(Path('alternative_book_names.sqlite'))
     log.debug('Bible Files {text}'.format(text=file_paths))
     self.db_cache = {}
     for file_path in file_paths:
         bible = BibleDB(self.parent, path=self.path, file=file_path)
         if not bible.session:
             continue
         name = bible.get_name()
         # Remove corrupted files.
         if name is None:
             bible.session.close_all()
             delete_file(self.path / file_path)
             continue
         log.debug('Bible Name: "{name}"'.format(name=name))
         self.db_cache[name] = bible
         # Look to see if lazy load bible exists and get create getter.
         if self.db_cache[name].is_web_bible:
             source = self.db_cache[name].get_object(
                 BibleMeta, 'download_source')
             download_name = self.db_cache[name].get_object(
                 BibleMeta, 'download_name').value
             meta_proxy = self.db_cache[name].get_object(
                 BibleMeta, 'proxy_server')
             web_bible = HTTPBible(self.parent,
                                   path=self.path,
                                   file=file_path,
                                   download_source=source.value,
                                   download_name=download_name)
             if meta_proxy:
                 web_bible.proxy_server = meta_proxy.value
             self.db_cache[name] = web_bible
     log.debug('Bibles reloaded')
Exemplo n.º 14
0
Arquivo: osis.py Projeto: jkunle/paul
 def __init__(self, parent, **kwargs):
     log.debug(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.filename = kwargs['filename']
Exemplo n.º 15
0
 def perform_wizard(self):
     """
     Perform the actual upgrade.
     """
     self.includeWebBible = False
     proxy_server = None
     if not self.files:
         self.progress_label.setText(
             translate('BiblesPlugin.UpgradeWizardForm',
                       'There are no Bibles that need to be upgraded.'))
         self.progress_bar.hide()
         return
     max_bibles = 0
     for number, file in enumerate(self.files):
         if self.checkBox[number].checkState() == QtCore.Qt.Checked:
             max_bibles += 1
     old_bible = None
     for number, filename in enumerate(self.files):
         # Close the previous bible's connection.
         if old_bible is not None:
             old_bible.close_connection()
             # Set to None to make obvious that we have already closed the
             # database.
             old_bible = None
         if self.stop_import_flag:
             self.success[number] = False
             break
         if not self.checkBox[number].checkState() == QtCore.Qt.Checked:
             self.success[number] = False
             continue
         self.progress_bar.reset()
         old_bible = OldBibleDB(self.media_item,
                                path=self.temp_dir,
                                file=filename[0])
         name = filename[1]
         self.progress_label.setText(
             translate('BiblesPlugin.UpgradeWizardForm',
                       'Upgrading Bible %s of %s: "%s"\nUpgrading ...') %
             (number + 1, max_bibles, name))
         self.new_bibles[number] = BibleDB(self.media_item,
                                           path=self.path,
                                           name=name,
                                           file=filename[0])
         self.new_bibles[number].register(self.plugin.upgrade_wizard)
         metadata = old_bible.get_metadata()
         web_bible = False
         meta_data = {}
         for meta in metadata:
             # Upgrade the names of the metadata keys
             if meta['key'] == 'Version':
                 meta['key'] = 'name'
             if meta['key'] == 'Bookname language':
                 meta['key'] = 'book_name_language'
             meta['key'] = meta['key'].lower().replace(' ', '_')
             # Copy the metadata
             meta_data[meta['key']] = meta['value']
             if meta['key'] != 'name' and meta['key'] != 'dbversion':
                 self.new_bibles[number].save_meta(meta['key'],
                                                   meta['value'])
             if meta['key'] == 'download_source':
                 web_bible = True
                 self.includeWebBible = True
             proxy_server = meta.get('proxy_server')
         if web_bible:
             if meta_data['download_source'].lower() == 'crosswalk':
                 handler = CWExtract(proxy_server)
             elif meta_data['download_source'].lower() == 'biblegateway':
                 handler = BGExtract(proxy_server)
             elif meta_data['download_source'].lower() == 'bibleserver':
                 handler = BSExtract(proxy_server)
             books = handler.get_books_from_http(meta_data['download_name'])
             if not books:
                 log.error(
                     'Upgrading books from %s - download name: "%s" failed'
                     % (meta_data['download_source'],
                        meta_data['download_name']))
                 self.new_bibles[number].session.close()
                 del self.new_bibles[number]
                 critical_error_message_box(
                     translate('BiblesPlugin.UpgradeWizardForm',
                               'Download Error'),
                     translate(
                         'BiblesPlugin.UpgradeWizardForm',
                         'To upgrade your Web Bibles an Internet connection is required.'
                     ))
                 self.increment_progress_bar(
                     translate('BiblesPlugin.UpgradeWizardForm',
                               'Upgrading Bible %s of %s: "%s"\nFailed') %
                     (number + 1, max_bibles, name),
                     self.progress_bar.maximum() -
                     self.progress_bar.value())
                 self.success[number] = False
                 continue
             bible = BiblesResourcesDB.get_webbible(
                 meta_data['download_name'],
                 meta_data['download_source'].lower())
             if bible and bible['language_id']:
                 language_id = bible['language_id']
                 self.new_bibles[number].save_meta('language_id',
                                                   language_id)
             else:
                 language_id = self.new_bibles[number].get_language(name)
             if not language_id:
                 log.warning('Upgrading from "%s" failed' % filename[0])
                 self.new_bibles[number].session.close()
                 del self.new_bibles[number]
                 self.increment_progress_bar(
                     translate('BiblesPlugin.UpgradeWizardForm',
                               'Upgrading Bible %s of %s: "%s"\nFailed') %
                     (number + 1, max_bibles, name),
                     self.progress_bar.maximum() -
                     self.progress_bar.value())
                 self.success[number] = False
                 continue
             self.progress_bar.setMaximum(len(books))
             for book in books:
                 if self.stop_import_flag:
                     self.success[number] = False
                     break
                 self.increment_progress_bar(
                     translate(
                         'BiblesPlugin.UpgradeWizardForm',
                         'Upgrading Bible %s of %s: "%s"\nUpgrading %s ...')
                     % (number + 1, max_bibles, name, book))
                 book_ref_id = self.new_bibles[number].\
                     get_book_ref_id_by_name(book, len(books), language_id)
                 if not book_ref_id:
                     log.warning(
                         'Upgrading books from %s - download name: "%s" aborted by user'
                         % (meta_data['download_source'],
                            meta_data['download_name']))
                     self.new_bibles[number].session.close()
                     del self.new_bibles[number]
                     self.success[number] = False
                     break
                 book_details = BiblesResourcesDB.get_book_by_id(
                     book_ref_id)
                 db_book = self.new_bibles[number].create_book(
                     book, book_ref_id, book_details['testament_id'])
                 # Try to import already downloaded verses.
                 oldbook = old_bible.get_book(book)
                 if oldbook:
                     verses = old_bible.get_verses(oldbook['id'])
                     if not verses:
                         log.warning(
                             'No verses found to import for book "%s"',
                             book)
                         continue
                     for verse in verses:
                         if self.stop_import_flag:
                             self.success[number] = False
                             break
                         self.new_bibles[number].create_verse(
                             db_book.id, int(verse['chapter']),
                             int(verse['verse']), str(verse['text']))
                         self.application.process_events()
                     self.new_bibles[number].session.commit()
         else:
             language_id = self.new_bibles[number].get_object(
                 BibleMeta, 'language_id')
             if not language_id:
                 language_id = self.new_bibles[number].get_language(name)
             if not language_id:
                 log.warning('Upgrading books from "%s" failed' % name)
                 self.new_bibles[number].session.close()
                 del self.new_bibles[number]
                 self.increment_progress_bar(
                     translate('BiblesPlugin.UpgradeWizardForm',
                               'Upgrading Bible %s of %s: "%s"\nFailed') %
                     (number + 1, max_bibles, name),
                     self.progress_bar.maximum() -
                     self.progress_bar.value())
                 self.success[number] = False
                 continue
             books = old_bible.get_books()
             self.progress_bar.setMaximum(len(books))
             for book in books:
                 if self.stop_import_flag:
                     self.success[number] = False
                     break
                 self.increment_progress_bar(
                     translate(
                         'BiblesPlugin.UpgradeWizardForm',
                         'Upgrading Bible %s of %s: "%s"\nUpgrading %s ...')
                     % (number + 1, max_bibles, name, book['name']))
                 book_ref_id = self.new_bibles[
                     number].get_book_ref_id_by_name(
                         book['name'], len(books), language_id)
                 if not book_ref_id:
                     log.warning(
                         'Upgrading books from %s " failed - aborted by user'
                         % name)
                     self.new_bibles[number].session.close()
                     del self.new_bibles[number]
                     self.success[number] = False
                     break
                 book_details = BiblesResourcesDB.get_book_by_id(
                     book_ref_id)
                 db_book = self.new_bibles[number].create_book(
                     book['name'], book_ref_id,
                     book_details['testament_id'])
                 verses = old_bible.get_verses(book['id'])
                 if not verses:
                     log.warning('No verses found to import for book "%s"',
                                 book['name'])
                     self.new_bibles[number].delete_book(db_book)
                     continue
                 for verse in verses:
                     if self.stop_import_flag:
                         self.success[number] = False
                         break
                     self.new_bibles[number].create_verse(
                         db_book.id, int(verse['chapter']),
                         int(verse['verse']), str(verse['text']))
                     self.application.process_events()
                 self.new_bibles[number].session.commit()
         if not self.success.get(number, True):
             self.increment_progress_bar(
                 translate('BiblesPlugin.UpgradeWizardForm',
                           'Upgrading Bible %s of %s: "%s"\nFailed') %
                 (number + 1, max_bibles, name),
                 self.progress_bar.maximum() - self.progress_bar.value())
         else:
             self.success[number] = True
             self.new_bibles[number].save_meta('name', name)
             self.increment_progress_bar(
                 translate('BiblesPlugin.UpgradeWizardForm',
                           'Upgrading Bible %s of %s: "%s"\nComplete') %
                 (number + 1, max_bibles, name))
         if number in self.new_bibles:
             self.new_bibles[number].session.close()
     # Close the last bible's connection if possible.
     if old_bible is not None:
         old_bible.close_connection()
Exemplo n.º 16
0
 def __init__(self, parent, **kwargs):
     log.debug(self.__class__.__name__)
     BibleDB.__init__(self, parent, **kwargs)
     self.filename = kwargs['filename']