forked from openlp/openlp
add song reporting
This commit is contained in:
parent
c763585250
commit
15adb41256
@ -379,6 +379,7 @@ class Settings(QtCore.QSettings):
|
||||
'shortcuts/themeScreen': [QtGui.QKeySequence(QtCore.Qt.Key_T)],
|
||||
'shortcuts/toolsReindexItem': [],
|
||||
'shortcuts/toolsFindDuplicates': [],
|
||||
'shortcuts/ReportSongList': [],
|
||||
'shortcuts/toolsAlertItem': [QtGui.QKeySequence(QtCore.Qt.Key_F7)],
|
||||
'shortcuts/toolsFirstTimeWizard': [],
|
||||
'shortcuts/toolsOpenDataFolder': [],
|
||||
|
@ -46,13 +46,13 @@ MIN_BLOCK_SIZE = 70
|
||||
MAX_TYPO_SIZE = 3
|
||||
|
||||
|
||||
def songs_probably_equal(song_tupel):
|
||||
def songs_probably_equal(song_tuple):
|
||||
"""
|
||||
Calculate and return whether two songs are probably equal.
|
||||
|
||||
:param song_tupel: A tuple of two songs to compare.
|
||||
:param song_tuple: A tuple of two songs to compare.
|
||||
"""
|
||||
song1, song2 = song_tupel
|
||||
song1, song2 = song_tuple
|
||||
pos1, lyrics1 = song1
|
||||
pos2, lyrics2 = song2
|
||||
if len(lyrics1) < len(lyrics2):
|
||||
|
97
openlp/plugins/songs/reporting.py
Normal file
97
openlp/plugins/songs/reporting.py
Normal file
@ -0,0 +1,97 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2016 OpenLP Developers #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# This program is free software; you can redistribute it and/or modify it #
|
||||
# under the terms of the GNU General Public License as published by the Free #
|
||||
# Software Foundation; version 2 of the License. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||
# more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License along #
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
"""
|
||||
The :mod:`db` module provides the ability to provide a csv file of all songs
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from openlp.core.common import Registry, check_directory_exists, translate
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.plugins.songs.lib.db import Song
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def report_song_list():
|
||||
"""
|
||||
Export the song list as a CSV file.
|
||||
:return: Nothing
|
||||
"""
|
||||
main_window = Registry().get('main_window')
|
||||
plugin = Registry().get('songs').plugin
|
||||
path = QtWidgets.QFileDialog.getExistingDirectory(
|
||||
main_window, translate('SongPlugin.ReportSongList', 'Output File Location'))
|
||||
if not path:
|
||||
main_window.error_message(
|
||||
translate('SongPlugin.ReportSongList', 'Output Path Not Selected'),
|
||||
translate('SongPlugin.ReportSongList', 'You have not set a valid output location for your'
|
||||
'report. \nPlease select an existing path '
|
||||
'on your computer.')
|
||||
)
|
||||
return
|
||||
check_directory_exists(path)
|
||||
report_file_name = os.path.join(path, 'song_index.csv')
|
||||
file_handle = None
|
||||
try:
|
||||
file_handle = open(report_file_name, 'wb')
|
||||
song_list = plugin.manager.get_all_objects(Song)
|
||||
for song in song_list:
|
||||
record = '\"{title}\",'.format(title=song.title)
|
||||
record += '\"{title}\",'.format(title=song.alternate_title)
|
||||
record += '\"{title}\",'.format(title=song.copyright)
|
||||
author_list = []
|
||||
for author_song in song.authors_songs:
|
||||
author_list.append(author_song.author.display_name)
|
||||
author_string = '\"{name}\"'.format(name=' | '.join(author_list))
|
||||
book_list = []
|
||||
for book_song in song.songbook_entries:
|
||||
if hasattr(book_song, 'entry') and book_song.entry:
|
||||
book_list.append('{name} #{entry}'.format(name=book_song.songbook.name, entry=book_song.entry))
|
||||
book_string = '\"{name}\"'.format(name=' | '.join(book_list))
|
||||
topic_list = []
|
||||
for topic_song in song.topics:
|
||||
if hasattr(topic_song, 'name'):
|
||||
topic_list.append(topic_song.name)
|
||||
topic_string = '\"{name}\"'.format(name=' | '.join(topic_list))
|
||||
record += '{title},'.format(title=author_string)
|
||||
record += '{title},'.format(title=book_string)
|
||||
record += '{title},'.format(title=topic_string)
|
||||
record += '\n'
|
||||
file_handle.write(record.encode('utf-8'))
|
||||
main_window.information_message(
|
||||
translate('SongPlugin.ReportSongList', 'Report Creation'),
|
||||
translate('SongPlugin.ReportSongList',
|
||||
'Report \n{name} \nhas been successfully created. ').format(name=report_file_name)
|
||||
)
|
||||
except OSError as ose:
|
||||
log.exception('Failed to write out song usage records')
|
||||
critical_error_message_box(translate('SongPlugin.ReportSongList', 'Song Extraction Failed'),
|
||||
translate('SongPlugin.ReportSongList',
|
||||
'An error occurred while extracting: {error}'
|
||||
).format(error=ose.strerror))
|
||||
finally:
|
||||
if file_handle:
|
||||
file_handle.close()
|
@ -36,6 +36,7 @@ from openlp.core.common.actions import ActionList
|
||||
from openlp.core.lib import Plugin, StringContent, build_icon
|
||||
from openlp.core.lib.db import Manager
|
||||
from openlp.core.lib.ui import create_action
|
||||
from openlp.plugins.songs import reporting
|
||||
from openlp.plugins.songs.forms.duplicatesongremovalform import DuplicateSongRemovalForm
|
||||
from openlp.plugins.songs.forms.songselectform import SongSelectForm
|
||||
from openlp.plugins.songs.lib import clean_song, upgrade
|
||||
@ -102,13 +103,13 @@ class SongsPlugin(Plugin):
|
||||
self.songselect_form.initialise()
|
||||
self.song_import_item.setVisible(True)
|
||||
self.song_export_item.setVisible(True)
|
||||
self.tools_reindex_item.setVisible(True)
|
||||
self.tools_find_duplicates.setVisible(True)
|
||||
self.song_tools_menu.menuAction().setVisible(True)
|
||||
action_list = ActionList.get_instance()
|
||||
action_list.add_action(self.song_import_item, UiStrings().Import)
|
||||
action_list.add_action(self.song_export_item, UiStrings().Export)
|
||||
action_list.add_action(self.tools_reindex_item, UiStrings().Tools)
|
||||
action_list.add_action(self.tools_find_duplicates, UiStrings().Tools)
|
||||
action_list.add_action(self.tools_report_song_list, UiStrings().Tools)
|
||||
|
||||
def add_import_menu_item(self, import_menu):
|
||||
"""
|
||||
@ -151,19 +152,37 @@ class SongsPlugin(Plugin):
|
||||
:param tools_menu: The actual **Tools** menu item, so that your actions can use it as their parent.
|
||||
"""
|
||||
log.info('add tools menu')
|
||||
self.tools_menu = tools_menu
|
||||
self.song_tools_menu = QtWidgets.QMenu(tools_menu)
|
||||
self.song_tools_menu.setObjectName('song_tools_menu')
|
||||
self.song_tools_menu.setTitle(translate('SongsPlugin', 'Song Tools'))
|
||||
self.tools_reindex_item = create_action(
|
||||
tools_menu, 'toolsReindexItem',
|
||||
text=translate('SongsPlugin', '&Re-index Songs'),
|
||||
icon=':/plugins/plugin_songs.png',
|
||||
statustip=translate('SongsPlugin', 'Re-index the songs database to improve searching and ordering.'),
|
||||
visible=False, triggers=self.on_tools_reindex_item_triggered)
|
||||
tools_menu.addAction(self.tools_reindex_item)
|
||||
triggers=self.on_tools_reindex_item_triggered)
|
||||
self.tools_find_duplicates = create_action(
|
||||
tools_menu, 'toolsFindDuplicates',
|
||||
text=translate('SongsPlugin', 'Find &Duplicate Songs'),
|
||||
statustip=translate('SongsPlugin', 'Find and remove duplicate songs in the song database.'),
|
||||
visible=False, triggers=self.on_tools_find_duplicates_triggered, can_shortcuts=True)
|
||||
tools_menu.addAction(self.tools_find_duplicates)
|
||||
triggers=self.on_tools_find_duplicates_triggered, can_shortcuts=True)
|
||||
self.tools_report_song_list = create_action(
|
||||
tools_menu, 'ReportSongList',
|
||||
text=translate('SongsPlugin', 'Export List on Songs'),
|
||||
statustip=translate('SongsPlugin', 'Produce a CSV file of all the songs in the database.'),
|
||||
triggers=self.on_tools_report_song_list_triggered)
|
||||
|
||||
self.tools_menu.addAction(self.song_tools_menu.menuAction())
|
||||
self.song_tools_menu.addAction(self.tools_reindex_item)
|
||||
self.song_tools_menu.addAction(self.tools_find_duplicates)
|
||||
self.song_tools_menu.addAction(self.tools_report_song_list)
|
||||
|
||||
self.song_tools_menu.menuAction().setVisible(False)
|
||||
|
||||
@staticmethod
|
||||
def on_tools_report_song_list_triggered():
|
||||
reporting.report_song_list()
|
||||
|
||||
def on_tools_reindex_item_triggered(self):
|
||||
"""
|
||||
|
1756
song_index.csv
Normal file
1756
song_index.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user