1
# -*- coding: utf-8 -*-
2
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
4
###############################################################################
5
# OpenLP - Open Source Lyrics Projection #
6
# --------------------------------------------------------------------------- #
7
# Copyright (c) 2008-2014 Raoul Snyman #
8
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
9
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
10
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
11
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
12
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
13
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
14
# Frode Woldsund, Martin Zibricky #
15
# --------------------------------------------------------------------------- #
16
# This program is free software; you can redistribute it and/or modify it #
17
# under the terms of the GNU General Public License as published by the Free #
18
# Software Foundation; version 2 of the License. #
20
# This program is distributed in the hope that it will be useful, but WITHOUT #
21
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
22
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
25
# You should have received a copy of the GNU General Public License along #
26
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
27
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
28
###############################################################################
30
The :mod:`mediashoutimport` module provides the functionality for importing
31
a MediaShout database into the OpenLP database.
37
from openlp.core.lib import translate
38
from openlp.plugins.songs.lib.songimport import SongImport
40
VERSE_TAGS = [u'V', u'C', u'B', u'O', u'P', u'I', u'E']
42
class MediaShoutImport(SongImport):
44
The :class:`MediaShoutImport` class provides the ability to import the
45
MediaShout Access Database
47
def __init__(self, manager, **kwargs):
49
Initialise the MediaShout importer.
51
SongImport.__init__(self, manager, **kwargs)
55
Receive a single file to import.
58
conn = pyodbc.connect(u'DRIVER={Microsoft Access Driver (*.mdb)};'
59
u'DBQ=%s;PWD=6NOZ4eHK7k' % self.importSource)
61
# Unfortunately no specific exception type
62
self.logError(self.importSource,
63
translate('SongsPlugin.MediaShoutImport',
64
'Unable to open the MediaShout database.'))
66
cursor = conn.cursor()
67
cursor.execute(u'SELECT Record, Title, Author, Copyright, '
68
u'SongID, CCLI, Notes FROM Songs ORDER BY Title')
69
songs = cursor.fetchall()
70
self.importWizard.progressBar.setMaximum(len(songs))
72
if self.stopImportFlag:
74
cursor.execute(u'SELECT Type, Number, Text FROM Verses '
75
u'WHERE Record = %s ORDER BY Type, Number' % song.Record)
76
verses = cursor.fetchall()
77
cursor.execute(u'SELECT Type, Number, POrder FROM PlayOrder '
78
u'WHERE Record = %s ORDER BY POrder' % song.Record)
79
verse_order = cursor.fetchall()
80
cursor.execute(u'SELECT Name FROM Themes INNER JOIN SongThemes '
81
u'ON SongThemes.ThemeId = Themes.ThemeId '
82
u'WHERE SongThemes.Record = %s' % song.Record)
83
topics = cursor.fetchall()
84
cursor.execute(u'SELECT Name FROM Groups INNER JOIN SongGroups '
85
u'ON SongGroups.GroupId = Groups.GroupId '
86
u'WHERE SongGroups.Record = %s' % song.Record)
87
topics += cursor.fetchall()
88
self.processSong(song, verses, verse_order, topics)
90
def processSong(self, song, verses, verse_order, topics):
92
Create the song, i.e. title, verse etc.
95
self.title = song.Title
96
self.parseAuthor(song.Author)
97
self.addCopyright(song.Copyright)
98
self.comments = song.Notes
100
self.topics.append(topic.Name)
101
if u'-' in song.SongID:
102
self.songBookName, self.songNumber = song.SongID.split(u'-', 1)
104
self.songBookName = song.SongID
106
tag = VERSE_TAGS[verse.Type] + unicode(verse.Number) \
107
if verse.Type < len(VERSE_TAGS) else u'O'
108
self.addVerse(verse.Text, tag)
109
for order in verse_order:
110
if order.Type < len(VERSE_TAGS):
111
self.verseOrderList.append(VERSE_TAGS[order.Type]
112
+ unicode(order.Number))