[sword-svn] r345 - trunk/modules

greg.hellings at crosswire.org greg.hellings at crosswire.org
Sun Jan 8 12:10:37 MST 2012


Author: greg.hellings
Date: 2012-01-08 12:10:37 -0700 (Sun, 08 Jan 2012)
New Revision: 345

Added:
   trunk/modules/compare.py
Log:
Added a file which will compare two SWORD modules and report any
verses where their content differs.

Added: trunk/modules/compare.py
===================================================================
--- trunk/modules/compare.py	                        (rev 0)
+++ trunk/modules/compare.py	2012-01-08 19:10:37 UTC (rev 345)
@@ -0,0 +1,47 @@
+#! /usr/bin/env python
+# Comapres two SWORD Bible modules for identical content
+#
+# Distributed under the "here, have it" license.
+#
+# Greg Hellings <greg.hellings at gmail.com>
+import Sword
+import sys
+
+# Check we have sufficient options
+if len(sys.argv) < 3:
+	print 'Usage: %s <First Module> <Second Module>' % (sys.argv[0], )
+	print 'Compares two SWORD Bible modules, verse by verse, to certify that the contents of each are identical.'
+	sys.exit(-1)
+# Warn if we have too many
+if len(sys.argv) > 3:
+	print 'Usage: %s <First Module> <Second Module>' % (sys.argv[0], )
+	print 'WARNING: Only accepts two arguments, treating first two arguments as module names, ignoring the rest.'
+	
+# Grab the base SWORD manager
+mgr = Sword.SWMgr()
+# Get the two modules, provided they both exist - this is an advanced user tool, if these throw errors, too bad
+original = mgr.getModule(sys.argv[1])
+test     = mgr.getModule(sys.argv[2])
+# Create the keys we will need so we can track - if original is not a Bible or Commentary, this will probably cause errors
+key = Sword.VerseKey(original.CreateKey())
+test.SetKey(key)
+book = key.Book()
+
+# Loop until one of the two modules throws an error, then exit
+while original.Error() == '\x00' and test.Error() == '\x00':
+	# Get the texts of each module and compare them
+	oText = original.RenderText()
+	tText = test.RenderText()
+	if oText != tText:
+		print 'Mismatch in %s\nOriginal text is**********:\n%s\nNew Text is*********:\n%s\n' % (key.getText(), oText, tText)
+	# Increment the keys to the next verse, and provide feedback if we have finished comparing an entire canonical book
+	original.increment()
+	key = Sword.VerseKey(original.getKey())
+	test.SetKey(key)
+	if book != key.Book():
+		print 'Checked up through %s' % (key.getText(),)
+		book = key.Book()
+
+# Alert the user where the comparison finished, in case we exited before the end of the Bible, indicating one of the modules
+# might be incomplete
+print 'Exited comparison at %s' % (key.getText(),)


Property changes on: trunk/modules/compare.py
___________________________________________________________________
Added: svn:executable
   + *




More information about the sword-cvs mailing list