Exemplo n.º 1
0
 def perform_wizard(self):
     """
     Perform the actual import.
     """
     bible_type = self.field('source_format')
     license_version = self.field('license_version')
     license_copyright = self.field('license_copyright')
     license_permissions = self.field('license_permissions')
     importer = None
     if bible_type == BibleFormat.OSIS:
         # Import an OSIS bible.
         importer = self.manager.import_bible(BibleFormat.OSIS, name=license_version,
                                              filename=self.field('osis_location'))
     elif bible_type == BibleFormat.CSV:
         # Import a CSV bible.
         importer = self.manager.import_bible(BibleFormat.CSV, name=license_version,
                                              booksfile=self.field('csv_booksfile'),
                                              versefile=self.field('csv_versefile'))
     elif bible_type == BibleFormat.OpenSong:
         # Import an OpenSong bible.
         importer = self.manager.import_bible(BibleFormat.OpenSong, name=license_version,
                                              filename=self.field('opensong_file'))
     elif bible_type == BibleFormat.WebDownload:
         # Import a bible from the web.
         self.progress_bar.setMaximum(1)
         download_location = self.field('web_location')
         bible_version = self.web_translation_combo_box.currentText()
         (bible, language_id) = self.web_bible_list[download_location][bible_version]
         importer = self.manager.import_bible(
             BibleFormat.WebDownload, name=license_version,
             download_source=WebDownload.Names[download_location],
             download_name=bible,
             proxy_server=self.field('proxy_server'),
             proxy_username=self.field('proxy_username'),
             proxy_password=self.field('proxy_password'),
             language_id=language_id
         )
     elif bible_type == BibleFormat.Zefania:
         # Import an Zefania bible.
         importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version,
                                              filename=self.field('zefania_file'))
     if importer.do_import(license_version):
         self.manager.save_meta_data(license_version, license_version, license_copyright, license_permissions)
         self.manager.reload_bibles()
         if bible_type == BibleFormat.WebDownload:
             self.progress_label.setText(
                 translate('BiblesPlugin.ImportWizardForm', 'Registered Bible. Please note, that verses will be '
                           'downloaded on demand and thus an internet connection is required.'))
         else:
             self.progress_label.setText(WizardStrings.FinishedImport)
     else:
         self.progress_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Your Bible import failed.'))
         del self.manager.db_cache[importer.name]
         delete_database(self.plugin.settings_section, importer.file)
Exemplo n.º 2
0
    def delete_database_without_db_file_name_test(self):
        """
        Test that the ``delete_database`` function removes a database file, without the file name parameter
        """
        # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location
        with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \
                patch('openlp.core.lib.db.delete_file') as mocked_delete_file:
            MockedAppLocation.get_section_data_path.return_value = 'test-dir'
            mocked_delete_file.return_value = True
            test_plugin = 'test'
            test_location = os.path.join('test-dir', test_plugin)

            # WHEN: delete_database is run without a database file
            result = delete_database(test_plugin)

            # THEN: The AppLocation.get_section_data_path and delete_file methods should have been called
            MockedAppLocation.get_section_data_path.assert_called_with(test_plugin)
            mocked_delete_file.assert_called_with(test_location)
            self.assertTrue(result, 'The result of delete_file should be True (was rigged that way)')
Exemplo n.º 3
0
    def test_delete_database_without_db_file_name(self):
        """
        Test that the ``delete_database`` function removes a database file, without the file name parameter
        """
        # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location
        with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \
                patch('openlp.core.lib.db.delete_file') as mocked_delete_file:
            MockedAppLocation.get_section_data_path.return_value = Path('test-dir')
            mocked_delete_file.return_value = True
            test_plugin = 'test'
            test_location = Path('test-dir', test_plugin)

            # WHEN: delete_database is run without a database file
            result = delete_database(test_plugin)

            # THEN: The AppLocation.get_section_data_path and delete_file methods should have been called
            MockedAppLocation.get_section_data_path.assert_called_with(test_plugin)
            mocked_delete_file.assert_called_with(test_location)
            assert result is True, 'The result of delete_file should be True (was rigged that way)'
Exemplo n.º 4
0
    def test_delete_database_with_db_file_name(self):
        """
        Test that the ``delete_database`` function removes a database file, with the file name supplied
        """
        # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location
        with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \
                patch('openlp.core.lib.db.delete_file') as mocked_delete_file:
            MockedAppLocation.get_section_data_path.return_value = 'test-dir'
            mocked_delete_file.return_value = False
            test_plugin = 'test'
            test_db_file = 'mydb.sqlite'
            test_location = os.path.join('test-dir', test_db_file)

            # WHEN: delete_database is run without a database file
            result = delete_database(test_plugin, test_db_file)

            # THEN: The AppLocation.get_section_data_path and delete_file methods should have been called
            MockedAppLocation.get_section_data_path.assert_called_with(
                test_plugin)
            mocked_delete_file.assert_called_with(test_location)
            self.assertFalse(
                result,
                'The result of delete_file should be False (was rigged that way)'
            )
Exemplo n.º 5
0
 def performWizard(self):
     """
     Perform the actual import.
     """
     bible_type = self.field(u'source_format')
     license_version = self.field(u'license_version')
     license_copyright = self.field(u'license_copyright')
     license_permissions = self.field(u'license_permissions')
     importer = None
     if bible_type == BibleFormat.OSIS:
         # Import an OSIS bible.
         importer = self.manager.import_bible(BibleFormat.OSIS,
             name=license_version,
             filename=self.field(u'osis_location')
         )
     elif bible_type == BibleFormat.CSV:
         # Import a CSV bible.
         importer = self.manager.import_bible(BibleFormat.CSV,
             name=license_version,
             booksfile=self.field(u'csv_booksfile'),
             versefile=self.field(u'csv_versefile')
         )
     elif bible_type == BibleFormat.OpenSong:
         # Import an OpenSong bible.
         importer = self.manager.import_bible(BibleFormat.OpenSong,
             name=license_version,
             filename=self.field(u'opensong_file')
         )
     elif bible_type == BibleFormat.WebDownload:
         # Import a bible from the web.
         self.progressBar.setMaximum(1)
         download_location = self.field(u'web_location')
         bible_version = self.webTranslationComboBox.currentText()
         bible = self.web_bible_list[download_location][bible_version]
         importer = self.manager.import_bible(
             BibleFormat.WebDownload, name=license_version,
             download_source=WebDownload.Names[download_location],
             download_name=bible,
             proxy_server=self.field(u'proxy_server'),
             proxy_username=self.field(u'proxy_username'),
             proxy_password=self.field(u'proxy_password')
         )
     elif bible_type == BibleFormat.OpenLP1:
         # Import an openlp.org 1.x bible.
         importer = self.manager.import_bible(BibleFormat.OpenLP1,
             name=license_version,
             filename=self.field(u'openlp1_location')
         )
     if importer.do_import(license_version):
         self.manager.save_meta_data(license_version, license_version,
             license_copyright, license_permissions)
         self.manager.reload_bibles()
         if bible_type == BibleFormat.WebDownload:
             self.progressLabel.setText(
                 translate('BiblesPlugin.ImportWizardForm', 'Registered Bible. Please note, that verses will be '
                 'downloaded on\ndemand and thus an internet connection is required.'))
         else:
             self.progressLabel.setText(WizardStrings.FinishedImport)
     else:
         self.progressLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Your Bible import failed.'))
         del self.manager.db_cache[importer.name]
         delete_database(self.plugin.settingsSection, importer.file)
Exemplo n.º 6
0
 def perform_wizard(self):
     """
     Perform the actual import.
     """
     bible_type = self.field("source_format")
     license_version = self.field("license_version")
     license_copyright = self.field("license_copyright")
     license_permissions = self.field("license_permissions")
     importer = None
     if bible_type == BibleFormat.OSIS:
         # Import an OSIS bible.
         importer = self.manager.import_bible(
             BibleFormat.OSIS, name=license_version, filename=self.field("osis_location")
         )
     elif bible_type == BibleFormat.CSV:
         # Import a CSV bible.
         importer = self.manager.import_bible(
             BibleFormat.CSV,
             name=license_version,
             booksfile=self.field("csv_booksfile"),
             versefile=self.field("csv_versefile"),
         )
     elif bible_type == BibleFormat.OpenSong:
         # Import an OpenSong bible.
         importer = self.manager.import_bible(
             BibleFormat.OpenSong, name=license_version, filename=self.field("opensong_file")
         )
     elif bible_type == BibleFormat.WebDownload:
         # Import a bible from the web.
         self.progress_bar.setMaximum(1)
         download_location = self.field("web_location")
         bible_version = self.web_translation_combo_box.currentText()
         (bible, language_id) = self.web_bible_list[download_location][bible_version]
         importer = self.manager.import_bible(
             BibleFormat.WebDownload,
             name=license_version,
             download_source=WebDownload.Names[download_location],
             download_name=bible,
             proxy_server=self.field("proxy_server"),
             proxy_username=self.field("proxy_username"),
             proxy_password=self.field("proxy_password"),
             language_id=language_id,
         )
     elif bible_type == BibleFormat.Zefania:
         # Import an Zefania bible.
         importer = self.manager.import_bible(
             BibleFormat.Zefania, name=license_version, filename=self.field("zefania_file")
         )
     if importer.do_import(license_version):
         self.manager.save_meta_data(license_version, license_version, license_copyright, license_permissions)
         self.manager.reload_bibles()
         if bible_type == BibleFormat.WebDownload:
             self.progress_label.setText(
                 translate(
                     "BiblesPlugin.ImportWizardForm",
                     "Registered Bible. Please note, that verses will be "
                     "downloaded on demand and thus an internet connection is required.",
                 )
             )
         else:
             self.progress_label.setText(WizardStrings.FinishedImport)
     else:
         self.progress_label.setText(translate("BiblesPlugin.ImportWizardForm", "Your Bible import failed."))
         del self.manager.db_cache[importer.name]
         delete_database(self.plugin.settings_section, importer.file)