forked from openlp/openlp
Add robustness to Generic document and Songs of Fellowship importers.
bzr-revno: 1601
This commit is contained in:
commit
7459255b65
@ -30,6 +30,7 @@ import os
|
|||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.utils import get_uno_command, get_uno_instance
|
from openlp.core.utils import get_uno_command, get_uno_instance
|
||||||
|
from openlp.core.lib import translate
|
||||||
from songimport import SongImport
|
from songimport import SongImport
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -39,8 +40,10 @@ if os.name == u'nt':
|
|||||||
PAGE_BEFORE = 4
|
PAGE_BEFORE = 4
|
||||||
PAGE_AFTER = 5
|
PAGE_AFTER = 5
|
||||||
PAGE_BOTH = 6
|
PAGE_BOTH = 6
|
||||||
|
NoConnectException = Exception
|
||||||
else:
|
else:
|
||||||
import uno
|
import uno
|
||||||
|
from com.sun.star.connection import NoConnectException
|
||||||
from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER, PAGE_BOTH
|
from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER, PAGE_BOTH
|
||||||
|
|
||||||
class OooImport(SongImport):
|
class OooImport(SongImport):
|
||||||
@ -57,7 +60,17 @@ class OooImport(SongImport):
|
|||||||
self.process_started = False
|
self.process_started = False
|
||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
|
if not isinstance(self.import_source, list):
|
||||||
|
return
|
||||||
|
try:
|
||||||
self.start_ooo()
|
self.start_ooo()
|
||||||
|
except NoConnectException as exc:
|
||||||
|
self.log_error(
|
||||||
|
self.import_source[0],
|
||||||
|
translate('SongsPlugin.SongImport',
|
||||||
|
'Unable to open OpenOffice.org or LibreOffice'))
|
||||||
|
log.error(exc)
|
||||||
|
return
|
||||||
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
self.import_wizard.progressBar.setMaximum(len(self.import_source))
|
||||||
for filename in self.import_source:
|
for filename in self.import_source:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
@ -68,6 +81,13 @@ class OooImport(SongImport):
|
|||||||
if self.document:
|
if self.document:
|
||||||
self.process_ooo_document()
|
self.process_ooo_document()
|
||||||
self.close_ooo_file()
|
self.close_ooo_file()
|
||||||
|
else:
|
||||||
|
self.log_error(self.filepath,
|
||||||
|
translate('SongsPlugin.SongImport',
|
||||||
|
'Unable to open file'))
|
||||||
|
else:
|
||||||
|
self.log_error(self.filepath,
|
||||||
|
translate('SongsPlugin.SongImport', 'File not found'))
|
||||||
self.close_ooo()
|
self.close_ooo()
|
||||||
|
|
||||||
def process_ooo_document(self):
|
def process_ooo_document(self):
|
||||||
@ -99,13 +119,16 @@ class OooImport(SongImport):
|
|||||||
while uno_instance is None and loop < 5:
|
while uno_instance is None and loop < 5:
|
||||||
try:
|
try:
|
||||||
uno_instance = get_uno_instance(resolver)
|
uno_instance = get_uno_instance(resolver)
|
||||||
except:
|
except NoConnectException:
|
||||||
log.exception("Failed to resolve uno connection")
|
log.exception("Failed to resolve uno connection")
|
||||||
self.start_ooo_process()
|
self.start_ooo_process()
|
||||||
loop += 1
|
loop += 1
|
||||||
|
else:
|
||||||
manager = uno_instance.ServiceManager
|
manager = uno_instance.ServiceManager
|
||||||
self.desktop = manager.createInstanceWithContext(
|
self.desktop = manager.createInstanceWithContext(
|
||||||
"com.sun.star.frame.Desktop", uno_instance)
|
"com.sun.star.frame.Desktop", uno_instance)
|
||||||
|
return
|
||||||
|
raise
|
||||||
|
|
||||||
def start_ooo_process(self):
|
def start_ooo_process(self):
|
||||||
try:
|
try:
|
||||||
@ -145,8 +168,8 @@ class OooImport(SongImport):
|
|||||||
else:
|
else:
|
||||||
self.import_wizard.incrementProgressBar(
|
self.import_wizard.incrementProgressBar(
|
||||||
u'Processing file ' + filepath, 0)
|
u'Processing file ' + filepath, 0)
|
||||||
except:
|
except AttributeError:
|
||||||
log.exception("open_ooo_file failed")
|
log.exception("open_ooo_file failed: %s", url)
|
||||||
return
|
return
|
||||||
|
|
||||||
def close_ooo_file(self):
|
def close_ooo_file(self):
|
||||||
|
@ -31,21 +31,27 @@
|
|||||||
# http://www.oooforum.org/forum/viewtopic.phtml?t=14409
|
# http://www.oooforum.org/forum/viewtopic.phtml?t=14409
|
||||||
# http://wiki.services.openoffice.org/wiki/Python
|
# http://wiki.services.openoffice.org/wiki/Python
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from oooimport import OooImport
|
from oooimport import OooImport
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
if os.name == u'nt':
|
if os.name == u'nt':
|
||||||
BOLD = 150.0
|
BOLD = 150.0
|
||||||
ITALIC = 2
|
ITALIC = 2
|
||||||
from oooimport import PAGE_BEFORE, PAGE_AFTER, PAGE_BOTH
|
from oooimport import PAGE_BEFORE, PAGE_AFTER, PAGE_BOTH
|
||||||
|
RuntimeException = Exception
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from com.sun.star.awt.FontWeight import BOLD
|
from com.sun.star.awt.FontWeight import BOLD
|
||||||
from com.sun.star.awt.FontSlant import ITALIC
|
from com.sun.star.awt.FontSlant import ITALIC
|
||||||
from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER, \
|
from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER, \
|
||||||
PAGE_BOTH
|
PAGE_BOTH
|
||||||
|
from com.sun.star.uno import RuntimeException
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -86,6 +92,7 @@ class SofImport(OooImport):
|
|||||||
"""
|
"""
|
||||||
self.blanklines = 0
|
self.blanklines = 0
|
||||||
self.new_song()
|
self.new_song()
|
||||||
|
try:
|
||||||
paragraphs = self.document.getText().createEnumeration()
|
paragraphs = self.document.getText().createEnumeration()
|
||||||
while paragraphs.hasMoreElements():
|
while paragraphs.hasMoreElements():
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
@ -93,9 +100,10 @@ class SofImport(OooImport):
|
|||||||
paragraph = paragraphs.nextElement()
|
paragraph = paragraphs.nextElement()
|
||||||
if paragraph.supportsService("com.sun.star.text.Paragraph"):
|
if paragraph.supportsService("com.sun.star.text.Paragraph"):
|
||||||
self.process_paragraph(paragraph)
|
self.process_paragraph(paragraph)
|
||||||
if self.song:
|
except RuntimeException as exc:
|
||||||
self.finish()
|
log.exception(u'Error processing file: %s', exc)
|
||||||
self.song = False
|
if not self.finish():
|
||||||
|
self.log_error(self.filepath)
|
||||||
|
|
||||||
def process_paragraph(self, paragraph):
|
def process_paragraph(self, paragraph):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user