2013-04-13 22:01:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2013-04-13 22:01:36 +00:00
|
|
|
"""
|
|
|
|
The :mod:`worshipcenterpro` module provides the functionality for importing
|
|
|
|
a WorshipCenter Pro database into the OpenLP database.
|
|
|
|
"""
|
2013-04-24 17:37:15 +00:00
|
|
|
import logging
|
2015-10-27 15:00:11 +00:00
|
|
|
import re
|
2017-12-28 08:08:12 +00:00
|
|
|
|
2013-04-13 22:01:36 +00:00
|
|
|
import pyodbc
|
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2014-07-04 09:31:06 +00:00
|
|
|
from openlp.plugins.songs.lib.importers.songimport import SongImport
|
2013-04-13 22:01:36 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2013-04-24 17:37:15 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2013-04-13 22:01:36 +00:00
|
|
|
class WorshipCenterProImport(SongImport):
|
|
|
|
"""
|
|
|
|
The :class:`WorshipCenterProImport` class provides the ability to import the
|
|
|
|
WorshipCenter Pro Access Database
|
|
|
|
"""
|
|
|
|
def __init__(self, manager, **kwargs):
|
|
|
|
"""
|
|
|
|
Initialise the WorshipCenter Pro importer.
|
|
|
|
"""
|
2015-01-16 15:25:25 +00:00
|
|
|
super(WorshipCenterProImport, self).__init__(manager, **kwargs)
|
2013-04-13 22:01:36 +00:00
|
|
|
|
2014-03-06 20:40:08 +00:00
|
|
|
def do_import(self):
|
2013-04-13 22:01:36 +00:00
|
|
|
"""
|
|
|
|
Receive a single file to import.
|
|
|
|
"""
|
|
|
|
try:
|
2016-06-14 19:11:57 +00:00
|
|
|
conn = pyodbc.connect('DRIVER={{Microsoft Access Driver (*.mdb)}};'
|
2016-05-27 08:13:14 +00:00
|
|
|
'DBQ={source}'.format(source=self.import_source))
|
2013-08-31 18:17:38 +00:00
|
|
|
except (pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError) as e:
|
2016-05-27 08:13:14 +00:00
|
|
|
log.warning('Unable to connect the WorshipCenter Pro '
|
|
|
|
'database {source}. {error}'.format(source=self.import_source, error=str(e)))
|
2013-04-13 22:01:36 +00:00
|
|
|
# Unfortunately no specific exception type
|
2014-03-21 21:38:08 +00:00
|
|
|
self.log_error(self.import_source, translate('SongsPlugin.WorshipCenterProImport',
|
|
|
|
'Unable to connect the WorshipCenter Pro database.'))
|
2013-04-13 22:01:36 +00:00
|
|
|
return
|
|
|
|
cursor = conn.cursor()
|
2013-08-31 18:17:38 +00:00
|
|
|
cursor.execute('SELECT ID, Field, Value FROM __SONGDATA')
|
2013-04-13 22:01:36 +00:00
|
|
|
records = cursor.fetchall()
|
|
|
|
songs = {}
|
|
|
|
for record in records:
|
|
|
|
id = record.ID
|
2013-08-31 18:17:38 +00:00
|
|
|
if id not in songs:
|
2013-04-13 22:01:36 +00:00
|
|
|
songs[id] = {}
|
|
|
|
songs[id][record.Field] = record.Value
|
|
|
|
self.import_wizard.progress_bar.setMaximum(len(songs))
|
|
|
|
for song in songs:
|
|
|
|
if self.stop_import_flag:
|
|
|
|
break
|
2014-03-05 18:58:22 +00:00
|
|
|
self.set_defaults()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.title = songs[song]['TITLE']
|
2015-10-27 15:00:11 +00:00
|
|
|
if 'AUTHOR' in songs[song]:
|
|
|
|
self.parse_author(songs[song]['AUTHOR'])
|
|
|
|
if 'CCLISONGID' in songs[song]:
|
|
|
|
self.ccli_number = songs[song]['CCLISONGID']
|
|
|
|
if 'COMMENTS' in songs[song]:
|
|
|
|
self.add_comment(songs[song]['COMMENTS'])
|
|
|
|
if 'COPY' in songs[song]:
|
|
|
|
self.add_copyright(songs[song]['COPY'])
|
|
|
|
if 'SUBJECT' in songs[song]:
|
|
|
|
self.topics.append(songs[song]['SUBJECT'])
|
2013-08-31 18:17:38 +00:00
|
|
|
lyrics = songs[song]['LYRICS'].strip('&crlf;&crlf;')
|
|
|
|
for verse in lyrics.split('&crlf;&crlf;'):
|
|
|
|
verse = verse.replace('&crlf;', '\n')
|
2015-10-27 15:00:11 +00:00
|
|
|
marker_type = 'v'
|
|
|
|
# Find verse markers if any
|
|
|
|
marker_start = verse.find('<')
|
|
|
|
if marker_start > -1:
|
|
|
|
marker_end = verse.find('>')
|
|
|
|
marker = verse[marker_start + 1:marker_end]
|
|
|
|
# Identify the marker type
|
|
|
|
if 'REFRAIN' in marker or 'CHORUS' in marker:
|
|
|
|
marker_type = 'c'
|
|
|
|
elif 'BRIDGE' in marker:
|
|
|
|
marker_type = 'b'
|
|
|
|
elif 'PRECHORUS' in marker:
|
|
|
|
marker_type = 'p'
|
|
|
|
elif 'END' in marker:
|
|
|
|
marker_type = 'e'
|
|
|
|
elif 'INTRO' in marker:
|
|
|
|
marker_type = 'i'
|
|
|
|
elif 'TAG' in marker:
|
|
|
|
marker_type = 'o'
|
|
|
|
else:
|
|
|
|
marker_type = 'v'
|
|
|
|
# Strip tags from text
|
|
|
|
verse = re.sub('<[^<]+?>', '', verse)
|
2015-10-28 16:43:17 +00:00
|
|
|
self.add_verse(verse.strip(), marker_type)
|
2013-04-13 22:01:36 +00:00
|
|
|
self.finish()
|