forked from openlp/openlp
Catch common errors during import and report to user
This commit is contained in:
parent
a5a8c0d6d2
commit
d05c349f41
@ -40,6 +40,7 @@ if os.name == u'nt':
|
|||||||
PAGE_BOTH = 6
|
PAGE_BOTH = 6
|
||||||
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):
|
||||||
@ -56,7 +57,16 @@ 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],
|
||||||
|
u'Unable to connect to 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:
|
||||||
@ -98,13 +108,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:
|
||||||
|
@ -30,10 +30,14 @@
|
|||||||
# 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
|
||||||
|
from com.sun.star.uno import RuntimeException
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
if os.name == u'nt':
|
if os.name == u'nt':
|
||||||
BOLD = 150.0
|
BOLD = 150.0
|
||||||
@ -85,6 +89,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:
|
||||||
@ -92,9 +97,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