Exemple #1
0
    def __init__(self, sourceFolder=None, moduleName=None, encoding='utf-8'):
        """
        Constructor: just sets up the Bible object.

        The sourceFolder should be the one containing mods.d and modules folders.
        The module name (if needed) should be the name of one of the .conf files in the mods.d folder
            (with or without the .conf on it).
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print("SwordBible.__init__( {} {} {} )".format(
                sourceFolder, moduleName, encoding))

        if not sourceFolder and not moduleName:
            logging.critical(
                _("SwordBible must be passed either a folder path or a module name!"
                  ))
            return

        # Setup and initialise the base class first
        Bible.__init__(self)
        self.objectNameString = 'Sword Bible object'
        self.objectTypeString = 'CrosswireSword' if SwordType == 'CrosswireLibrary' else 'Sword'

        # Now we can set our object variables
        self.sourceFolder, self.moduleName, self.encoding = sourceFolder, moduleName, encoding
        self.SwordInterface = None

        if self.sourceFolder:
            # Do a preliminary check on the readability of our folder
            if not os.access(self.sourceFolder, os.R_OK):
                logging.critical(
                    _("SwordBible: Folder {!r} is unreadable").format(
                        self.sourceFolder))

            if not self.moduleName:  # If we weren't passed the module name, we need to assume that there's only one
                confFolder = os.path.join(self.sourceFolder, 'mods.d/')
                foundConfs = []
                for something in os.listdir(confFolder):
                    somepath = os.path.join(confFolder, something)
                    if os.path.isfile(somepath) and something.endswith(
                            '.conf'):
                        foundConfs.append(something[:-5])  # Drop the .conf bit
                if foundConfs == 0:
                    logging.critical(
                        "No .conf files found in {}".format(confFolder))
                elif len(foundConfs) > 1:
                    logging.critical(
                        "Too many .conf files found in {}".format(confFolder))
                else:
                    if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
                        print("SwordBible.__init__ got", foundConfs[0])
                    self.moduleName = foundConfs[0]
        self.abbreviation = self.moduleName  # First attempt

        # Load the Sword manager and find our module
        if self.SwordInterface is None and SwordType is not None:
            self.SwordInterface = SwordInterface()  # Load the Sword library
        if self.SwordInterface is None:  # still
            logging.critical(exp("SwordBible: no Sword interface available"))
            return
        #try: self.SWMgr = Sword.SWMgr()
        #except NameError:
        #logging.critical( _("Unable to initialise {!r} module -- no Sword manager available").format( self.moduleName ) )
        #return # our Sword import must have failed
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule and SwordType == 'CrosswireLibrary':
            availableGlobalOptions = [
                str(option)
                for option in self.SwordInterface.library.getGlobalOptions()
            ]
            print("availableGlobalOptions", availableGlobalOptions)
        # Don't need to set options if we use getRawEntry() rather than stripText() or renderText()
        #for optionName in ( 'Headings', 'Footnotes', 'Cross-references', "Strong's Numbers", 'Morphological Tags', ):
        #self.SWMgr.setGlobalOption( optionName, 'On' )

        if self.sourceFolder:
            self.SwordInterface.library.augmentModules(
                self.sourceFolder, False)  # Add our folder to the SW Mgr

        availableModuleCodes = []
        for j, something in enumerate(
                self.SwordInterface.library.getModules()):
            # something can be a moduleBuffer (Crosswire) or just a string (BOS)
            if SwordType == 'CrosswireLibrary':
                if isinstance(something, str):
                    print("Why did we get a string instead of a module? {}".
                          format(something))
                if BibleOrgSysGlobals.strictCheckingFlag:
                    assert not isinstance(something, str)
                moduleID = something.getRawData()
            else:
                if BibleOrgSysGlobals.strictCheckingFlag:
                    assert isinstance(something, str)
                moduleID = something
            if BibleOrgSysGlobals.strictCheckingFlag:
                assert isinstance(moduleID, str)

            if moduleID.upper() == self.moduleName.upper():
                self.moduleName = moduleID  # Get the case correct
            #module = SWMgr.getModule( moduleID )
            #if 0:
            #print( "{} {} ({}) {} {!r}".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) )
            #try: print( "    {} {!r} {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) )
            #except UnicodeDecodeError: print( "   Description is not Unicode!" )
            #print( "moduleID", repr(moduleID) )
            availableModuleCodes.append(moduleID)
        #print( "Available module codes:", availableModuleCodes )

        if self.moduleName not in availableModuleCodes:
            logging.critical("Unable to find {!r} Sword module".format(
                self.moduleName))
            if BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.verbosityLevel > 2:
                print("Available module codes:", availableModuleCodes)

        self.abbreviation = self.moduleName  # Perhaps a better attempt
Exemple #2
0
    def __init__( self, sourceFolder=None, moduleName=None, encoding='utf-8' ):
        """
        Constructor: just sets up the Bible object.

        The sourceFolder should be the one containing mods.d and modules folders.
        The module name (if needed) should be the name of one of the .conf files in the mods.d folder
            (with or without the .conf on it).
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print( "SwordBible.__init__( {} {} {} )".format( sourceFolder, moduleName, encoding ) )

        if not sourceFolder and not moduleName:
            logging.critical( _("SwordBible must be passed either a folder path or a module name!" ) )
            return

         # Setup and initialise the base class first
        Bible.__init__( self )
        self.objectNameString = 'Sword Bible object'
        self.objectTypeString = 'Sword'

        # Now we can set our object variables
        self.sourceFolder, self.moduleName, self.encoding = sourceFolder, moduleName, encoding
        self.SwordInterface = None

        if self.sourceFolder:
            # Do a preliminary check on the readability of our folder
            if not os.access( self.sourceFolder, os.R_OK ):
                logging.critical( _("SwordBible: Folder {!r} is unreadable").format( self.sourceFolder ) )

            if not self.moduleName: # If we weren't passed the module name, we need to assume that there's only one
                confFolder = os.path.join( self.sourceFolder, 'mods.d/' )
                foundConfs = []
                for something in os.listdir( confFolder ):
                    somepath = os.path.join( confFolder, something )
                    if os.path.isfile( somepath ) and something.endswith( '.conf' ):
                        foundConfs.append( something[:-5] ) # Drop the .conf bit
                if foundConfs == 0:
                    logging.critical( "No .conf files found in {}".format( confFolder ) )
                elif len(foundConfs) > 1:
                    logging.critical( "Too many .conf files found in {}".format( confFolder ) )
                else:
                    print( "SwordBible.__init__ got", foundConfs[0] )
                    self.moduleName = foundConfs[0]
        self.abbreviation = self.moduleName # First attempt

        # Load the Sword manager and find our module
        if self.SwordInterface is None and SwordType is not None:
            self.SwordInterface = SwordInterface() # Load the Sword library
        if self.SwordInterface is None: # still
            logging.critical( exp("SwordBible: no Sword interface available") )
            return
        #try: self.SWMgr = Sword.SWMgr()
        #except NameError:
            #logging.critical( _("Unable to initialise {!r} module -- no Sword manager available").format( self.moduleName ) )
            #return # our Sword import must have failed
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule and SwordType=='CrosswireLibrary':
            availableGlobalOptions = [str(option) for option in self.SwordInterface.library.getGlobalOptions()]
            print( "availableGlobalOptions", availableGlobalOptions )
        # Don't need to set options if we use getRawEntry() rather than stripText() or renderText()
        #for optionName in ( 'Headings', 'Footnotes', 'Cross-references', "Strong's Numbers", 'Morphological Tags', ):
            #self.SWMgr.setGlobalOption( optionName, 'On' )

        if self.sourceFolder:
            self.SwordInterface.library.augmentModules( self.sourceFolder, False ) # Add our folder to the SW Mgr

        availableModuleCodes = []
        for j,something in enumerate(self.SwordInterface.library.getModules()):
            # something can be a moduleBuffer (Crosswire) or just a string (BOS)
            moduleID = something.getRawData() if SwordType=='CrosswireLibrary' else something

            if moduleID.upper() == self.moduleName.upper(): self.moduleName = moduleID # Get the case correct
            #module = SWMgr.getModule( moduleID )
            #if 0:
                #print( "{} {} ({}) {} {!r}".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) )
                #try: print( "    {} {!r} {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) )
                #except UnicodeDecodeError: print( "   Description is not Unicode!" )
            #print( "moduleID", repr(moduleID) )
            availableModuleCodes.append( moduleID )
        #print( "Available module codes:", availableModuleCodes )

        if self.moduleName not in availableModuleCodes:
            logging.critical( "Unable to find {!r} Sword module".format( self.moduleName ) )
            if BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.verbosityLevel > 2:
                print( "Available module codes:", availableModuleCodes )

        self.abbreviation = self.moduleName # Perhaps a better attempt
Exemple #3
0
class SwordBible(Bible):
    """
    Class for reading, validating, and converting SwordBible files.
    """
    def __init__(self, sourceFolder=None, moduleName=None, encoding='utf-8'):
        """
        Constructor: just sets up the Bible object.

        The sourceFolder should be the one containing mods.d and modules folders.
        The module name (if needed) should be the name of one of the .conf files in the mods.d folder
            (with or without the .conf on it).
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print("SwordBible.__init__( {} {} {} )".format(
                sourceFolder, moduleName, encoding))

        if not sourceFolder and not moduleName:
            logging.critical(
                _("SwordBible must be passed either a folder path or a module name!"
                  ))
            return

        # Setup and initialise the base class first
        Bible.__init__(self)
        self.objectNameString = 'Sword Bible object'
        self.objectTypeString = 'CrosswireSword' if SwordType == 'CrosswireLibrary' else 'Sword'

        # Now we can set our object variables
        self.sourceFolder, self.moduleName, self.encoding = sourceFolder, moduleName, encoding
        self.SwordInterface = None

        if self.sourceFolder:
            # Do a preliminary check on the readability of our folder
            if not os.access(self.sourceFolder, os.R_OK):
                logging.critical(
                    _("SwordBible: Folder {!r} is unreadable").format(
                        self.sourceFolder))

            if not self.moduleName:  # If we weren't passed the module name, we need to assume that there's only one
                confFolder = os.path.join(self.sourceFolder, 'mods.d/')
                foundConfs = []
                for something in os.listdir(confFolder):
                    somepath = os.path.join(confFolder, something)
                    if os.path.isfile(somepath) and something.endswith(
                            '.conf'):
                        foundConfs.append(something[:-5])  # Drop the .conf bit
                if foundConfs == 0:
                    logging.critical(
                        "No .conf files found in {}".format(confFolder))
                elif len(foundConfs) > 1:
                    logging.critical(
                        "Too many .conf files found in {}".format(confFolder))
                else:
                    if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
                        print("SwordBible.__init__ got", foundConfs[0])
                    self.moduleName = foundConfs[0]
        self.abbreviation = self.moduleName  # First attempt

        # Load the Sword manager and find our module
        if self.SwordInterface is None and SwordType is not None:
            self.SwordInterface = SwordInterface()  # Load the Sword library
        if self.SwordInterface is None:  # still
            logging.critical(exp("SwordBible: no Sword interface available"))
            return
        #try: self.SWMgr = Sword.SWMgr()
        #except NameError:
        #logging.critical( _("Unable to initialise {!r} module -- no Sword manager available").format( self.moduleName ) )
        #return # our Sword import must have failed
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule and SwordType == 'CrosswireLibrary':
            availableGlobalOptions = [
                str(option)
                for option in self.SwordInterface.library.getGlobalOptions()
            ]
            print("availableGlobalOptions", availableGlobalOptions)
        # Don't need to set options if we use getRawEntry() rather than stripText() or renderText()
        #for optionName in ( 'Headings', 'Footnotes', 'Cross-references', "Strong's Numbers", 'Morphological Tags', ):
        #self.SWMgr.setGlobalOption( optionName, 'On' )

        if self.sourceFolder:
            self.SwordInterface.library.augmentModules(
                self.sourceFolder, False)  # Add our folder to the SW Mgr

        availableModuleCodes = []
        for j, something in enumerate(
                self.SwordInterface.library.getModules()):
            # something can be a moduleBuffer (Crosswire) or just a string (BOS)
            if SwordType == 'CrosswireLibrary':
                if isinstance(something, str):
                    print("Why did we get a string instead of a module? {}".
                          format(something))
                if BibleOrgSysGlobals.strictCheckingFlag:
                    assert not isinstance(something, str)
                moduleID = something.getRawData()
            else:
                if BibleOrgSysGlobals.strictCheckingFlag:
                    assert isinstance(something, str)
                moduleID = something
            if BibleOrgSysGlobals.strictCheckingFlag:
                assert isinstance(moduleID, str)

            if moduleID.upper() == self.moduleName.upper():
                self.moduleName = moduleID  # Get the case correct
            #module = SWMgr.getModule( moduleID )
            #if 0:
            #print( "{} {} ({}) {} {!r}".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) )
            #try: print( "    {} {!r} {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) )
            #except UnicodeDecodeError: print( "   Description is not Unicode!" )
            #print( "moduleID", repr(moduleID) )
            availableModuleCodes.append(moduleID)
        #print( "Available module codes:", availableModuleCodes )

        if self.moduleName not in availableModuleCodes:
            logging.critical("Unable to find {!r} Sword module".format(
                self.moduleName))
            if BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.verbosityLevel > 2:
                print("Available module codes:", availableModuleCodes)

        self.abbreviation = self.moduleName  # Perhaps a better attempt

    # end of SwordBible.__init__

    def loadBooks(self):
        """
        Load the compressed data file and import book elements.
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print(exp("SwordBible.loadBooks()"))

        if BibleOrgSysGlobals.verbosityLevel > 1:
            print(_("\nLoading {} module…").format(self.moduleName))

        self.SwordInterface.loadBooks(self, self.moduleName)

        #try: module = self.SwordInterface.library.getModule( self.moduleName )
        #except AttributeError: # probably no SWMgr
        #logging.critical( _("Unable to load {!r} module -- no Sword loader available").format( self.moduleName ) )
        #return
        #if module is None:
        #logging.critical( _("Unable to load {!r} module -- not known by Sword").format( self.moduleName ) )
        #return

        #if SwordType=='CrosswireLibrary': # need to load the module
        #markupCode = ord( module.getMarkup() )
        #encoding = ord( module.getEncoding() )
        #if encoding == ENC_LATIN1: self.encoding = 'latin-1'
        #elif encoding == ENC_UTF8: self.encoding = 'utf-8'
        #elif encoding == ENC_UTF16: self.encoding = 'utf-16'
        #elif BibleOrgSysGlobals.debugFlag and debuggingThisModule: halt

        #if BibleOrgSysGlobals.verbosityLevel > 3:
        #print( 'Description: {!r}'.format( module.getDescription() ) )
        #print( 'Direction: {!r}'.format( ord(module.getDirection()) ) )
        #print( 'Encoding: {!r}'.format( encoding ) )
        #print( 'Language: {!r}'.format( module.getLanguage() ) )
        #print( 'Markup: {!r}={}'.format( markupCode, FMT_DICT[markupCode] ) )
        #print( 'Name: {!r}'.format( module.getName() ) )
        #print( 'RenderHeader: {!r}'.format( module.getRenderHeader() ) )
        #print( 'Type: {!r}'.format( module.getType() ) )
        #print( 'IsSkipConsecutiveLinks: {!r}'.format( module.isSkipConsecutiveLinks() ) )
        #print( 'IsUnicode: {!r}'.format( module.isUnicode() ) )
        #print( 'IsWritable: {!r}'.format( module.isWritable() ) )
        ##return

        #bookCount = 0
        #currentBBB = None
        #for index in range( 0, 999999 ):
        #module.setIndex( index )
        #if module.getIndex() != index: break # Gone too far

        ## Find where we're at
        #verseKey = module.getKey()
        #verseKeyText = verseKey.getShortText()
        ##if '2' in verseKeyText: halt # for debugging first verses
        ##if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
        ##print( '\nvkst={!r} vkix={}'.format( verseKeyText, verseKey.getIndex() ) )

        ##nativeVerseText = module.renderText().decode( self.encoding, 'replace' )
        ##nativeVerseText = str( module.renderText() ) if self.encoding=='utf-8' else str( module.renderText(), encoding=self.encoding )
        ##print( 'getRenderHeader: {} {!r}'.format( len(module.getRenderHeader()), module.getRenderHeader() ) )
        ##print( 'stripText: {} {!r}'.format( len(module.stripText()), module.stripText() ) )
        ##print( 'renderText: {} {!r}'.format( len(str(module.renderText())), str(module.renderText()) ) )
        ##print( 'getRawEntry: {} {!r}'.format( len(module.getRawEntry()), module.getRawEntry() ) )
        #try: nativeVerseText = module.getRawEntry()
        ##try: nativeVerseText = str( module.renderText() )
        #except UnicodeDecodeError: nativeVerseText = ''

        #if ':' not in verseKeyText:
        #if BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.verbosityLevel > 2:
        #print( "Unusual Sword verse key: {} (gave {!r})".format( verseKeyText, nativeVerseText ) )
        #if BibleOrgSysGlobals.debugFlag:
        #assert verseKeyText in ( '[ Module Heading ]', '[ Testament 1 Heading ]', '[ Testament 2 Heading ]', )
        #if BibleOrgSysGlobals.verbosityLevel > 3:
        #if markupCode == FMT_OSIS:
        #match = re.search( '<milestone ([^/>]*?)type="x-importer"([^/>]*?)/>', nativeVerseText )
        #if match:
        #attributes = match.group(1) + match.group(2)
        #match2 = re.search( 'subType="(.+?)"', attributes )
        #subType = match2.group(1) if match2 else None
        #if subType and subType.startswith( 'x-' ): subType = subType[2:] # Remove the x- prefix
        #match2 = re.search( 'n="(.+?)"', attributes )
        #n = match2.group(1) if match2 else None
        #if n: n = n.replace( '$', '' ).strip()
        #print( "Module created by {} {}".format( subType, n ) )
        #continue
        #vkBits = verseKeyText.split()
        #assert len(vkBits) == 2
        #osisBBB = vkBits[0]
        #BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromOSISAbbreviation( osisBBB )
        #if isinstance( BBB, list ): BBB = BBB[0] # We sometimes get a list of options -- take the first = most likely one
        #vkBits = vkBits[1].split( ':' )
        #assert len(vkBits) == 2
        #C, V = vkBits
        ##print( 'At {} {}:{}'.format( BBB, C, V ) )

        ## Start a new book if necessary
        #if BBB != currentBBB:
        #if currentBBB is not None and haveText: # Save the previous book
        #if BibleOrgSysGlobals.verbosityLevel > 3: print( "Saving", currentBBB, bookCount )
        #self.stashBook( thisBook )
        ## Create the new book
        #if BibleOrgSysGlobals.verbosityLevel > 2:  print( '  Loading {} {}…'.format( self.moduleName, BBB ) )
        #thisBook = BibleBook( self, BBB )
        #thisBook.objectNameString = 'Sword Bible Book object'
        #thisBook.objectTypeString = 'Sword Bible'
        #currentBBB, currentC, haveText = BBB, '0', False
        #bookCount += 1

        #if C != currentC:
        #thisBook.addLine( 'c', C )
        ##if C == '2': halt
        #currentC = C

        #if nativeVerseText:
        #haveText = True
        #if markupCode == FMT_OSIS: importOSISVerseLine( nativeVerseText, thisBook, self.moduleName, BBB, C, V )
        #elif markupCode == FMT_GBF: importGBFVerseLine( nativeVerseText, thisBook, self.moduleName, BBB, C, V )
        #elif markupCode == FMT_THML: importTHMLVerseLine( nativeVerseText, thisBook, self.moduleName, BBB, C, V )
        #else:
        #print( 'markupCode', repr(markupCode) )
        #if BibleOrgSysGlobals.debugFlag: halt
        #return

        #if currentBBB is not None and haveText: # Save the very last book
        #if BibleOrgSysGlobals.verbosityLevel > 3: print( "Saving", self.moduleName, currentBBB, bookCount )
        #self.stashBook( thisBook )

        #elif SwordType=='OurCode': # module is already loaded above
        ##print( "moduleConfig =", module.SwordModuleConfiguration )
        #self.books = module.books

        self.doPostLoadProcessing()
Exemple #4
0
class SwordBible( Bible ):
    """
    Class for reading, validating, and converting SwordBible files.
    """
    def __init__( self, sourceFolder=None, moduleName=None, encoding='utf-8' ):
        """
        Constructor: just sets up the Bible object.

        The sourceFolder should be the one containing mods.d and modules folders.
        The module name (if needed) should be the name of one of the .conf files in the mods.d folder
            (with or without the .conf on it).
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print( "SwordBible.__init__( {} {} {} )".format( sourceFolder, moduleName, encoding ) )

        if not sourceFolder and not moduleName:
            logging.critical( _("SwordBible must be passed either a folder path or a module name!" ) )
            return

         # Setup and initialise the base class first
        Bible.__init__( self )
        self.objectNameString = 'Sword Bible object'
        self.objectTypeString = 'Sword'

        # Now we can set our object variables
        self.sourceFolder, self.moduleName, self.encoding = sourceFolder, moduleName, encoding
        self.SwordInterface = None

        if self.sourceFolder:
            # Do a preliminary check on the readability of our folder
            if not os.access( self.sourceFolder, os.R_OK ):
                logging.critical( _("SwordBible: Folder {!r} is unreadable").format( self.sourceFolder ) )

            if not self.moduleName: # If we weren't passed the module name, we need to assume that there's only one
                confFolder = os.path.join( self.sourceFolder, 'mods.d/' )
                foundConfs = []
                for something in os.listdir( confFolder ):
                    somepath = os.path.join( confFolder, something )
                    if os.path.isfile( somepath ) and something.endswith( '.conf' ):
                        foundConfs.append( something[:-5] ) # Drop the .conf bit
                if foundConfs == 0:
                    logging.critical( "No .conf files found in {}".format( confFolder ) )
                elif len(foundConfs) > 1:
                    logging.critical( "Too many .conf files found in {}".format( confFolder ) )
                else:
                    print( "SwordBible.__init__ got", foundConfs[0] )
                    self.moduleName = foundConfs[0]
        self.abbreviation = self.moduleName # First attempt

        # Load the Sword manager and find our module
        if self.SwordInterface is None and SwordType is not None:
            self.SwordInterface = SwordInterface() # Load the Sword library
        if self.SwordInterface is None: # still
            logging.critical( exp("SwordBible: no Sword interface available") )
            return
        #try: self.SWMgr = Sword.SWMgr()
        #except NameError:
            #logging.critical( _("Unable to initialise {!r} module -- no Sword manager available").format( self.moduleName ) )
            #return # our Sword import must have failed
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule and SwordType=='CrosswireLibrary':
            availableGlobalOptions = [str(option) for option in self.SwordInterface.library.getGlobalOptions()]
            print( "availableGlobalOptions", availableGlobalOptions )
        # Don't need to set options if we use getRawEntry() rather than stripText() or renderText()
        #for optionName in ( 'Headings', 'Footnotes', 'Cross-references', "Strong's Numbers", 'Morphological Tags', ):
            #self.SWMgr.setGlobalOption( optionName, 'On' )

        if self.sourceFolder:
            self.SwordInterface.library.augmentModules( self.sourceFolder, False ) # Add our folder to the SW Mgr

        availableModuleCodes = []
        for j,something in enumerate(self.SwordInterface.library.getModules()):
            # something can be a moduleBuffer (Crosswire) or just a string (BOS)
            moduleID = something.getRawData() if SwordType=='CrosswireLibrary' else something

            if moduleID.upper() == self.moduleName.upper(): self.moduleName = moduleID # Get the case correct
            #module = SWMgr.getModule( moduleID )
            #if 0:
                #print( "{} {} ({}) {} {!r}".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) )
                #try: print( "    {} {!r} {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) )
                #except UnicodeDecodeError: print( "   Description is not Unicode!" )
            #print( "moduleID", repr(moduleID) )
            availableModuleCodes.append( moduleID )
        #print( "Available module codes:", availableModuleCodes )

        if self.moduleName not in availableModuleCodes:
            logging.critical( "Unable to find {!r} Sword module".format( self.moduleName ) )
            if BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.verbosityLevel > 2:
                print( "Available module codes:", availableModuleCodes )

        self.abbreviation = self.moduleName # Perhaps a better attempt
    # end of SwordBible.__init__


    def loadBooks( self ):
        """
        Load the compressed data file and import book elements.
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print( exp("SwordBible.load()") )

        if BibleOrgSysGlobals.verbosityLevel > 1:
            print( _("\nLoading {} module…").format( self.moduleName ) )

        self.SwordInterface.loadBooks( self, self.moduleName )

        #try: module = self.SwordInterface.library.getModule( self.moduleName )
        #except AttributeError: # probably no SWMgr
            #logging.critical( _("Unable to load {!r} module -- no Sword loader available").format( self.moduleName ) )
            #return
        #if module is None:
            #logging.critical( _("Unable to load {!r} module -- not known by Sword").format( self.moduleName ) )
            #return

        #if SwordType=='CrosswireLibrary': # need to load the module
            #markupCode = ord( module.getMarkup() )
            #encoding = ord( module.getEncoding() )
            #if encoding == ENC_LATIN1: self.encoding = 'latin-1'
            #elif encoding == ENC_UTF8: self.encoding = 'utf-8'
            #elif encoding == ENC_UTF16: self.encoding = 'utf-16'
            #elif BibleOrgSysGlobals.debugFlag and debuggingThisModule: halt

            #if BibleOrgSysGlobals.verbosityLevel > 3:
                #print( 'Description: {!r}'.format( module.getDescription() ) )
                #print( 'Direction: {!r}'.format( ord(module.getDirection()) ) )
                #print( 'Encoding: {!r}'.format( encoding ) )
                #print( 'Language: {!r}'.format( module.getLanguage() ) )
                #print( 'Markup: {!r}={}'.format( markupCode, FMT_DICT[markupCode] ) )
                #print( 'Name: {!r}'.format( module.getName() ) )
                #print( 'RenderHeader: {!r}'.format( module.getRenderHeader() ) )
                #print( 'Type: {!r}'.format( module.getType() ) )
                #print( 'IsSkipConsecutiveLinks: {!r}'.format( module.isSkipConsecutiveLinks() ) )
                #print( 'IsUnicode: {!r}'.format( module.isUnicode() ) )
                #print( 'IsWritable: {!r}'.format( module.isWritable() ) )
                ##return

            #bookCount = 0
            #currentBBB = None
            #for index in range( 0, 999999 ):
                #module.setIndex( index )
                #if module.getIndex() != index: break # Gone too far

                ## Find where we're at
                #verseKey = module.getKey()
                #verseKeyText = verseKey.getShortText()
                ##if '2' in verseKeyText: halt # for debugging first verses
                ##if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
                    ##print( '\nvkst={!r} vkix={}'.format( verseKeyText, verseKey.getIndex() ) )

                ##nativeVerseText = module.renderText().decode( self.encoding, 'replace' )
                ##nativeVerseText = str( module.renderText() ) if self.encoding=='utf-8' else str( module.renderText(), encoding=self.encoding )
                ##print( 'getRenderHeader: {} {!r}'.format( len(module.getRenderHeader()), module.getRenderHeader() ) )
                ##print( 'stripText: {} {!r}'.format( len(module.stripText()), module.stripText() ) )
                ##print( 'renderText: {} {!r}'.format( len(str(module.renderText())), str(module.renderText()) ) )
                ##print( 'getRawEntry: {} {!r}'.format( len(module.getRawEntry()), module.getRawEntry() ) )
                #try: nativeVerseText = module.getRawEntry()
                ##try: nativeVerseText = str( module.renderText() )
                #except UnicodeDecodeError: nativeVerseText = ''

                #if ':' not in verseKeyText:
                    #if BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.verbosityLevel > 2:
                        #print( "Unusual Sword verse key: {} (gave {!r})".format( verseKeyText, nativeVerseText ) )
                    #if BibleOrgSysGlobals.debugFlag:
                        #assert verseKeyText in ( '[ Module Heading ]', '[ Testament 1 Heading ]', '[ Testament 2 Heading ]', )
                    #if BibleOrgSysGlobals.verbosityLevel > 3:
                        #if markupCode == FMT_OSIS:
                            #match = re.search( '<milestone ([^/>]*?)type="x-importer"([^/>]*?)/>', nativeVerseText )
                            #if match:
                                #attributes = match.group(1) + match.group(2)
                                #match2 = re.search( 'subType="(.+?)"', attributes )
                                #subType = match2.group(1) if match2 else None
                                #if subType and subType.startswith( 'x-' ): subType = subType[2:] # Remove the x- prefix
                                #match2 = re.search( 'n="(.+?)"', attributes )
                                #n = match2.group(1) if match2 else None
                                #if n: n = n.replace( '$', '' ).strip()
                                #print( "Module created by {} {}".format( subType, n ) )
                    #continue
                #vkBits = verseKeyText.split()
                #assert len(vkBits) == 2
                #osisBBB = vkBits[0]
                #BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromOSIS( osisBBB )
                #if isinstance( BBB, list ): BBB = BBB[0] # We sometimes get a list of options -- take the first = most likely one
                #vkBits = vkBits[1].split( ':' )
                #assert len(vkBits) == 2
                #C, V = vkBits
                ##print( 'At {} {}:{}'.format( BBB, C, V ) )

                ## Start a new book if necessary
                #if BBB != currentBBB:
                    #if currentBBB is not None and haveText: # Save the previous book
                        #if BibleOrgSysGlobals.verbosityLevel > 3: print( "Saving", currentBBB, bookCount )
                        #self.stashBook( thisBook )
                    ## Create the new book
                    #if BibleOrgSysGlobals.verbosityLevel > 2:  print( '  Loading {} {}…'.format( self.moduleName, BBB ) )
                    #thisBook = BibleBook( self, BBB )
                    #thisBook.objectNameString = 'Sword Bible Book object'
                    #thisBook.objectTypeString = 'Sword Bible'
                    #currentBBB, currentC, haveText = BBB, '0', False
                    #bookCount += 1

                #if C != currentC:
                    #thisBook.addLine( 'c', C )
                    ##if C == '2': halt
                    #currentC = C

                #if nativeVerseText:
                    #haveText = True
                    #if markupCode == FMT_OSIS: importOSISVerseLine( nativeVerseText, thisBook, self.moduleName, BBB, C, V )
                    #elif markupCode == FMT_GBF: importGBFVerseLine( nativeVerseText, thisBook, self.moduleName, BBB, C, V )
                    #elif markupCode == FMT_THML: importTHMLVerseLine( nativeVerseText, thisBook, self.moduleName, BBB, C, V )
                    #else:
                        #print( 'markupCode', repr(markupCode) )
                        #if BibleOrgSysGlobals.debugFlag: halt
                        #return

            #if currentBBB is not None and haveText: # Save the very last book
                #if BibleOrgSysGlobals.verbosityLevel > 3: print( "Saving", self.moduleName, currentBBB, bookCount )
                #self.stashBook( thisBook )


        #elif SwordType=='OurCode': # module is already loaded above
            ##print( "moduleConfig =", module.SwordModuleConfiguration )
            #self.books = module.books

        self.doPostLoadProcessing()