Beispiel #1
0
    def get_verses(self, bible, verse_text, book_ref_id=False, show_error=True):
        """
        Parses a scripture reference, fetches the verses from the Bible
        specified, and returns a list of ``Verse`` objects.

        :param bible: Unicode. The Bible to use.
        :param verse_text:
             Unicode. The scripture reference. Valid scripture references are:

                - Genesis 1
                - Genesis 1-2
                - Genesis 1:1
                - Genesis 1:1-10
                - Genesis 1:1-10,15-20
                - Genesis 1:1-2:10
                - Genesis 1:1-10,2:1-10

        :param book_ref_id:  Unicode. The book reference id from the book in verse_text.
            For second bible this is necessary.
        :param show_error:
        """
        log.debug('BibleManager.get_verses("%s", "%s")', bible, verse_text)
        if not bible:
            if show_error:
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager', 'No Bibles Available'),
                    translate('BiblesPlugin.BibleManager', 'There are no Bibles currently installed. Please use the '
                              'Import Wizard to install one or more Bibles.')
                )
            return None
        language_selection = self.get_language_selection(bible)
        ref_list = parse_reference(verse_text, self.db_cache[bible], language_selection, book_ref_id)
        if ref_list:
            return self.db_cache[bible].get_verses(ref_list, show_error)
        else:
            if show_error:
                reference_separators = {
                    'verse': get_reference_separator('sep_v_display'),
                    'range': get_reference_separator('sep_r_display'),
                    'list': get_reference_separator('sep_l_display')}
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager', 'Scripture Reference Error'),
                    translate('BiblesPlugin.BibleManager', 'Your scripture reference is either not supported by '
                              'OpenLP or is invalid. Please make sure your reference '
                              'conforms to one of the following patterns or consult the manual:\n\n'
                              'Book Chapter\n'
                              'Book Chapter%(range)sChapter\n'
                              'Book Chapter%(verse)sVerse%(range)sVerse\n'
                              'Book Chapter%(verse)sVerse%(range)sVerse%(list)sVerse'
                              '%(range)sVerse\n'
                              'Book Chapter%(verse)sVerse%(range)sVerse%(list)sChapter'
                              '%(verse)sVerse%(range)sVerse\n'
                              'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse',
                              'Please pay attention to the appended "s" of the wildcards '
                              'and refrain from translating the words inside the names in the brackets.')
                    % reference_separators
                )
            return None
 def test_parse_reference_two(self):
     """
     Test the parse_reference method with 1 Timothy 1:1-2
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('1 Timothy 1:1-2', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a verse array should be returned
     self.assertEqual([(54, 1, 1, 2)], results, "The bible verses should matches the expected results")
 def test_parse_reference_four(self):
     """
     Test the parse_reference method with non existence book
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock())
     # THEN a verse array should be returned
     self.assertEqual(False, results, "The bible Search should return False")
 def parse_reference_two_test(self):
     """
     Test the parse_reference method with 1 Timothy 1:1-2
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('1 Timothy 1:1-2', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a verse array should be returned
     self.assertEqual([(54, 1, 1, 2)], results, "The bible verses should matches the expected results")
 def test_parse_reference_invalid_book(self):
     """
     Test the parse_reference method with non existent book
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock())
     # THEN an empty verse array should be returned
     assert [] == results, "The bible search should return an empty list"
 def test_parse_reference_to_chapter_less_than_from_chapter(self):
     """
     Test the parse_reference method with 1 Timothy 2:1-1:1
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference with a to_chapter less than the from_chapter
     results = parse_reference('1 Timothy 2:1-1:1', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN an empty verse array should be returned
     assert [] == results, "The bible verse list should be empty"
 def test_parse_reference_non_regexp_matching_reference(self):
     """
     Test the parse_reference method with 1 Timothy
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference that fails the regexp matching
     results = parse_reference('1 Timothy', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN an empty verse array should be returned
     assert [] == results, "The bible verse list should be empty"
 def test_parse_reference_no_from_chapter_specified(self):
     """
     Test the parse_reference method with 1 Timothy :1-2
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference with no from_chapter specified
     results = parse_reference('1 Timothy :1-2', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a two tuple verse array should be returned with the bible verse references treated as chapter references
     assert [(54, 1, 1, -1), (54, 2, 1, -1)] == results, "The bible verses should match the expected results"
 def test_parse_reference_no_from_chapter_in_second_range(self):
     """
     Test the parse_reference method with 1 Timothy 1:1,3
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference that has no from_chapter in the second range
     results = parse_reference('1 Timothy 1:1,3', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a two tuple verse array should be returned
     assert [(54, 1, 1, 1), (54, 1, 3, 3)] == results, "The bible verses should match the expected results"
 def test_parse_reference_book_ref_id_invalid(self):
     """
     Test the parse_reference method with 1 Timothy 1:1 with an invalid bible ref id
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference with an invalid bible reference id
     results = parse_reference('1 Timothy 1:1', self.manager.db_cache['tests'], MagicMock(), -666)
     # THEN an empty verse array should be returned
     assert [] == results, "The bible verse list should be empty"
 def parse_reference_four_test(self):
     """
     Test the parse_reference method with non existence book
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock())
     # THEN a verse array should be returned
     self.assertEqual(False, results, "The bible Search should return False")
 def test_parse_reference_numbered_book_single_range_single_chapter_multiple_verses(self):
     """
     Test the parse_reference method with 1 Timothy 1:1-2
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('1 Timothy 1:1-2', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a one tuple verse array should be returned
     assert [(54, 1, 1, 2)] == results, "The bible verses should match the expected results"
 def test_parse_reference_three_chapters(self):
     """
     Test the parse_reference method with 1 Timothy 1-3
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference with three chapters
     results = parse_reference('1 Timothy 1-3', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a three tuple verse array should be returned
     assert [(54, 1, 1, -1), (54, 2, 1, -1), (54, 3, 1, -1)] == results, \
         "The bible verses should match the expected results"
 def test_parse_reference_numbered_book_single_range_single_chapter_with_end_reference_no_bible_ref_id(self):
     """
     Test the parse_reference method with 1 Timothy 1:3-end without a bible ref id to match
     how the GUI does the search.  This is logged in issue #282
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference in Language 0 (english)
     results = parse_reference('1 Timothy 1:3-end', self.manager.db_cache['tests'], 0)
     # THEN a one tuple verse array should be returned
     assert [(54, 1, 3, -1)] == results, "The bible verses should match the expected results"
Beispiel #15
0
    def get_verses(self,
                   bible,
                   verse_text,
                   book_ref_id=False,
                   show_error=True):
        """
        Parses a scripture reference, fetches the verses from the Bible
        specified, and returns a list of ``Verse`` objects.

        :param bible: Unicode. The Bible to use.
        :param verse_text:
             Unicode. The scripture reference. Valid scripture references are:

                - Genesis 1
                - Genesis 1-2
                - Genesis 1:1
                - Genesis 1:1-10
                - Genesis 1:1-10,15-20
                - Genesis 1:1-2:10
                - Genesis 1:1-10,2:1-10

        :param book_ref_id:  Unicode. The book reference id from the book in verse_text.
            For second bible this is necessary.
        :param show_error:
        """
        # If no bibles are installed, message is given.
        log.debug('BibleManager.get_verses("{bible}", "{verse}")'.format(
            bible=bible, verse=verse_text))
        if not bible:
            if show_error:
                self.main_window.information_message(
                    UiStrings().BibleNoBiblesTitle,
                    UiStrings().BibleNoBibles)
            return None
        # Get the language for books.
        language_selection = self.get_language_selection(bible)
        ref_list = parse_reference(verse_text, self.db_cache[bible],
                                   language_selection, book_ref_id)
        if ref_list:
            return self.db_cache[bible].get_verses(ref_list, show_error)
        # If nothing is found. Message is given if this is not combined search. (defined in mediaitem.py)
        else:
            return None
Beispiel #16
0
 def parse_ref(self, bible, reference_text, book_ref_id=False):
     if not bible:
         return
     language_selection = self.get_language_selection(bible)
     return parse_reference(reference_text, self.db_cache[bible],
                            language_selection, book_ref_id)
    def on_import_as_new_button_clicked(self, update=False):
        """
        Create a new service and import all of the PCO items into it
        """
        service_manager = Registry().get('service_manager')
        old_service_items = []
        if update:
            old_service_items = service_manager.service_items.copy()
            service_manager.new_file()
        else:
            service_manager.on_new_service_clicked()
        # we only continue here if the service_manager is now empty
        if len(service_manager.service_items) == 0:
            service_manager.application.set_busy_cursor()
            # get the plan ID for the current plan selection
            plan_id = self.plan_selection_combo_box.itemData(
                self.plan_selection_combo_box.currentIndex())
            # get the items array from Planning Center
            planning_center_items_dict = self.planning_center_api.GetItemsDict(
                plan_id)
            service_manager.main_window.display_progress_bar(
                len(planning_center_items_dict['data']))
            # convert the planning center dict to Songs and Add them to the ServiceManager
            pco_id_to_openlp_id = {}
            for item in planning_center_items_dict['data']:
                item_title = item['attributes']['title']
                media_type = ''
                openlp_id = -1
                if item['attributes']['item_type'] == 'song':
                    arrangement_id = item['relationships']['arrangement'][
                        'data']['id']
                    song_id = item['relationships']['song']['data']['id']
                    if song_id not in pco_id_to_openlp_id:
                        # get arrangement from "included" resources
                        arrangement_data = {}
                        song_data = {}
                        for included_item in planning_center_items_dict[
                                'included']:
                            if included_item[
                                    'type'] == 'Song' and included_item[
                                        'id'] == song_id:
                                song_data = included_item
                            elif included_item[
                                    'type'] == 'Arrangement' and included_item[
                                        'id'] == arrangement_id:
                                arrangement_data = included_item
                            # if we have both song and arrangement set, stop iterating
                            if len(song_data) and len(arrangement_data):
                                break
                        author = song_data['attributes']['author']
                        lyrics = arrangement_data['attributes']['lyrics']
                        arrangement_updated_at = datetime.strptime(
                            arrangement_data['attributes']
                            ['updated_at'].rstrip("Z"), '%Y-%m-%dT%H:%M:%S')
                        # start importing the song
                        pco_import = PlanningCenterSongImport()
                        theme_name = self.song_theme_selection_combo_box.currentText(
                        )
                        openlp_id = pco_import.add_song(
                            item_title, author, lyrics, theme_name,
                            arrangement_updated_at)
                        pco_id_to_openlp_id[song_id] = openlp_id

                    openlp_id = pco_id_to_openlp_id[song_id]
                    media_type = 'songs'
                else:
                    # if we have "details" for the item, create slides from those
                    html_details = item['attributes']['html_details']
                    theme_name = self.slide_theme_selection_combo_box.currentText(
                    )
                    custom_import = PlanningCenterCustomImport()
                    openlp_id = custom_import.add_slide(
                        item_title, html_details, theme_name)
                    media_type = 'custom'

                # add the media to the service
                media_type_plugin = Registry().get(media_type)
                # the variable suffix names below for "songs" is "song", so change media_type to song
                media_type_suffix = media_type
                if media_type == 'songs':
                    media_type_suffix = 'song'
                # turn on remote song feature to add to service
                media_type_plugin.remote_triggered = True
                setattr(media_type_plugin,
                        "remote_{0}".format(media_type_suffix), openlp_id)
                media_type_plugin.add_to_service(remote=openlp_id)
                # also add verse references if they are there
                if media_type == 'custom' and not html_details:
                    # check if the slide title is also a verse reference
                    # get a reference to the bible manager
                    bible_media = Registry().get('bibles')
                    bibles = bible_media.plugin.manager.get_bibles()
                    # get the current bible selected from the bibles plugin screen
                    bible = bible_media.quickVersionComboBox.currentText()
                    language_selection = bible_media.plugin.manager.get_language_selection(
                        bible)
                    # replace long dashes with normal dashes -- why do these get inserted in PCO?
                    tmp_item_title = re.sub('–', '-', item_title)
                    ref_list = parse_reference(tmp_item_title, bibles[bible],
                                               language_selection)
                    if ref_list:
                        bible_media.search_results = bibles[bible].get_verses(
                            ref_list)
                        bible_media.list_view.clear()
                        bible_media.display_results(bible, '')
                        bible_media.add_to_service()
                service_manager.main_window.increment_progress_bar()
            if update:
                for old_service_item in old_service_items:
                    # see if this service_item contained within the current set of service items

                    # see if we have this same value in the new service
                    for service_index, service_item in enumerate(
                            service_manager.service_items):
                        # we can compare songs to songs and custom to custom but not between them
                        if old_service_item[
                                'service_item'].name == 'songs' and service_item[
                                    'service_item'].name == 'songs':
                            if old_service_item[
                                    'service_item'].audit == service_item[
                                        'service_item'].audit:
                                # get the timestamp from the xml of both the old and new and compare...
                                # modifiedDate="2018-06-30T18:44:35Z"
                                old_match = re.search(
                                    'modifiedDate="(.+?)Z*"',
                                    old_service_item['service_item'].
                                    xml_version)
                                old_datetime = datetime.strptime(
                                    old_match.group(1), '%Y-%m-%dT%H:%M:%S')
                                new_match = re.search(
                                    'modifiedDate="(.+?)Z*"',
                                    service_item['service_item'].xml_version)
                                new_datetime = datetime.strptime(
                                    new_match.group(1), '%Y-%m-%dT%H:%M:%S')
                                # if old timestamp is more recent than new, then copy old to new
                                if old_datetime > new_datetime:
                                    service_manager.service_items[
                                        service_index] = old_service_item
                                break
                        elif old_service_item[
                                'service_item'].name == 'custom' and service_item[
                                    'service_item'].name == 'custom':
                            """ we don't get actual slide content from the V2 PC API, so all we create by default is a 
                            single slide with matching title and content.  If the content
                            is different between the old serviceitem (previously imported
                            from PC and the new content that we are importing now, then
                            the assumption is that we updated this content and we want to 
                            keep the old content after this update.  If we actually updated
                            something on the PC site in this slide, it would have a
                            different title because that is all we can get the v2API """
                            if old_service_item[
                                    'service_item'].title == service_item[
                                        'service_item'].title:
                                if old_service_item[
                                        'service_item']._raw_frames != service_item[
                                            'service_item']._raw_frames:
                                    service_manager.service_items[
                                        service_index] = old_service_item
                                break

            service_manager.main_window.finished_progress_bar()
            # select the first item
            item = service_manager.service_manager_list.topLevelItem(0)
            service_manager.service_manager_list.setCurrentItem(item)
            service_manager.repaint_service_list(-1, -1)
            service_manager.application.set_normal_cursor()
        self.done(QtWidgets.QDialog.Accepted)
Beispiel #18
0
    def get_verses(self,
                   bible,
                   verse_text,
                   book_ref_id=False,
                   show_error=True):
        """
        Parses a scripture reference, fetches the verses from the Bible
        specified, and returns a list of ``Verse`` objects.

        :param bible: Unicode. The Bible to use.
        :param verse_text:
             Unicode. The scripture reference. Valid scripture references are:

                - Genesis 1
                - Genesis 1-2
                - Genesis 1:1
                - Genesis 1:1-10
                - Genesis 1:1-10,15-20
                - Genesis 1:1-2:10
                - Genesis 1:1-10,2:1-10

        :param book_ref_id:  Unicode. The book reference id from the book in verse_text.
            For second bible this is necessary.
        :param show_error:
        """
        log.debug('BibleManager.get_verses("%s", "%s")', bible, verse_text)
        if not bible:
            if show_error:
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager',
                              'No Bibles Available'),
                    translate(
                        'BiblesPlugin.BibleManager',
                        'There are no Bibles currently installed. Please use the '
                        'Import Wizard to install one or more Bibles.'))
            return None
        language_selection = self.get_language_selection(bible)
        ref_list = parse_reference(verse_text, self.db_cache[bible],
                                   language_selection, book_ref_id)
        if ref_list:
            return self.db_cache[bible].get_verses(ref_list, show_error)
        else:
            if show_error:
                reference_separators = {
                    'verse': get_reference_separator('sep_v_display'),
                    'range': get_reference_separator('sep_r_display'),
                    'list': get_reference_separator('sep_l_display')
                }
                self.main_window.information_message(
                    translate('BiblesPlugin.BibleManager',
                              'Scripture Reference Error'),
                    translate(
                        'BiblesPlugin.BibleManager',
                        'Your scripture reference is either not supported by '
                        'OpenLP or is invalid. Please make sure your reference '
                        'conforms to one of the following patterns or consult the manual:\n\n'
                        'Book Chapter\n'
                        'Book Chapter%(range)sChapter\n'
                        'Book Chapter%(verse)sVerse%(range)sVerse\n'
                        'Book Chapter%(verse)sVerse%(range)sVerse%(list)sVerse'
                        '%(range)sVerse\n'
                        'Book Chapter%(verse)sVerse%(range)sVerse%(list)sChapter'
                        '%(verse)sVerse%(range)sVerse\n'
                        'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse',
                        'Please pay attention to the appended "s" of the wildcards '
                        'and refrain from translating the words inside the names in the brackets.'
                    ) % reference_separators)
            return None