def demo(): """ Demonstrate reading and checking some Bible databases. """ if BibleOrgSysGlobals.verbosityLevel > 0: print(ProgNameVersion) if 1: # Load and process some of our test versions count = 0 for name, abbreviation, testFolder in ( # name, abbreviation, folder ( "Open English Translation—Literal Version", "OET-LV", "../../../../../Data/Work/Matigsalug/Bible/OET-LV/", ), #("Matigsalug", "MBTV", "../../../../../Data/Work/Matigsalug/Bible/MBTV/",), #("ESFM Test 1", "OET-LV", "Tests/DataFilesForTests/ESFMTest1/"), #("ESFM Test 2", "OET-RV", "Tests/DataFilesForTests/ESFMTest2/"), #("All Markers Project", "WEB+", "Tests/DataFilesForTests/USFMAllMarkersProject/"), #("USFM Error Project", "UEP", "Tests/DataFilesForTests/USFMErrorProject/"), #("BOS Exported Files", "Exported", "Tests/BOS_USFM_Export/"), ): count += 1 if os.access(testFolder, os.R_OK): if BibleOrgSysGlobals.verbosityLevel > 0: print("\nESFM A{}/".format(count)) EsfmB = ESFMBible(testFolder, name, abbreviation) EsfmB.load() print("Gen assumed book name:", repr(EsfmB.getAssumedBookName('GEN'))) print("Gen long TOC book name:", repr(EsfmB.getLongTOCName('GEN'))) print("Gen short TOC book name:", repr(EsfmB.getShortTOCName('GEN'))) print("Gen book abbreviation:", repr(EsfmB.getBooknameAbbreviation('GEN'))) if BibleOrgSysGlobals.verbosityLevel > 0: print(EsfmB) if BibleOrgSysGlobals.strictCheckingFlag: EsfmB.check() #print( EsfmB.books['GEN']._processedLines[0:40] ) EsfmBErrors = EsfmB.getErrors() # print( UBErrors ) if BibleOrgSysGlobals.commandLineOptions.export: ##EsfmB.toDrupalBible() EsfmB.doAllExports(wantPhotoBible=False, wantODFs=True, wantPDFs=True) newObj = BibleOrgSysGlobals.unpickleObject( BibleOrgSysGlobals.makeSafeFilename(abbreviation) + '.pickle', os.path.join("OutputFiles/", "BOS_Bible_Object_Pickle/")) if BibleOrgSysGlobals.verbosityLevel > 0: print("newObj is", newObj) else: print( "\nSorry, test folder {!r} is not readable on this computer." .format(testFolder)) if 0: # Test a whole folder full of folders of ESFM Bibles testBaseFolder = "Tests/DataFilesForTests/theWordRoundtripTestFiles/" def findInfo(somepath): """ Find out info about the project from the included copyright.htm file """ cFilepath = os.path.join(somepath, "copyright.htm") if not os.path.exists(cFilepath): return with open(cFilepath, encoding='utf-8' ) as myFile: # Automatically closes the file when done lastLine, lineCount = None, 0 title, nameDict = None, {} for line in myFile: lineCount += 1 if lineCount == 1 and line and line[0] == chr( 65279): #U+FEFF logging.info( "ESFMBible: Detected UTF-16 Byte Order Marker in copyright.htm file" ) line = line[1:] # Remove the UTF-8 Byte Order Marker if line[-1] == '\n': line = line[:-1] # Removing trailing newline character if not line: continue # Just discard blank lines lastLine = line if line.startswith("<title>"): title = line.replace("<title>", "").replace("</title>", "").strip() if line.startswith('<option value="'): adjLine = line.replace('<option value="', '').replace('</option>', '') ESFM_BBB, name = adjLine[:3], adjLine[11:] BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromESFM( ESFM_BBB) #print( ESFM_BBB, BBB, name ) nameDict[BBB] = name return title, nameDict # end of findInfo count = totalBooks = 0 if os.access(testBaseFolder, os.R_OK): # check that we can read the test data for something in sorted(os.listdir(testBaseFolder)): somepath = os.path.join(testBaseFolder, something) if os.path.isfile(somepath): print("Ignoring file {!r} in {!r}".format( something, testBaseFolder)) elif os.path.isdir( somepath ): # Let's assume that it's a folder containing a ESFM (partial) Bible #if not something.startswith( 'ssx' ): continue # This line is used for debugging only specific modules count += 1 title = None findInfoResult = findInfo(somepath) if findInfoResult: title, bookNameDict = findInfoResult if title is None: title = something[:-5] if something.endswith( "_usfm") else something name, testFolder = title, somepath if os.access(testFolder, os.R_OK): if BibleOrgSysGlobals.verbosityLevel > 0: print("\nESFM B{}/".format(count)) EsfmB = ESFMBible(testFolder, name) EsfmB.load() if BibleOrgSysGlobals.verbosityLevel > 0: print(EsfmB) if BibleOrgSysGlobals.strictCheckingFlag: EsfmB.check() EsfmBErrors = EsfmB.getErrors() #print( EsfmBErrors ) if BibleOrgSysGlobals.commandLineOptions.export: EsfmB.doAllExports(wantPhotoBible=False, wantODFs=False, wantPDFs=False) else: print( "\nSorry, test folder {!r} is not readable on this computer." .format(testFolder)) if count: print("\n{} total ESFM (partial) Bibles processed.".format( count)) if totalBooks: print("{} total books ({} average per folder)".format( totalBooks, round(totalBooks / count))) else: print( "\nSorry, test folder {!r} is not readable on this computer.". format(testBaseFolder))
def demo(): """ Demonstrate reading and checking some Bible databases. """ if BibleOrgSysGlobals.verbosityLevel > 0: print( ProgNameVersion ) if 1: # Load and process some of our test versions count = 0 for name, abbreviation, testFolder in ( # name, abbreviation, folder ("Open English Translation—Literal Version", "OET-LV", "../../../../../Data/Work/Matigsalug/Bible/OET-LV/",), #("Matigsalug", "MBTV", "../../../../../Data/Work/Matigsalug/Bible/MBTV/",), #("ESFM Test 1", "OET-LV", "Tests/DataFilesForTests/ESFMTest1/"), #("ESFM Test 2", "OET-RV", "Tests/DataFilesForTests/ESFMTest2/"), #("All Markers Project", "WEB+", "Tests/DataFilesForTests/USFMAllMarkersProject/"), #("USFM Error Project", "UEP", "Tests/DataFilesForTests/USFMErrorProject/"), #("BOS Exported Files", "Exported", "Tests/BOS_USFM_Export/"), ): count += 1 if os.access( testFolder, os.R_OK ): if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nESFM A{}/".format( count ) ) EsfmB = ESFMBible( testFolder, name, abbreviation ) EsfmB.load() print( "Gen assumed book name:", repr( EsfmB.getAssumedBookName( 'GEN' ) ) ) print( "Gen long TOC book name:", repr( EsfmB.getLongTOCName( 'GEN' ) ) ) print( "Gen short TOC book name:", repr( EsfmB.getShortTOCName( 'GEN' ) ) ) print( "Gen book abbreviation:", repr( EsfmB.getBooknameAbbreviation( 'GEN' ) ) ) if BibleOrgSysGlobals.verbosityLevel > 0: print( EsfmB ) if BibleOrgSysGlobals.strictCheckingFlag: EsfmB.check() #print( EsfmB.books['GEN']._processedLines[0:40] ) EsfmBErrors = EsfmB.getErrors() # print( UBErrors ) if BibleOrgSysGlobals.commandLineOptions.export: ##EsfmB.toDrupalBible() EsfmB.doAllExports( wantPhotoBible=False, wantODFs=True, wantPDFs=True ) newObj = BibleOrgSysGlobals.unpickleObject( BibleOrgSysGlobals.makeSafeFilename(abbreviation) + '.pickle', os.path.join( "OutputFiles/", "BOS_Bible_Object_Pickle/" ) ) if BibleOrgSysGlobals.verbosityLevel > 0: print( "newObj is", newObj ) else: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testFolder ) ) if 0: # Test a whole folder full of folders of ESFM Bibles testBaseFolder = "Tests/DataFilesForTests/theWordRoundtripTestFiles/" def findInfo( somepath ): """ Find out info about the project from the included copyright.htm file """ cFilepath = os.path.join( somepath, "copyright.htm" ) if not os.path.exists( cFilepath ): return with open( cFilepath, encoding='utf-8' ) as myFile: # Automatically closes the file when done lastLine, lineCount = None, 0 title, nameDict = None, {} for line in myFile: lineCount += 1 if lineCount==1 and line and line[0]==chr(65279): #U+FEFF logging.info( "ESFMBible: Detected UTF-16 Byte Order Marker in copyright.htm file" ) line = line[1:] # Remove the UTF-8 Byte Order Marker if line[-1]=='\n': line = line[:-1] # Removing trailing newline character if not line: continue # Just discard blank lines lastLine = line if line.startswith("<title>"): title = line.replace("<title>","").replace("</title>","").strip() if line.startswith('<option value="'): adjLine = line.replace('<option value="','').replace('</option>','') ESFM_BBB, name = adjLine[:3], adjLine[11:] BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromESFM( ESFM_BBB ) #print( ESFM_BBB, BBB, name ) nameDict[BBB] = name return title, nameDict # end of findInfo count = totalBooks = 0 if os.access( testBaseFolder, os.R_OK ): # check that we can read the test data for something in sorted( os.listdir( testBaseFolder ) ): somepath = os.path.join( testBaseFolder, something ) if os.path.isfile( somepath ): print( "Ignoring file {!r} in {!r}".format( something, testBaseFolder ) ) elif os.path.isdir( somepath ): # Let's assume that it's a folder containing a ESFM (partial) Bible #if not something.startswith( 'ssx' ): continue # This line is used for debugging only specific modules count += 1 title = None findInfoResult = findInfo( somepath ) if findInfoResult: title, bookNameDict = findInfoResult if title is None: title = something[:-5] if something.endswith("_usfm") else something name, testFolder = title, somepath if os.access( testFolder, os.R_OK ): if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nESFM B{}/".format( count ) ) EsfmB = ESFMBible( testFolder, name ) EsfmB.load() if BibleOrgSysGlobals.verbosityLevel > 0: print( EsfmB ) if BibleOrgSysGlobals.strictCheckingFlag: EsfmB.check() EsfmBErrors = EsfmB.getErrors() #print( EsfmBErrors ) if BibleOrgSysGlobals.commandLineOptions.export: EsfmB.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) else: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testFolder ) ) if count: print( "\n{} total ESFM (partial) Bibles processed.".format( count ) ) if totalBooks: print( "{} total books ({} average per folder)".format( totalBooks, round(totalBooks/count) ) ) else: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testBaseFolder ) )
def demo(): """ Demonstrate reading and checking some Bible databases. """ if BibleOrgSysGlobals.verbosityLevel > 0: print(ProgNameVersion) #testFolder = "Tests/DataFilesForTests/BCVTest1/" testFolder = "OutputFiles/BOS_BCV_Export/" if 1: # demo the file checking code -- first with the whole folder and then with only one folder if BibleOrgSysGlobals.verbosityLevel > 0: print("\nBCV TestA1") result1 = BCVBibleFileCheck(testFolder) if BibleOrgSysGlobals.verbosityLevel > 1: print("BCV TestA1", result1) if BibleOrgSysGlobals.verbosityLevel > 0: print("\nBCV TestA2") result2 = BCVBibleFileCheck(testFolder, autoLoad=True) # But doesn't preload books if BibleOrgSysGlobals.verbosityLevel > 1: print("BCV TestA2", result2) #result2.loadMetadataFile( os.path.join( testFolder, "BooknamesMetadata.txt" ) ) if BibleOrgSysGlobals.strictCheckingFlag: result2.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) bibleErrors = result2.getErrors() # print( bibleErrors ) #if BibleOrgSysGlobals.commandLineArguments.export: ###result2.toDrupalBible() #result2.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) if BibleOrgSysGlobals.verbosityLevel > 0: print("\nBCV TestA3") result3 = BCVBibleFileCheck(testFolder, autoLoad=True, autoLoadBooks=True) if BibleOrgSysGlobals.verbosityLevel > 1: print("BCV TestA3", result3) #result3.loadMetadataFile( os.path.join( testFolder, "BooknamesMetadata.txt" ) ) if BibleOrgSysGlobals.strictCheckingFlag: result3.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) bibleErrors = result3.getErrors() # print( bibleErrors ) if BibleOrgSysGlobals.commandLineArguments.export: ##result3.toDrupalBible() result3.doAllExports(wantPhotoBible=False, wantODFs=False, wantPDFs=False) if 0: # all discovered modules in the test folder foundFolders, foundFiles = [], [] for something in os.listdir(testFolder): somepath = os.path.join(testFolder, something) if os.path.isdir(somepath): foundFolders.append(something) elif os.path.isfile(somepath): foundFiles.append(something) if BibleOrgSysGlobals.maxProcesses > 1: # Get our subprocesses ready and waiting for work if BibleOrgSysGlobals.verbosityLevel > 1: print("\nTrying all {} discovered modules…".format( len(foundFolders))) parameters = [folderName for folderName in sorted(foundFolders)] BibleOrgSysGlobals.alreadyMultiprocessing = True with multiprocessing.Pool(processes=BibleOrgSysGlobals.maxProcesses ) as pool: # start worker processes results = pool.map(testBCV, parameters) # have the pool do our loads assert len(results) == len( parameters ) # Results (all None) are actually irrelevant to us here BibleOrgSysGlobals.alreadyMultiprocessing = False else: # Just single threaded for j, someFolder in enumerate(sorted(foundFolders)): if BibleOrgSysGlobals.verbosityLevel > 1: print("\nBCV D{}/ Trying {}".format(j + 1, someFolder)) #myTestFolder = os.path.join( testFolder, someFolder+'/' ) testBCV(someFolder) if 0: # Load and process some of our test versions count = 0 for name, encoding, testFolder in ( ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/BCVTest1/"), ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/BCVTest2/"), ("Exported", 'utf-8', "Tests/BOS_BCV_Export/"), ): count += 1 if os.access(testFolder, os.R_OK): if BibleOrgSysGlobals.verbosityLevel > 0: print("\nBCV A{}/".format(count)) bcvB = BCVBible(testFolder, name, encoding=encoding) bcvB.load() if BibleOrgSysGlobals.verbosityLevel > 1: print("Gen assumed book name:", repr(bcvB.getAssumedBookName('GEN'))) print("Gen long TOC book name:", repr(bcvB.getLongTOCName('GEN'))) print("Gen short TOC book name:", repr(bcvB.getShortTOCName('GEN'))) print("Gen book abbreviation:", repr(bcvB.getBooknameAbbreviation('GEN'))) if BibleOrgSysGlobals.verbosityLevel > 0: print(bcvB) if BibleOrgSysGlobals.strictCheckingFlag: bcvB.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) bcbibleErrors = bcvB.getErrors() # print( bcbibleErrors ) if BibleOrgSysGlobals.commandLineArguments.export: ##bcvB.toDrupalBible() bcvB.doAllExports(wantPhotoBible=False, wantODFs=False, wantPDFs=False) newObj = BibleOrgSysGlobals.unpickleObject( BibleOrgSysGlobals.makeSafeFilename(name) + '.pickle', os.path.join("OutputFiles/", "BOS_Bible_Object_Pickle/")) if BibleOrgSysGlobals.verbosityLevel > 0: print("newObj is", newObj) else: print( "\nSorry, test folder {!r} is not readable on this computer." .format(testFolder))
def demo(): """ Demonstrate reading and checking some Bible databases. """ if BibleOrgSysGlobals.verbosityLevel > 0: print( ProgNameVersion ) #testFolder = "Tests/DataFilesForTests/BCVTest1/" testFolder = "OutputFiles/BOS_BCV_Export/" if 1: # demo the file checking code -- first with the whole folder and then with only one folder if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nBCV TestA1" ) result1 = BCVBibleFileCheck( testFolder ) if BibleOrgSysGlobals.verbosityLevel > 1: print( "BCV TestA1", result1 ) if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nBCV TestA2" ) result2 = BCVBibleFileCheck( testFolder, autoLoad=True ) # But doesn't preload books if BibleOrgSysGlobals.verbosityLevel > 1: print( "BCV TestA2", result2 ) #result2.loadMetadataFile( os.path.join( testFolder, "BooknamesMetadata.txt" ) ) if BibleOrgSysGlobals.strictCheckingFlag: result2.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) bibleErrors = result2.getErrors() # print( bibleErrors ) #if BibleOrgSysGlobals.commandLineArguments.export: ###result2.toDrupalBible() #result2.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nBCV TestA3" ) result3 = BCVBibleFileCheck( testFolder, autoLoad=True, autoLoadBooks=True ) if BibleOrgSysGlobals.verbosityLevel > 1: print( "BCV TestA3", result3 ) #result3.loadMetadataFile( os.path.join( testFolder, "BooknamesMetadata.txt" ) ) if BibleOrgSysGlobals.strictCheckingFlag: result3.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) bibleErrors = result3.getErrors() # print( bibleErrors ) if BibleOrgSysGlobals.commandLineArguments.export: ##result3.toDrupalBible() result3.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) if 0: # all discovered modules in the test folder foundFolders, foundFiles = [], [] for something in os.listdir( testFolder ): somepath = os.path.join( testFolder, something ) if os.path.isdir( somepath ): foundFolders.append( something ) elif os.path.isfile( somepath ): foundFiles.append( something ) if BibleOrgSysGlobals.maxProcesses > 1: # Get our subprocesses ready and waiting for work if BibleOrgSysGlobals.verbosityLevel > 1: print( "\nTrying all {} discovered modules…".format( len(foundFolders) ) ) parameters = [folderName for folderName in sorted(foundFolders)] BibleOrgSysGlobals.alreadyMultiprocessing = True with multiprocessing.Pool( processes=BibleOrgSysGlobals.maxProcesses ) as pool: # start worker processes results = pool.map( testBCV, parameters ) # have the pool do our loads assert len(results) == len(parameters) # Results (all None) are actually irrelevant to us here BibleOrgSysGlobals.alreadyMultiprocessing = False else: # Just single threaded for j, someFolder in enumerate( sorted( foundFolders ) ): if BibleOrgSysGlobals.verbosityLevel > 1: print( "\nBCV D{}/ Trying {}".format( j+1, someFolder ) ) #myTestFolder = os.path.join( testFolder, someFolder+'/' ) testBCV( someFolder ) if 0: # Load and process some of our test versions count = 0 for name, encoding, testFolder in ( ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/BCVTest1/"), ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/BCVTest2/"), ("Exported", 'utf-8', "Tests/BOS_BCV_Export/"), ): count += 1 if os.access( testFolder, os.R_OK ): if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nBCV A{}/".format( count ) ) bcvB = BCVBible( testFolder, name, encoding=encoding ) bcvB.load() if BibleOrgSysGlobals.verbosityLevel > 1: print( "Gen assumed book name:", repr( bcvB.getAssumedBookName( 'GEN' ) ) ) print( "Gen long TOC book name:", repr( bcvB.getLongTOCName( 'GEN' ) ) ) print( "Gen short TOC book name:", repr( bcvB.getShortTOCName( 'GEN' ) ) ) print( "Gen book abbreviation:", repr( bcvB.getBooknameAbbreviation( 'GEN' ) ) ) if BibleOrgSysGlobals.verbosityLevel > 0: print( bcvB ) if BibleOrgSysGlobals.strictCheckingFlag: bcvB.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) bcbibleErrors = bcvB.getErrors() # print( bcbibleErrors ) if BibleOrgSysGlobals.commandLineArguments.export: ##bcvB.toDrupalBible() bcvB.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) newObj = BibleOrgSysGlobals.unpickleObject( BibleOrgSysGlobals.makeSafeFilename(name) + '.pickle', os.path.join( "OutputFiles/", "BOS_Bible_Object_Pickle/" ) ) if BibleOrgSysGlobals.verbosityLevel > 0: print( "newObj is", newObj ) else: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testFolder ) )
def demo(): """ Demonstrate reading and checking some Bible databases. """ if BibleOrgSysGlobals.verbosityLevel > 0: print( ProgNameVersion ) if 1: # demo the file checking code -- first with the whole folder and then with only one folder for j,testFolder in enumerate( ("Tests/DataFilesForTests/USFMTest1/", "Tests/DataFilesForTests/USFMTest2/", "Tests/DataFilesForTests/USFMTest3/", "Tests/DataFilesForTests/USFMAllMarkersProject/", "Tests/DataFilesForTests/USFMErrorProject/", "Tests/DataFilesForTests/PTX7Test/", "OutputFiles/BOS_USFM_Export/", "OutputFiles/BOS_USFM_Reexport/", "MadeUpFolder/", ) ): print( "\nUSFM A{} testfolder is: {}".format( j+1, testFolder ) ) result1 = USFMBibleFileCheck( testFolder ) if BibleOrgSysGlobals.verbosityLevel > 1: print( "USFM TestAa", result1 ) result2 = USFMBibleFileCheck( testFolder, autoLoad=True ) if BibleOrgSysGlobals.verbosityLevel > 1: print( "USFM TestAb", result2 ) result3 = USFMBibleFileCheck( testFolder, autoLoadBooks=True ) if BibleOrgSysGlobals.verbosityLevel > 1: print( "USFM TestAc", result3 ) if isinstance( result3, Bible ): if BibleOrgSysGlobals.strictCheckingFlag: result3.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) UsfmBErrors = UsfmB.getErrors() # print( UBErrors ) if BibleOrgSysGlobals.commandLineArguments.export: result3.pickle() ##UsfmB.toDrupalBible() result3.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) if 1: # Load and process some of our test versions for j,(name, encoding, testFolder) in enumerate( ( ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/USFMTest1/"), ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/USFMTest2/"), ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/USFMTest3/"), ("WEB+", 'utf-8', "Tests/DataFilesForTests/USFMAllMarkersProject/"), ("UEP", 'utf-8', "Tests/DataFilesForTests/USFMErrorProject/"), ("Exported", 'utf-8', "Tests/BOS_USFM_Export/"), ) ): if os.access( testFolder, os.R_OK ): if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nUSFM B{}/".format( j+1 ) ) UsfmB = USFMBible( testFolder, name, encoding=encoding ) UsfmB.load() if BibleOrgSysGlobals.verbosityLevel > 1: print( "Gen assumed book name:", repr( UsfmB.getAssumedBookName( 'GEN' ) ) ) print( "Gen long TOC book name:", repr( UsfmB.getLongTOCName( 'GEN' ) ) ) print( "Gen short TOC book name:", repr( UsfmB.getShortTOCName( 'GEN' ) ) ) print( "Gen book abbreviation:", repr( UsfmB.getBooknameAbbreviation( 'GEN' ) ) ) if BibleOrgSysGlobals.verbosityLevel > 0: print( UsfmB ) if BibleOrgSysGlobals.strictCheckingFlag: UsfmB.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) UsfmBErrors = UsfmB.getErrors() # print( UBErrors ) if BibleOrgSysGlobals.commandLineArguments.export: UsfmB.pickle() ##UsfmB.toDrupalBible() UsfmB.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) newObj = BibleOrgSysGlobals.unpickleObject( BibleOrgSysGlobals.makeSafeFilename(name) + '.pickle', os.path.join( "OutputFiles/", "BOS_Bible_Object_Pickle/" ) ) if BibleOrgSysGlobals.verbosityLevel > 0: print( "newObj is", newObj ) elif BibleOrgSysGlobals.verbosityLevel > 0: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testFolder ) ) if 0: # Test a whole folder full of folders of USFM Bibles testBaseFolder = "Tests/DataFilesForTests/theWordRoundtripTestFiles/" def findInfo( somepath ): """ Find out info about the project from the included copyright.htm file """ cFilepath = os.path.join( somepath, "copyright.htm" ) if not os.path.exists( cFilepath ): return with open( cFilepath ) as myFile: # Automatically closes the file when done lastLine, lineCount = None, 0 title, nameDict = None, {} for line in myFile: lineCount += 1 if lineCount==1: if line[0]==chr(65279): #U+FEFF logging.info( "USFMBible.findInfo1: Detected Unicode Byte Order Marker (BOM) in {}".format( "copyright.htm" ) ) line = line[1:] # Remove the UTF-16 Unicode Byte Order Marker (BOM) elif line[:3] == '': # 0xEF,0xBB,0xBF logging.info( "USFMBible.findInfo2: Detected Unicode Byte Order Marker (BOM) in {}".format( "copyright.htm" ) ) line = line[3:] # Remove the UTF-8 Unicode Byte Order Marker (BOM) if line[-1]=='\n': line = line[:-1] # Removing trailing newline character if not line: continue # Just discard blank lines lastLine = line if line.startswith("<title>"): title = line.replace("<title>","").replace("</title>","").strip() if line.startswith('<option value="'): adjLine = line.replace('<option value="','').replace('</option>','') USFM_BBB, name = adjLine[:3], adjLine[11:] BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromUSFM( USFM_BBB ) #print( USFM_BBB, BBB, name ) nameDict[BBB] = name return title, nameDict # end of findInfo count = totalBooks = 0 if os.access( testBaseFolder, os.R_OK ): # check that we can read the test data for something in sorted( os.listdir( testBaseFolder ) ): somepath = os.path.join( testBaseFolder, something ) if os.path.isfile( somepath ): print( "Ignoring file {!r} in {!r}".format( something, testBaseFolder ) ) elif os.path.isdir( somepath ): # Let's assume that it's a folder containing a USFM (partial) Bible #if not something.startswith( 'ssx' ): continue # This line is used for debugging only specific modules count += 1 title = None findInfoResult = findInfo( somepath ) if findInfoResult: title, bookNameDict = findInfoResult if title is None: title = something[:-5] if something.endswith("_usfm") else something name, encoding, testFolder = title, 'utf-8', somepath if os.access( testFolder, os.R_OK ): if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nUSFM C{}/".format( count ) ) UsfmB = USFMBible( testFolder, name, encoding=encoding ) UsfmB.load() if BibleOrgSysGlobals.verbosityLevel > 0: print( UsfmB ) if BibleOrgSysGlobals.strictCheckingFlag: UsfmB.check() UsfmBErrors = UsfmB.getErrors() #print( UsfmBErrors ) if BibleOrgSysGlobals.commandLineArguments.export: UsfmB.doAllExports( wantPhotoBible=False, wantODFs=False, wantPDFs=False ) else: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testFolder ) ) if count: print( "\n{} total USFM (partial) Bibles processed.".format( count ) ) if totalBooks: print( "{} total books ({} average per folder)".format( totalBooks, round(totalBooks/count) ) ) elif BibleOrgSysGlobals.verbosityLevel > 0: print( "\nSorry, test folder {!r} is not readable on this computer.".format( testBaseFolder ) )
def demo(): """ Demonstrate reading and checking some Bible databases. """ if BibleOrgSysGlobals.verbosityLevel > 0: print(ProgNameVersion) if 1: # demo the file checking code -- first with the whole folder and then with only one folder for j, testFolder in enumerate(( "Tests/DataFilesForTests/USFMTest1/", "Tests/DataFilesForTests/USFMTest2/", "Tests/DataFilesForTests/USFMTest3/", "Tests/DataFilesForTests/USFMAllMarkersProject/", "Tests/DataFilesForTests/USFMErrorProject/", "Tests/DataFilesForTests/PTX7Test/", "OutputFiles/BOS_USFM_Export/", "OutputFiles/BOS_USFM_Reexport/", "MadeUpFolder/", )): print("\nUSFM A{} testfolder is: {}".format(j + 1, testFolder)) result1 = USFMBibleFileCheck(testFolder) if BibleOrgSysGlobals.verbosityLevel > 1: print("USFM TestAa", result1) result2 = USFMBibleFileCheck(testFolder, autoLoad=True) if BibleOrgSysGlobals.verbosityLevel > 1: print("USFM TestAb", result2) result3 = USFMBibleFileCheck(testFolder, autoLoadBooks=True) if BibleOrgSysGlobals.verbosityLevel > 1: print("USFM TestAc", result3) if isinstance(result3, Bible): if BibleOrgSysGlobals.strictCheckingFlag: result3.check() #print( result3.books['GEN']._processedLines[0:40] ) UsfmBErrors = result3.getErrors() # print( UBErrors ) if BibleOrgSysGlobals.commandLineArguments.export: result3.pickle() ##result3.toDrupalBible() result3.doAllExports(wantPhotoBible=False, wantODFs=False, wantPDFs=False) if 1: # Load and process some of our test versions for j, (name, encoding, testFolder) in enumerate(( ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/USFMTest1/"), ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/USFMTest2/"), ("Matigsalug", 'utf-8', "Tests/DataFilesForTests/USFMTest3/"), ("WEB+", 'utf-8', "Tests/DataFilesForTests/USFMAllMarkersProject/"), ("UEP", 'utf-8', "Tests/DataFilesForTests/USFMErrorProject/"), ("Exported", 'utf-8', "Tests/BOS_USFM_Export/"), )): if os.access(testFolder, os.R_OK): if BibleOrgSysGlobals.verbosityLevel > 0: print("\nUSFM B{}/".format(j + 1)) UsfmB = USFMBible(testFolder, name, encoding=encoding) UsfmB.load() if BibleOrgSysGlobals.verbosityLevel > 1: print("Gen assumed book name:", repr(UsfmB.getAssumedBookName('GEN'))) print("Gen long TOC book name:", repr(UsfmB.getLongTOCName('GEN'))) print("Gen short TOC book name:", repr(UsfmB.getShortTOCName('GEN'))) print("Gen book abbreviation:", repr(UsfmB.getBooknameAbbreviation('GEN'))) if BibleOrgSysGlobals.verbosityLevel > 0: print(UsfmB) if BibleOrgSysGlobals.strictCheckingFlag: UsfmB.check() #print( UsfmB.books['GEN']._processedLines[0:40] ) UsfmBErrors = UsfmB.getErrors() # print( UBErrors ) if BibleOrgSysGlobals.commandLineArguments.export: UsfmB.pickle() ##UsfmB.toDrupalBible() UsfmB.doAllExports(wantPhotoBible=False, wantODFs=False, wantPDFs=False) newObj = BibleOrgSysGlobals.unpickleObject( BibleOrgSysGlobals.makeSafeFilename(name) + '.pickle', os.path.join("OutputFiles/", "BOS_Bible_Object_Pickle/")) if BibleOrgSysGlobals.verbosityLevel > 0: print("newObj is", newObj) elif BibleOrgSysGlobals.verbosityLevel > 0: print( "\nSorry, test folder {!r} is not readable on this computer." .format(testFolder)) if 0: # Test a whole folder full of folders of USFM Bibles testBaseFolder = "Tests/DataFilesForTests/theWordRoundtripTestFiles/" def findInfo(somepath): """ Find out info about the project from the included copyright.htm file """ cFilepath = os.path.join(somepath, "copyright.htm") if not os.path.exists(cFilepath): return with open(cFilepath ) as myFile: # Automatically closes the file when done lastLine, lineCount = None, 0 title, nameDict = None, {} for line in myFile: lineCount += 1 if lineCount == 1: if line[0] == chr(65279): #U+FEFF logging.info( "USFMBible.findInfo1: Detected Unicode Byte Order Marker (BOM) in {}" .format("copyright.htm")) line = line[ 1:] # Remove the UTF-16 Unicode Byte Order Marker (BOM) elif line[:3] == '': # 0xEF,0xBB,0xBF logging.info( "USFMBible.findInfo2: Detected Unicode Byte Order Marker (BOM) in {}" .format("copyright.htm")) line = line[ 3:] # Remove the UTF-8 Unicode Byte Order Marker (BOM) if line[-1] == '\n': line = line[:-1] # Removing trailing newline character if not line: continue # Just discard blank lines lastLine = line if line.startswith("<title>"): title = line.replace("<title>", "").replace("</title>", "").strip() if line.startswith('<option value="'): adjLine = line.replace('<option value="', '').replace('</option>', '') USFM_BBB, name = adjLine[:3], adjLine[11:] BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromUSFM( USFM_BBB) #print( USFM_BBB, BBB, name ) nameDict[BBB] = name return title, nameDict # end of findInfo count = totalBooks = 0 if os.access(testBaseFolder, os.R_OK): # check that we can read the test data for something in sorted(os.listdir(testBaseFolder)): somepath = os.path.join(testBaseFolder, something) if os.path.isfile(somepath): print("Ignoring file {!r} in {!r}".format( something, testBaseFolder)) elif os.path.isdir( somepath ): # Let's assume that it's a folder containing a USFM (partial) Bible #if not something.startswith( 'ssx' ): continue # This line is used for debugging only specific modules count += 1 title = None findInfoResult = findInfo(somepath) if findInfoResult: title, bookNameDict = findInfoResult if title is None: title = something[:-5] if something.endswith( "_usfm") else something name, encoding, testFolder = title, 'utf-8', somepath if os.access(testFolder, os.R_OK): if BibleOrgSysGlobals.verbosityLevel > 0: print("\nUSFM C{}/".format(count)) UsfmB = USFMBible(testFolder, name, encoding=encoding) UsfmB.load() if BibleOrgSysGlobals.verbosityLevel > 0: print(UsfmB) if BibleOrgSysGlobals.strictCheckingFlag: UsfmB.check() UsfmBErrors = UsfmB.getErrors() #print( UsfmBErrors ) if BibleOrgSysGlobals.commandLineArguments.export: UsfmB.doAllExports(wantPhotoBible=False, wantODFs=False, wantPDFs=False) else: print( "\nSorry, test folder {!r} is not readable on this computer." .format(testFolder)) if count: print("\n{} total USFM (partial) Bibles processed.".format( count)) if totalBooks: print("{} total books ({} average per folder)".format( totalBooks, round(totalBooks / count))) elif BibleOrgSysGlobals.verbosityLevel > 0: print( "\nSorry, test folder {!r} is not readable on this computer.". format(testBaseFolder))