summaryrefslogtreecommitdiffstats
path: root/modules/python/usfm2osis.py
diff options
context:
space:
mode:
authorChris Little <chrislit@crosswire.org>2012-08-26 22:40:55 +0000
committerChris Little <chrislit@crosswire.org>2012-08-26 22:40:55 +0000
commit49680c0072608952fdf24bb4d572a12611af9e80 (patch)
tree70cf609b09a3c970937a86c213dfe141d1fa167e /modules/python/usfm2osis.py
parentfdb561136ce47be309d220cde81561bf02c0884d (diff)
downloadsword-tools-49680c0072608952fdf24bb4d572a12611af9e80.tar.gz
added unsorted & random sort options
git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@398 07627401-56e2-0310-80f4-f8cd0041bdcd
Diffstat (limited to 'modules/python/usfm2osis.py')
-rwxr-xr-xmodules/python/usfm2osis.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/modules/python/usfm2osis.py b/modules/python/usfm2osis.py
index 872726a..043c1e8 100755
--- a/modules/python/usfm2osis.py
+++ b/modules/python/usfm2osis.py
@@ -50,7 +50,6 @@ scriptVersion = '0.5'
# 1.x SWORD module output?, requiring SWORD bindings
### TODO for next milestone:
-# file sorting options (natural/alphabetic/canonical/none)
# expand sub-verses with ! in osisIDs
# Python3 compatability
# document functions (docstrings)
@@ -90,6 +89,7 @@ scriptVersion = '0.5'
import sys, codecs, re
from encodings.aliases import aliases
import multiprocessing, Queue
+import random
date = date.replace('$', '').strip()[6:16]
rev = rev.replace('$', '').strip()[5:]
@@ -325,6 +325,12 @@ def keycanon(filename):
def keyusfm(filename):
return usfmNumericOrder.index(filename2osis[filename])
+def keysupplied(filename):
+ if not hasattr(keysupplied, "counter"):
+ keysupplied.counter = 0 # it doesn't exist yet, so initialize it
+ keysupplied.counter += 1
+ return keysupplied.counter
+
def convertToOsis(sFile):
global encoding
global relaxedConformance
@@ -1207,7 +1213,8 @@ def printUsage():
print(' -h, --help print this usage information')
print(' -o FILENAME output filename (default is: <osisWork>.osis.xml)')
print(' -r enable relaxed markup processing (for non-standard USFM)')
- print(' -s mode set book sorting mode: natural (default), alpha, canonical, usfm, none')
+ print(' -s mode set book sorting mode: natural (default), alpha, canonical,')
+ print(' usfm, random, none')
print(' -v verbose feedback')
print(' -x disable XML validation')
print('')
@@ -1322,15 +1329,17 @@ if __name__ == "__main__":
elif sys.argv[i].startswith('u'):
sortKey = keyusfm
print('Sorting book files by USFM book number.')
+ elif sys.argv[i].startswith('random'): # for testing only
+ sortKey = lambda filename: int(random.random()*256)
+ print('Sorting book files randomly.')
else:
- sortKey = None # TODO: write appropriate helpers
- print('Leaving book files unsorted.')
+ sortKey = keysupplied
+ print('Leaving book files unsorted, in the order in which they were supplied.')
inputFilesIdx += 2 # increment 2, reflecting 2 args for -s
else:
sortKey = keynat
print('Sorting book files naturally.')
-
usfmDocList = sys.argv[inputFilesIdx:]
for filename in usfmDocList: