summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hellings <greg.hellings@gmail.com>2018-04-05 02:29:20 +0000
committerGreg Hellings <greg.hellings@gmail.com>2018-04-05 02:29:20 +0000
commit49cb074836fefb9526176ddd4a64ee71dc289672 (patch)
tree23ecc9b0baaf1d8fcb4389d2a0fd6ed76b41dbce
parent16c06f5192d5ab95dcd94bf4b898bc2d809d2e0d (diff)
downloadsword-tools-49cb074836fefb9526176ddd4a64ee71dc289672.tar.gz
Switch to logging to make it a little bit more civilized.
git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@520 07627401-56e2-0310-80f4-f8cd0041bdcd
-rwxr-xr-xversification/av11n.py57
1 files changed, 27 insertions, 30 deletions
diff --git a/versification/av11n.py b/versification/av11n.py
index 7dabfee..54347a8 100755
--- a/versification/av11n.py
+++ b/versification/av11n.py
@@ -7,10 +7,12 @@
# in the proper order, although within each testament, it requires nothing
# special as for ordering.
#
-# Invoke simply by calling the program and the file name. If you want
-# more output, change the following line to be True instead of False
-verbose = False
-debug = True
+# Invoke simply by calling the program and the file name.
+import logging
+# in normal state level should be debug.WARNING, debug.INFO and debug.DEBUG
+# give additional information.
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ level=logging.WARNING)
import re
import sys
verseid = re.compile(r'^.+\..+\..+$')
@@ -19,7 +21,8 @@ verseid = re.compile(r'^.+\..+\..+$')
try:
import Sword
except ImportError:
- print "You do not have the SWORD library installed. Please install it."
+ logging.exception(
+ "You do not have the SWORD library installed. Please install it.")
sys.exit(1)
# Inform the user that we need pyquery, as it makes parsing XML files
@@ -27,30 +30,29 @@ except ImportError:
try:
from pyquery import PyQuery as pq # noqa
except ImportError:
- print "You do not appear to have PyQuery installed. Please install it."
+ logging.exception(
+ "You do not appear to have PyQuery installed. Please install it.")
sys.exit(2)
# Without the name of a file, we cannot proceed any further
if len(sys.argv) < 2 or sys.argv[1] == '--help':
- print "Usage: %s <OSISfile>" % (sys.argv[0],)
+ print >>sys.stderr, "Usage: %s <OSISfile>" % sys.argv[0]
+ sys.exit(1)
# Open the file
-if debug:
- print 'Opening %s' % (sys.argv[1],)
+logging.debug('Opening %s' % (sys.argv[1],))
d = pq(filename=sys.argv[1])
# Get the list of versifications
-if debug:
- print 'Fetching a list of versifications'
+logging.debug('Fetching a list of versifications')
vmgr = Sword.VersificationMgr.getSystemVersificationMgr()
av11ns = vmgr.getVersificationSystems()
# Get the list of all osisIDs
-if debug:
- print 'Fetching a list of OSIS IDs'
+logging.debug('Fetching a list of OSIS IDs')
ids = d("*[osisID]")
# Iterate each versification scheme
for v11n in av11ns:
- print 'Checking %s' % (v11n.c_str(),)
+ print('Checking %s' % v11n.c_str())
# Construct a list of the IDs in this versification
key = Sword.VerseKey()
key.setVersificationSystem(v11n.c_str())
@@ -98,26 +100,21 @@ for v11n in av11ns:
keyList = list(otkeyList.union(ntkeyList))
keyList.sort()
if len(keyList) > 0:
- if verbose:
- print '\tThe following IDs do not appear in your file:'
- for k in keyList:
- print k
- else:
- print ('\tThere are %d OT IDs and %d NT IDs ' +
- 'in the versification which are not in your file.') \
- % (len(otkeyList), len(ntkeyList))
+ logging.info('\tThe following IDs do not appear in your file:\n%s',
+ str("\n".join(keyList)))
+ print ('\tThere are %d OT IDs and %d NT IDs ' +
+ 'in the versification which are not in your file.') \
+ % (len(otkeyList), len(ntkeyList))
else:
print '\tYour file has all the references in this versification'
# Now let's see if you had extra
if len(otextraKeys + ntextraKeys) > 0:
- if verbose:
- print '\tThe following IDs do not appear in the versification:'
- for k in ntextraKeys + otextraKeys:
- print k
- else:
- print ('\tThere are %d OT IDs and %d NT IDs ' +
- 'in your file which do not appear in the versification.') \
- % (len(otextraKeys), len(ntextraKeys))
+ logging.info(
+ '\tThe following IDs do not appear in the versification:\n%s',
+ str("\n".join(keyList)))
+ print ('\tThere are %d OT IDs and %d NT IDs ' +
+ 'in your file which do not appear in the versification.') \
+ % (len(otextraKeys), len(ntextraKeys))
else:
print '\tYour file has no extra references'