← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~gerald-britton/openlp/importer into lp:openlp

 

jerryb has proposed merging lp:~gerald-britton/openlp/importer into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)

For more details, see:
https://code.launchpad.net/~gerald-britton/openlp/importer/+merge/62915

This branch contains a change to a single module -- importer.py. The purpose of the change is to add exception reporting for the three imports done under try/except.  This will ensure that an entry is written to the log detailing the reason for the failed import.  This is important since if the module to be imported is found but it suffers an import failure for some reason, it is helpful to know that reason.  For example:

Given a file t.py that has a single line:

import foo

Running an interactive session:

$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import t
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "t.py", line 1, in <module>
    import foo
ImportError: No module named foo

So, the problem above is that "foo" is not found even though module "t" is.  Currently, we just catch the ImportError and set a flag indicating that we cannot import that type of song file.  With this patch, we will be able to see more about the cause of the failed import, especially if it is a subsequent import failure in a subordinate module.

30 May - moved import logging statement as requested
-- 
https://code.launchpad.net/~gerald-britton/openlp/importer/+merge/62915
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/importer.py'
--- openlp/plugins/songs/lib/importer.py	2011-05-26 17:11:22 +0000
+++ openlp/plugins/songs/lib/importer.py	2011-05-30 20:17:24 +0000
@@ -27,6 +27,7 @@
 """
 The :mod:`importer` modules provides the general song import functionality.
 """
+import logging
 from opensongimport import OpenSongImport
 from easislidesimport import EasiSlidesImport
 from olpimport import OpenLPSongImport
@@ -38,20 +39,24 @@
 from songshowplusimport import SongShowPlusImport
 from foilpresenterimport import FoilPresenterImport
 # Imports that might fail
+log = logging.getLogger(__name__)
 try:
     from olp1import import OpenLP1SongImport
     HAS_OPENLP1 = True
 except ImportError:
+    log.exception('Error importing %s', 'OpenLP1SongImport')
     HAS_OPENLP1 = False
 try:
     from sofimport import SofImport
     HAS_SOF = True
 except ImportError:
+    log.exception('Error importing %s', 'SofImport')
     HAS_SOF = False
 try:
     from oooimport import OooImport
     HAS_OOO = True
 except ImportError:
+    log.exception('Error importing %s', 'OooImport')
     HAS_OOO = False
 
 class SongFormat(object):


Follow ups