Working ZionWorxImport

This commit is contained in:
Samuel Findlay 2012-06-05 19:16:24 +10:00
commit 2fb09b2462
7 changed files with 328 additions and 282 deletions

View File

@ -444,6 +444,20 @@ class ThemeXML(object):
element.appendChild(child)
return child
def set_default_header_footer(self):
"""
Set the header and footer size into the current primary screen.
10 px on each side is removed to allow for a border.
"""
from openlp.core.ui import ScreenList
current_screen = ScreenList().current
self.font_main_y = 0
self.font_main_width = current_screen[u'size'].width() - 20
self.font_main_height = current_screen[u'size'].height() * 9 / 10
self.font_footer_width = current_screen[u'size'].width() - 20
self.font_footer_y = current_screen[u'size'].height() * 9 / 10
self.font_footer_height = current_screen[u'size'].height() / 10
def dump_xml(self):
"""
Dump the XML to file used for debugging

View File

@ -257,6 +257,7 @@ class ThemeManager(QtGui.QWidget):
editing form for the user to make their customisations.
"""
theme = ThemeXML()
theme.set_default_header_footer()
self.themeForm.theme = theme
self.themeForm.exec_()

View File

@ -36,8 +36,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, SettingsManager, translate
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.plugins.songs.lib.importer import SongFormat, SongFormatAttr, \
SongFormatSelect
from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect
log = logging.getLogger(__name__)
@ -88,7 +87,7 @@ class SongImportForm(OpenLPWizard):
Song wizard specific initialisation.
"""
for format in SongFormat.get_format_list():
if not SongFormatAttr.get(format, SongFormatAttr.availability):
if not SongFormat.get(format, SongFormat.Availability):
self.formatWidgets[format][u'disabledWidget'].setVisible(True)
self.formatWidgets[format][u'importWidget'].setVisible(False)
@ -97,7 +96,7 @@ class SongImportForm(OpenLPWizard):
Song wizard specific signals.
"""
for format in SongFormat.get_format_list():
select_mode = SongFormatAttr.get(format, SongFormatAttr.select_mode)
select_mode = SongFormat.get(format, SongFormat.SelectMode)
if select_mode == SongFormatSelect.MultipleFiles:
QtCore.QObject.connect(self.formatWidgets[format][u'addButton'],
QtCore.SIGNAL(u'clicked()'), self.onAddButtonClicked)
@ -161,9 +160,9 @@ class SongImportForm(OpenLPWizard):
self.sourcePage.setSubTitle(WizardStrings.ImportSelectLong)
self.formatLabel.setText(WizardStrings.FormatLabel)
for format in SongFormat.get_format_list():
format_name, custom_combo_text, select_mode = SongFormatAttr.get(
format, SongFormatAttr.name, SongFormatAttr.combo_box_text,
SongFormatAttr.select_mode)
format_name, custom_combo_text, select_mode = SongFormat.get(
format, SongFormat.Name, SongFormat.ComboBoxText,
SongFormat.SelectMode)
combo_box_text = custom_combo_text if custom_combo_text \
else format_name
self.formatComboBox.setItemText(format, combo_box_text)
@ -182,7 +181,7 @@ class SongImportForm(OpenLPWizard):
translate('SongsPlugin.ImportWizardForm', f_label))
for format in self.disablableFormats:
self.formatWidgets[format][u'disabledLabel'].setText(
SongFormatAttr.get(format, SongFormatAttr.disabled_label_text))
SongFormat.get(format, SongFormat.DisabledLabelText))
self.progressPage.setTitle(WizardStrings.Importing)
self.progressPage.setSubTitle(
translate('SongsPlugin.ImportWizardForm',
@ -194,8 +193,8 @@ class SongImportForm(OpenLPWizard):
self.errorSaveToButton.setText(translate('SongsPlugin.ImportWizardForm',
'Save to File'))
# Align all QFormLayouts towards each other.
formats = filter(lambda f: u'filepathLabel' in
self.formatWidgets[f], SongFormat.get_format_list())
formats = filter(lambda f: u'filepathLabel' in self.formatWidgets[f],
SongFormat.get_format_list())
labels = [self.formatWidgets[f][u'filepathLabel'] for f in formats]
# Get max width of all labels
max_label_width = max(self.formatLabel.minimumSizeHint().width(),
@ -228,9 +227,9 @@ class SongImportForm(OpenLPWizard):
format = self.currentFormat
QtCore.QSettings().setValue(u'songs/last import type',
format)
select_mode, class_, error_msg = \
SongFormatAttr.get(format, SongFormatAttr.select_mode,
SongFormatAttr.class_, SongFormatAttr.invalid_source_msg)
select_mode, class_, error_msg = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Class,
SongFormat.InvalidSourceMsg)
if select_mode == SongFormatSelect.MultipleFiles:
import_source = self.getListOfFiles(
self.formatWidgets[format][u'fileListWidget'])
@ -293,9 +292,8 @@ class SongImportForm(OpenLPWizard):
def onBrowseButtonClicked(self):
format = self.currentFormat
select_mode, format_name, filter = SongFormatAttr.get(format,
SongFormatAttr.select_mode, SongFormatAttr.name,
SongFormatAttr.filter)
select_mode, format_name, filter = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Name, SongFormat.Filter)
filepathEdit = self.formatWidgets[format][u'filepathEdit']
if select_mode == SongFormatSelect.SingleFile:
self.getFileName(WizardStrings.OpenTypeFile % format_name,
@ -306,9 +304,9 @@ class SongImportForm(OpenLPWizard):
def onAddButtonClicked(self):
format = self.currentFormat
select_mode, format_name, filter, custom_title = SongFormatAttr.get(
format, SongFormatAttr.select_mode, SongFormatAttr.name,
SongFormatAttr.filter, SongFormatAttr.get_files_title)
select_mode, format_name, filter, custom_title = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Name, SongFormat.Filter,
SongFormat.GetFilesTitle)
title = custom_title if custom_title \
else WizardStrings.OpenTypeFile % format_name
if select_mode == SongFormatSelect.MultipleFiles:
@ -341,7 +339,7 @@ class SongImportForm(OpenLPWizard):
last_import_type = 0
self.formatComboBox.setCurrentIndex(last_import_type)
for format in SongFormat.get_format_list():
select_mode = SongFormatAttr.get(format, SongFormatAttr.select_mode)
select_mode = SongFormat.get(format, SongFormat.SelectMode)
if select_mode == SongFormatSelect.MultipleFiles:
self.formatWidgets[format][u'fileListWidget'].clear()
else:
@ -366,8 +364,7 @@ class SongImportForm(OpenLPWizard):
the actual importing.
"""
source_format = self.currentFormat
select_mode = SongFormatAttr.get(source_format,
SongFormatAttr.select_mode)
select_mode = SongFormat.get(source_format, SongFormat.SelectMode)
if select_mode == SongFormatSelect.SingleFile:
importer = self.plugin.importSongs(source_format, filename=unicode(
self.formatWidgets[source_format][u'filepathEdit'].text()))
@ -401,9 +398,8 @@ class SongImportForm(OpenLPWizard):
def addFileSelectItem(self):
format = self.currentFormat
prefix, can_disable, select_mode = SongFormatAttr.get(
format, SongFormatAttr.prefix, SongFormatAttr.can_disable,
SongFormatAttr.select_mode)
prefix, can_disable, select_mode = SongFormat.get(format,
SongFormat.Prefix, SongFormat.CanDisable, SongFormat.SelectMode)
page = QtGui.QWidget()
page.setObjectName(prefix + u'Page')
if can_disable:
@ -500,21 +496,29 @@ class SongImportSourcePage(QtGui.QWizardPage):
def isComplete(self):
"""
Returns True if an available format is selected, and the
file/folder/files widget is not empty.
Returns True if:
* an available format is selected, and
* if MultipleFiles mode, at least one file is selected
* or if SingleFile mode, the specified file exists
* or if SingleFolder mode, the specified folder exists
When this method returns True, the wizard's Next button is enabled.
"""
wizard = self.wizard()
format = wizard.currentFormat
select_mode, format_available = SongFormatAttr.get(format,
SongFormatAttr.select_mode, SongFormatAttr.availability)
select_mode, format_available = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Availability)
if format_available:
if select_mode == SongFormatSelect.MultipleFiles:
if wizard.formatWidgets[format][u'fileListWidget'].count() > 0:
return True
else:
filepathEdit = wizard.formatWidgets[format][u'filepathEdit']
if not filepathEdit.text().isEmpty():
return True
filepath = wizard.formatWidgets[format][u'filepathEdit'].text()
if not filepath.isEmpty():
if select_mode == SongFormatSelect.SingleFile \
and os.path.isfile(filepath):
return True
elif select_mode == SongFormatSelect.SingleFolder \
and os.path.isdir(filepath):
return True
return False

View File

@ -44,6 +44,7 @@ from ewimport import EasyWorshipSongImport
from songbeamerimport import SongBeamerImport
from songshowplusimport import SongShowPlusImport
from foilpresenterimport import FoilPresenterImport
from zionworximport import ZionWorxImport
# Imports that might fail
log = logging.getLogger(__name__)
try:
@ -65,11 +66,42 @@ except ImportError:
log.exception('Error importing %s', 'OooImport')
HAS_OOO = False
class SongFormatSelect(object):
"""
This is a special enumeration class listing available file selection modes.
"""
SingleFile = 0
MultipleFiles = 1
SingleFolder = 2
class SongFormat(object):
"""
This is a special enumeration class that holds the various types of song
importers and some helper functions to facilitate access.
This is a special static class that holds an enumeration of the various
song formats handled by the importer, the attributes of each song format,
and a few helper functions.
Required attributes for each song format:
* ``Class`` Import class, e.g. OpenLyricsImport
* ``Name`` Name of the format, e.g. u'OpenLyrics'
* ``Prefix`` Prefix for Qt objects. Use camelCase, e.g. u'openLyrics'
See ``SongImportForm.addFileSelectItem()``.
Optional attributes for each song format:
* ``CanDisable`` Whether song format importer is disablable.
* ``Availability`` Whether song format importer is available.
* ``SelectMode`` Whether format accepts single file, multiple files, or
single folder (as per SongFormatSelect options).
* ``Filter`` File extension filter for QFileDialog.
Optional/custom text Strings for SongImportForm widgets:
* ``ComboBoxText`` Combo box selector (default value is format Name).
* ``DisabledLabelText`` Required for disablable song formats.
* ``GetFilesTitle`` Title for QFileDialog (default includes format Name).
* ``InvalidSourceMsg`` Message displayed when source does not validate with
Class.isValidSource().
"""
# Song Formats
Unknown = -1
OpenLyrics = 0
OpenLP2 = 1
@ -86,7 +118,171 @@ class SongFormat(object):
SongShowPlus = 12
SongsOfFellowship = 13
WordsOfWorship = 14
#CSV = 15
ZionWorx = 15
#CSV = 16
# Required attributes
Class = -10
Name = -11
Prefix = -12
# Optional attributes
CanDisable = -20
Availability = -21
SelectMode = -22
Filter = -23
# Optional/custom text values
ComboBoxText = -30
DisabledLabelText = -31
GetFilesTitle = -32
InvalidSourceMsg = -33
# Set optional attribute defaults
_defaults = {
CanDisable: False,
Availability: True,
SelectMode: SongFormatSelect.MultipleFiles,
Filter: u'',
ComboBoxText: None,
DisabledLabelText: u'',
GetFilesTitle: None,
InvalidSourceMsg: None
}
# Set attribute values for each Song Format
_attributes = {
OpenLyrics: {
Class: OpenLyricsImport,
Name: u'OpenLyrics',
Prefix: u'openLyrics',
Filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm',
'OpenLyrics Files'),
ComboBoxText: translate('SongsPlugin.ImportWizardForm',
'OpenLyrics or OpenLP 2.0 Exported Song')
},
OpenLP2: {
Class: OpenLPSongImport,
Name: UiStrings().OLPV2,
Prefix: u'openLP2',
SelectMode: SongFormatSelect.SingleFile,
Filter: u'%s (*.sqlite)' % (translate(
'SongsPlugin.ImportWizardForm', 'OpenLP 2.0 Databases'))
},
OpenLP1: {
Name: UiStrings().OLPV1,
Prefix: u'openLP1',
CanDisable: True,
SelectMode: SongFormatSelect.SingleFile,
Filter: u'%s (*.olp)' % translate('SongsPlugin.ImportWizardForm',
'openlp.org v1.x Databases'),
DisabledLabelText: WizardStrings.NoSqlite
},
Generic: {
Name: translate('SongsPlugin.ImportWizardForm',
'Generic Document/Presentation'),
Prefix: u'generic',
CanDisable: True,
DisabledLabelText: translate('SongsPlugin.ImportWizardForm',
'The generic document/presentation importer has been disabled '
'because OpenLP cannot access OpenOffice or LibreOffice.'),
GetFilesTitle: translate('SongsPlugin.ImportWizardForm',
'Select Document/Presentation Files')
},
CCLI: {
Class: CCLIFileImport,
Name: u'CCLI/SongSelect',
Prefix: u'ccli',
Filter: u'%s (*.usr *.txt)' % translate(
'SongsPlugin.ImportWizardForm', 'CCLI SongSelect Files')
},
DreamBeam: {
Class: DreamBeamImport,
Name: u'DreamBeam',
Prefix: u'dreamBeam',
Filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm',
'DreamBeam Song Files')
},
EasySlides: {
Class: EasySlidesImport,
Name: u'EasySlides',
Prefix: u'easySlides',
SelectMode: SongFormatSelect.SingleFile,
Filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm',
'EasySlides XML File')
},
EasyWorship: {
Class: EasyWorshipSongImport,
Name: u'EasyWorship',
Prefix: u'ew',
SelectMode: SongFormatSelect.SingleFile,
Filter: u'%s (*.db)' % translate('SongsPlugin.ImportWizardForm',
'EasyWorship Song Database')
},
FoilPresenter: {
Class: FoilPresenterImport,
Name: u'Foilpresenter',
Prefix: u'foilPresenter',
Filter: u'%s (*.foil)' % translate('SongsPlugin.ImportWizardForm',
'Foilpresenter Song Files')
},
OpenSong: {
Class: OpenSongImport,
Name: WizardStrings.OS,
Prefix: u'openSong'
},
PowerSong: {
Class: PowerSongImport,
Name: u'PowerSong 1.0',
Prefix: u'powerSong',
SelectMode: SongFormatSelect.SingleFolder,
InvalidSourceMsg: translate('SongsPlugin.ImportWizardForm',
'You need to specify a valid PowerSong 1.0 database folder.')
},
SongBeamer: {
Class: SongBeamerImport,
Name: u'SongBeamer',
Prefix: u'songBeamer',
Filter: u'%s (*.sng)' % translate('SongsPlugin.ImportWizardForm',
'SongBeamer Files')
},
SongShowPlus: {
Class: SongShowPlusImport,
Name: u'SongShow Plus',
Prefix: u'songShowPlus',
Filter: u'%s (*.sbsong)' % translate('SongsPlugin.ImportWizardForm',
'SongShow Plus Song Files')
},
SongsOfFellowship: {
Name: u'Songs of Fellowship',
Prefix: u'songsOfFellowship',
CanDisable: True,
Filter: u'%s (*.rtf)' % translate('SongsPlugin.ImportWizardForm',
'Songs Of Fellowship Song Files'),
DisabledLabelText: translate('SongsPlugin.ImportWizardForm',
'The Songs of Fellowship importer has been disabled because '
'OpenLP cannot access OpenOffice or LibreOffice.')
},
WordsOfWorship: {
Class: WowImport,
Name: u'Words of Worship',
Prefix: u'wordsOfWorship',
Filter: u'%s (*.wsg *.wow-song)' % translate(
'SongsPlugin.ImportWizardForm', 'Words Of Worship Song Files')
},
ZionWorx: {
Class: ZionWorxImport,
Name: u'ZionWorx',
Prefix: u'zionWorx',
SelectMode: SongFormatSelect.SingleFile,
ComboBoxText: translate('SongsPlugin.ImportWizardForm',
'ZionWorx (CSV database dump)')
# },
# CSV: {
# class_: CSVImport,
# name: WizardStrings.CSV,
# prefix: u'csv',
# select_mode: SongFormatSelect.SingleFile
}
}
@staticmethod
def get_format_list():
@ -108,200 +304,10 @@ class SongFormat(object):
SongFormat.SongBeamer,
SongFormat.SongShowPlus,
SongFormat.SongsOfFellowship,
SongFormat.WordsOfWorship
SongFormat.WordsOfWorship,
SongFormat.ZionWorx
]
class SongFormatSelect(object):
"""
This is a special enumeration class listing available file selection modes.
"""
SingleFile = 0
MultipleFiles = 1
SingleFolder = 2
class SongFormatAttr(object):
"""
This is a special static class that holds the attributes of each song format
to aid the importing of each song type.
The various definable attributes are enumerated as follows:
Required attributes for each song format:
* ``class_`` Import class, e.g. OpenLyricsImport
* ``name`` Name of this format, e.g. u'OpenLyrics'
* ``prefix`` Prefix for objects. Use camelCase, e.g. u'openLyrics'
See ``SongImportForm.addFileSelectItem()``.
Optional attributes for each song format:
* ``can_disable`` Whether song format is disablable.
* ``availability`` Whether song format is available.
* ``select_mode`` Whether format accepts single file, multiple files, or
single folder.
* ``filter`` File extension filter for QFileDialog.
Optional/custom text values for SongImportForm widgets:
* ``combo_box_text`` Combo box selector (default is format name).
* ``disabled_label_text`` Required for disablable song formats.
* ``get_files_title`` Title for QFileDialog (default includes format
name).
* ``invalid_source_msg`` Message shown when source does not validate with
class_.isValidSource().
"""
# Required attributes
class_ = 0
name = 1
prefix = 2
# Optional attributes
can_disable = 10
availability = 11
select_mode = 12
filter = 13
# Optional/custom text values
combo_box_text = 20
disabled_label_text = 21
get_files_title = 22
invalid_source_msg = 23
# Set optional attribute defaults
_defaults = {
can_disable: False,
availability: True,
select_mode: SongFormatSelect.MultipleFiles,
filter: u'',
combo_box_text: None,
disabled_label_text: u'',
get_files_title: None,
invalid_source_msg: None
}
# Set attribute values
_attributes = {
SongFormat.OpenLyrics: {
class_: OpenLyricsImport,
name: u'OpenLyrics',
prefix: u'openLyrics',
filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm',
'OpenLyrics Files'),
combo_box_text: translate('SongsPlugin.ImportWizardForm',
'OpenLyrics or OpenLP 2.0 Exported Song')
},
SongFormat.OpenLP2: {
class_: OpenLPSongImport,
name: UiStrings().OLPV2,
prefix: u'openLP2',
select_mode: SongFormatSelect.SingleFile,
filter: u'%s (*.sqlite)' % (translate(
'SongsPlugin.ImportWizardForm', 'OpenLP 2.0 Databases'))
},
SongFormat.OpenLP1: {
name: UiStrings().OLPV1,
prefix: u'openLP1',
can_disable: True,
select_mode: SongFormatSelect.SingleFile,
filter: u'%s (*.olp)' % translate('SongsPlugin.ImportWizardForm',
'openlp.org v1.x Databases'),
disabled_label_text: WizardStrings.NoSqlite
},
SongFormat.Generic: {
name: translate('SongsPlugin.ImportWizardForm',
'Generic Document/Presentation'),
prefix: u'generic',
can_disable: True,
disabled_label_text: translate('SongsPlugin.ImportWizardForm',
'The generic document/presentation importer has been disabled '
'because OpenLP cannot access OpenOffice or LibreOffice.'),
get_files_title: translate('SongsPlugin.ImportWizardForm',
'Select Document/Presentation Files')
},
SongFormat.CCLI: {
class_: CCLIFileImport,
name: u'CCLI/SongSelect',
prefix: u'ccli',
filter: u'%s (*.usr *.txt)' % translate(
'SongsPlugin.ImportWizardForm', 'CCLI SongSelect Files')
},
SongFormat.DreamBeam: {
class_: DreamBeamImport,
name: u'DreamBeam',
prefix: u'dreamBeam',
filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm',
'DreamBeam Song Files')
},
SongFormat.EasySlides: {
class_: EasySlidesImport,
name: u'EasySlides',
prefix: u'easySlides',
select_mode: SongFormatSelect.SingleFile,
filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm',
'EasySlides XML File')
},
SongFormat.EasyWorship: {
class_: EasyWorshipSongImport,
name: u'EasyWorship',
prefix: u'ew',
select_mode: SongFormatSelect.SingleFile,
filter: u'%s (*.db)' % translate('SongsPlugin.ImportWizardForm',
'EasyWorship Song Database')
},
SongFormat.FoilPresenter: {
class_: FoilPresenterImport,
name: u'Foilpresenter',
prefix: u'foilPresenter',
filter: u'%s (*.foil)' % translate('SongsPlugin.ImportWizardForm',
'Foilpresenter Song Files')
},
SongFormat.OpenSong: {
class_: OpenSongImport,
name: WizardStrings.OS,
prefix: u'openSong'
},
SongFormat.PowerSong: {
class_: PowerSongImport,
name: u'PowerSong 1.0',
prefix: u'powerSong',
select_mode: SongFormatSelect.SingleFolder,
invalid_source_msg: translate('SongsPlugin.ImportWizardForm',
'You need to specify a valid PowerSong 1.0 database folder.')
},
SongFormat.SongBeamer: {
class_: SongBeamerImport,
name: u'SongBeamer',
prefix: u'songBeamer',
filter: u'%s (*.sng)' % translate('SongsPlugin.ImportWizardForm',
'SongBeamer Files')
},
SongFormat.SongShowPlus: {
class_: SongShowPlusImport,
name: u'SongShow Plus',
prefix: u'songShowPlus',
filter: u'%s (*.sbsong)' % translate('SongsPlugin.ImportWizardForm',
'SongShow Plus Song Files')
},
SongFormat.SongsOfFellowship: {
name: u'Songs of Fellowship',
prefix: u'songsOfFellowship',
can_disable: True,
filter: u'%s (*.rtf)' % translate('SongsPlugin.ImportWizardForm',
'Songs Of Fellowship Song Files'),
disabled_label_text: translate('SongsPlugin.ImportWizardForm',
'The Songs of Fellowship importer has been disabled because '
'OpenLP cannot access OpenOffice or LibreOffice.')
},
SongFormat.WordsOfWorship: {
class_: WowImport,
name: u'Words of Worship',
prefix: u'wordsOfWorship',
filter: u'%s (*.wsg *.wow-song)' % translate(
'SongsPlugin.ImportWizardForm', 'Words Of Worship Song Files')
# },
# SongFormat.CSV: {
# class_: CSVImport,
# name: WizardStrings.CSV,
# prefix: u'csv',
# select_mode: SongFormatSelect.SingleFile
}
}
@staticmethod
def get(format, *attributes):
"""
@ -311,7 +317,7 @@ class SongFormatAttr(object):
A song format from SongFormat.
``*attributes``
Zero or more song format attributes from SongFormatAttr.
Zero or more song format attributes from SongFormat.
Return type depends on number of supplied attributes:
* 0 : Return dict containing all defined attributes for the format.
@ -319,16 +325,16 @@ class SongFormatAttr(object):
* >1 : Return tuple of requested attribute values.
"""
if not attributes:
return SongFormatAttr._attributes.get(format)
return SongFormat._attributes.get(format)
elif len(attributes) == 1:
default = SongFormatAttr._defaults.get(attributes[0])
return SongFormatAttr._attributes[format].get(attributes[0],
default = SongFormat._defaults.get(attributes[0])
return SongFormat._attributes[format].get(attributes[0],
default)
else:
values = []
for attr in attributes:
default = SongFormatAttr._defaults.get(attr)
values.append(SongFormatAttr._attributes[format].get(attr,
default = SongFormat._defaults.get(attr)
values.append(SongFormat._attributes[format].get(attr,
default))
return tuple(values)
@ -337,20 +343,16 @@ class SongFormatAttr(object):
"""
Set specified song format attribute to the supplied value.
"""
SongFormatAttr._attributes[format][attribute] = value
SongFormat._attributes[format][attribute] = value
SongFormatAttr.set(SongFormat.OpenLP1, SongFormatAttr.availability, HAS_OPENLP1)
SongFormat.set(SongFormat.OpenLP1, SongFormat.Availability, HAS_OPENLP1)
if HAS_OPENLP1:
SongFormatAttr.set(SongFormat.OpenLP1, SongFormatAttr.class_,
OpenLP1SongImport)
SongFormatAttr.set(SongFormat.SongsOfFellowship, SongFormatAttr.availability,
HAS_SOF)
SongFormat.set(SongFormat.OpenLP1, SongFormat.Class, OpenLP1SongImport)
SongFormat.set(SongFormat.SongsOfFellowship, SongFormat.Availability, HAS_SOF)
if HAS_SOF:
SongFormatAttr.set(SongFormat.SongsOfFellowship, SongFormatAttr.class_,
SofImport)
SongFormatAttr.set(SongFormat.Generic, SongFormatAttr.availability, HAS_OOO)
SongFormat.set(SongFormat.SongsOfFellowship, SongFormat.Class, SofImport)
SongFormat.set(SongFormat.Generic, SongFormat.Availability, HAS_OOO)
if HAS_OOO:
SongFormatAttr.set(SongFormat.Generic, SongFormatAttr.class_,
OooImport)
SongFormat.set(SongFormat.Generic, SongFormat.Class, OooImport)
__all__ = [u'SongFormat', u'SongFormatSelect', u'SongFormatAttr']
__all__ = [u'SongFormat', u'SongFormatSelect']

View File

@ -87,9 +87,8 @@ class PowerSongImport(SongImport):
"""
Receive either a list of files or a folder (unicode) to import.
"""
from importer import SongFormat, SongFormatAttr
PS_string = SongFormatAttr.get(SongFormat.PowerSong,
SongFormatAttr.name)
from importer import SongFormat
PS_string = SongFormat.get(SongFormat.PowerSong, SongFormat.Name)
if isinstance(self.importSource, unicode):
if os.path.isdir(self.importSource):
dir = self.importSource

View File

@ -73,46 +73,72 @@ class ZionWorxImport(SongImport):
* Note: This is the default format of the Python ``csv`` module.
"""
def doImport(self):
"""
Receive a CSV file (from a ZionWorx database dump) to import.
"""
if not os.path.isfile(self.importSource):
self.logError(unicode(translate('SongsPlugin.ZionWorxImport',
'No songs to import.')),
unicode(translate('SongsPlugin.ZionWorxImport',
'No %s CSV file found.' % WizardStrings.ZW)))
return
with open(self.importSource, 'rb') as songs_file:
songs_reader = csv.reader(songs_file)
try:
num_records = sum(1 for _ in songs_reader)
except csv.Error, e:
self.logError(unicode(translate('SongsPlugin.ZionWorxImport',
'Error reading CSV file.')),
unicode(translate('SongsPlugin.ZionWorxImport',
'Line %d: %s' % songs_reader.line_num, e)))
log.debug(u'%s records found in CSV file' % num_records)
self.importWizard.progressBar.setMaximum(num_records)
fieldnames = [u'SongNum', u'Title1', u'Title2', u'Lyrics',
u'Writer', u'Copyright', u'Keywords', u'DefaultStyle']
songs_reader_dict= csv.DictReader(songs_file, fieldnames)
songs_reader = csv.DictReader(songs_file, fieldnames)
try:
for record in songs_reader_dict:
if self.stopImportFlag:
return
self.setDefaults()
self.title = unicode(record[u'Title1'])
if record[u'Title2']:
self.alternateTitle = unicode(record[u'Title2'])
self.parseAuthor(unicode(record[u'Writer']))
self.addCopyright(unicode(record[u'Copyright']))
self.processSongText(unicode(record[u'Lyrics']))
if not self.finish():
self.logError(self.title)
records = list(songs_reader)
except csv.Error, e:
self.logError(unicode(translate('SongsPlugin.ZionWorxImport',
'Error reading CSV file.')),
unicode(translate('SongsPlugin.ZionWorxImport',
'Line %d: %s' % songs_reader_dict.line_num, e)))
'Line %d: %s' % (songs_reader.line_num, e))))
else:
num_records = len(records)
log.info(u'%s records found in CSV file' % num_records)
self.importWizard.progressBar.setMaximum(num_records)
try:
for index, record in enumerate(records, 1):
if self.stopImportFlag:
return
self.setDefaults()
try:
self.title = self._decode(record[u'Title1'])
if record[u'Title2']:
self.alternateTitle = self._decode(
record[u'Title2'])
self.parseAuthor(self._decode(record[u'Writer']))
self.addCopyright(self._decode(
record[u'Copyright']))
lyrics = self._decode(record[u'Lyrics'])
except UnicodeDecodeError, e:
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport',
'Decoding error.')),
unicode(translate('SongsPlugin.ZionWorxImport',
'Record %d: %s' % (index, e))))
else:
verse = u''
for line in lyrics.splitlines():
if line and not line.isspace():
verse += line + u'\n'
elif verse:
self.addVerse(verse)
verse = u''
if verse:
self.addVerse(verse)
title = self.title
if not self.finish():
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport',
'Record %d' % index))
+ (u': "' + title + u'"' if title else u''))
except TypeError, e:
self.logError(unicode(translate(
'SongsPlugin.ZionWorxImport',
'File not valid ZionWorx CSV format.')),
u'TypeError: %s' % e)
def _decode(self, str):
"""
Decodes CSV input to unicode.
This encoding choice seems OK. ZionWorx has no option for setting the
encoding for its songs, so we assume encoding is always the same.
"""
return unicode(str, u'cp1252')

View File

@ -39,7 +39,7 @@ from openlp.core.utils.actions import ActionList
from openlp.plugins.songs.lib import clean_song, upgrade, SongMediaItem, \
SongsTab
from openlp.plugins.songs.lib.db import init_schema, Song
from openlp.plugins.songs.lib.importer import SongFormatAttr
from openlp.plugins.songs.lib.importer import SongFormat
from openlp.plugins.songs.lib.olpimport import OpenLPSongImport
log = logging.getLogger(__name__)
@ -194,7 +194,7 @@ class SongsPlugin(Plugin):
self.manager.save_object(song)
def importSongs(self, format, **kwargs):
class_ = SongFormatAttr.get(format, SongFormatAttr.class_)
class_ = SongFormat.get(format, SongFormat.Class)
importer = class_(self.manager, **kwargs)
importer.register(self.mediaItem.importWizard)
return importer