summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hellings <greg.hellings@gmail.com>2018-04-05 02:18:14 +0000
committerGreg Hellings <greg.hellings@gmail.com>2018-04-05 02:18:14 +0000
commit1a6d0bd9172b498e85d6848f718affcdb8ece061 (patch)
tree74dc21e806a41e69f30ed153edb65f99cfd15f6b
parent6cef237f0b55a03ded27daff9ccb4b7dffdedc19 (diff)
downloadsword-tools-1a6d0bd9172b498e85d6848f718affcdb8ece061.tar.gz
Make versification/av11n.py script PEP-8 compliant
Mostly '\t' -> ' ' Patch from mcepl git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@518 07627401-56e2-0310-80f4-f8cd0041bdcd
-rwxr-xr-xversification/av11n.py163
1 files changed, 87 insertions, 76 deletions
diff --git a/versification/av11n.py b/versification/av11n.py
index 136a382..5e01c9e 100755
--- a/versification/av11n.py
+++ b/versification/av11n.py
@@ -11,102 +11,113 @@
# more output, change the following line to be True instead of False
verbose = False
debug = True
-import sys
import re
-verseid = re.compile('^.+\..+\..+$')
+import sys
+verseid = re.compile(r'^.+\..+\..+$')
# Inform the user that we need the SWORD extension
try:
- import Sword
-except:
- print "You do not have the SWORD library installed. Please install it."
- sys.exit(1)
+ import Sword
+except ImportError:
+ print "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 that much easier
+# Inform the user that we need pyquery, as it makes parsing XML files
+# that much easier
try:
- from pyquery import PyQuery as pq
-except:
- print "You do not appear to have PyQuery installed. Please install it."
- sys.exit(2)
+ from pyquery import PyQuery as pq # noqa
+except ImportError:
+ print "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 "Usage: %s <OSISfile>" % (sys.argv[0],)
# Open the file
if debug:
- print 'Opening %s' % (sys.argv[1],)
+ print 'Opening %s' % (sys.argv[1],)
d = pq(filename=sys.argv[1])
# Get the list of versifications
if debug:
- print 'Fetching a list of versifications'
+ print 'Fetching a list of versifications'
vmgr = Sword.VerseMgr.getSystemVerseMgr()
av11ns = vmgr.getVersificationSystems()
# Get the list of all osisIDs
if debug:
- print 'Fetching a list of OSIS IDs'
+ print 'Fetching a list of OSIS IDs'
ids = d("*[osisID]")
# Iterate each versification scheme
for v11n in av11ns:
- print 'Checking %s' % (v11n.c_str(),)
- # Construct a list of the IDs in this versification
- key = Sword.VerseKey()
- key.setVersificationSystem(v11n.c_str())
- otkeyList = [] # Anything left in this afterwards is missing from the OSIS ot
- ntkeyList = [] # Anything left in this afterwards is missing from the OSIS nt
- otextraKeys = [] # Anything that gets placed in here is extraneous OT material (we think)
- ntextraKeys = [] # Anything that gets placed in here is extraneous NT material (we think)
-
- inNT = False
- while key.Error() == '\x00':
- skey = key.getOSISRef()
- if not inNT and re.match('^Matt', skey): # Assume we enter the NT when we hit Matthew
- inNT = True
- if inNT:
- ntkeyList.append(skey)
- else:
- otkeyList.append(skey)
- key.increment()
- ntkeyList = set(ntkeyList) # The 'in' operator only works on a set
- otkeyList = set(otkeyList)
-
- inNT = False
- # Now iterate the ones we have in this file
- for e in ids:
- osisid = e.attrib.get('osisID')
- #print 'Checking key %s' % (osisid,)
- if osisid in otkeyList:
- otkeyList.remove(osisid)
- elif osisid in ntkeyList:
- ntkeyList.remove(osisid)
- inNT = True
- elif verseid.match(osisid) and inNT:
- ntextraKeys.append(osisid)
- elif verseid.match(osisid) and not inNT:
- otextraKeys.append(osisid)
- # Ignore it if not verseid.match()
-
- # Now let's see what is left over
- keyList = list(otkeyList.union(ntkeyList)) # Sets in Python cannot be ordered
- 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))
- 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))
- else:
- print '\tYour file has no extra references'
+ print 'Checking %s' % (v11n.c_str(),)
+ # Construct a list of the IDs in this versification
+ key = Sword.VerseKey()
+ key.setVersificationSystem(v11n.c_str())
+ # Anything left in this afterwards is missing from the OSIS ot
+ otkeyList = []
+ # Anything left in this afterwards is missing from the OSIS nt
+ ntkeyList = []
+ # Anything that gets placed in here is extraneous OT material (we think)
+ otextraKeys = []
+ # Anything that gets placed in here is extraneous NT material (we think)
+ ntextraKeys = []
+
+ inNT = False
+ while key.Error() == '\x00':
+ skey = key.getOSISRef()
+ # Assume we enter the NT when we hit Matthew
+ if not inNT and re.match('^Matt', skey):
+ inNT = True
+ if inNT:
+ ntkeyList.append(skey)
+ else:
+ otkeyList.append(skey)
+ key.increment()
+ ntkeyList = set(ntkeyList) # The 'in' operator only works on a set
+ otkeyList = set(otkeyList)
+
+ inNT = False
+ # Now iterate the ones we have in this file
+ for e in ids:
+ osisid = e.attrib.get('osisID')
+ #print 'Checking key %s' % (osisid,)
+ if osisid in otkeyList:
+ otkeyList.remove(osisid)
+ elif osisid in ntkeyList:
+ ntkeyList.remove(osisid)
+ inNT = True
+ elif verseid.match(osisid) and inNT:
+ ntextraKeys.append(osisid)
+ elif verseid.match(osisid) and not inNT:
+ otextraKeys.append(osisid)
+ # Ignore it if not verseid.match()
+
+ # Now let's see what is left over
+ # Sets in Python cannot be ordered
+ 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))
+ 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))
+ else:
+ print '\tYour file has no extra references'