示例#1
0
    def __init__(self, sourceFolder, givenName, encoding='utf-8'):
        """
        Constructor: just sets up the VerseView Bible object.
        """
        # Setup and initialise the base class first
        Bible.__init__(self)
        self.objectNameString = 'VerseView XML Bible object'
        self.objectTypeString = 'VerseView'

        # Now we can set our object variables
        self.sourceFolder, self.givenName, self.encoding = sourceFolder, givenName, encoding
        self.sourceFilepath = os.path.join(self.sourceFolder, self.givenName)

        self.XMLTree = self.header = None  # Will hold the XML data

        # Get the data tables that we need for proper checking
        #self.ISOLanguages = ISO_639_3_Languages().loadData()
        self.genericBOS = BibleOrganisationalSystem('GENERIC-KJV-66-ENG')

        # Do a preliminary check on the readability of our file
        if not os.access(self.sourceFilepath, os.R_OK):
            vPrint(
                'Quiet', debuggingThisModule,
                "VerseViewXMLBible: File {!r} is unreadable".format(
                    self.sourceFilepath))

        self.name = self.givenName
示例#2
0
    def __init__(self, sourceFileOrFolder, givenName=None) -> None:
        """
        Constructor: just sets up the Bible object.
        """
        fnPrint(debuggingThisModule,
                f"GoBible.__init__( '{sourceFileOrFolder}', {givenName!r} )")

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

        # Now we can set our object variables
        self.sourceFileOrFolder, self.givenName = sourceFileOrFolder, givenName
        if sourceFileOrFolder.endswith(GOBIBLE_FILENAME_END):
            assert os.path.isfile(sourceFileOrFolder)
            self.sourceFilepath = sourceFileOrFolder
            self.sourceFolder = os.path.dirname(sourceFileOrFolder)
        else:  # assume it's a folder
            assert os.path.isdir(sourceFileOrFolder)
            self.sourceFolder = sourceFileOrFolder
            self.sourceFilepath = os.path.join(
                self.sourceFolder, self.givenName + GOBIBLE_FILENAME_END)

        # Do a preliminary check on the readability of our file
        if not os.access(self.sourceFilepath, os.R_OK):
            logging.critical(
                _("GoBible: File '{}' is unreadable").format(
                    self.sourceFilepath))

        self.name = self.givenName
示例#3
0
    def __init__(self, sourceFolder, givenName, encoding='utf-8') -> None:
        """
        Constructor: just sets up the Bible object.
        """
        fnPrint(
            debuggingThisModule,
            _("DrupalBible__init__ ( {!r}, {!r}, {!r} )").format(
                sourceFolder, givenName, encoding))
        assert sourceFolder
        assert givenName

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

        # Now we can set our object variables
        self.sourceFolder, self.givenName, self.encoding = sourceFolder, givenName, encoding
        self.sourceFilepath = os.path.join(self.sourceFolder,
                                           self.givenName + '.bc')

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

        self.name = self.givenName
示例#4
0
    def __init__(self,
                 sourceFolder,
                 givenName: Optional[str] = None,
                 givenAbbreviation: Optional[str] = None,
                 encoding: Optional[str] = None) -> None:
        """
        Create the internal uW OBS Bible object.

        Note that sourceFolder can be None if we don't know that yet.
        """
        # Setup and initialise the base class first
        Bible.__init__(self)
        self.objectNameString = 'uW OBS Bible object'
        self.objectTypeString = 'uW OBS'

        # Now we can set our object variables
        self.sourceFolder, self.givenName, self.abbreviation, self.encoding = sourceFolder, givenName, givenAbbreviation, encoding
示例#5
0
    def __init__( self, sourceFolder, givenName, encoding='utf-8' ):
        """
        Constructor: just sets up the Bible object.
        """
         # Setup and initialise the base class first
        Bible.__init__( self )
        self.objectNameString = 'VPL Bible object'
        self.objectTypeString = 'VPL'

        # Now we can set our object variables
        self.sourceFolder, self.givenName, self.encoding = sourceFolder, givenName, encoding
        self.sourceFilepath =  os.path.join( self.sourceFolder, self.givenName+'.txt' )

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

        self.name = self.givenName
示例#6
0
    def __init__(self, sourceFilepath, givenName=None, encoding='utf-8'):
        """
        Constructor: expects the filepath of the source folder.
        Loads (and crudely validates the file(s)) into ???.
        """
        # Setup and initialise the base class first
        Bible.__init__(self)
        self.objectNameString = 'Greek NT Bible object'
        self.objectTypeString = 'GreekNT'

        # Now we can set our object variables
        self.sourceFilepath, self.givenName, self.encoding = sourceFilepath, givenName, encoding

        self.title = self.version = self.date = None
        self.XMLTree = self.header = self.frontMatter = self.divs = self.divTypesString = None
        #self.bkData, self.USFMBooks = {}, {}
        self.lang = self.language = None

        # Do a preliminary check on the readability of our files
        self.possibleFilenames = []
        if os.path.isdir(
                self.sourceFilepath
        ):  # We've been given a folder -- see if we can find the files
            # There's no standard for OSIS xml file naming
            fileList = os.listdir(self.sourceFilepath)
            #vPrint( 'Quiet', debuggingThisModule, len(fileList), fileList )
            # First try looking for OSIS book names
            for filename in fileList:
                if filename.lower().endswith('.txt'):
                    thisFilepath = os.path.join(self.sourceFilepath, filename)
                    #if BibleOrgSysGlobals.debugFlag: vPrint( 'Quiet', debuggingThisModule, "Trying {}…".format( thisFilepath ) )
                    if os.access(thisFilepath,
                                 os.R_OK):  # we can read that file
                        self.possibleFilenames.append(filename)
        elif not os.access(self.sourceFilepath, os.R_OK):
            logging.critical("GreekNT: File {!r} is unreadable".format(
                self.sourceFilepath))
            return  # No use continuing
        #vPrint( 'Quiet', debuggingThisModule, self.possibleFilenames ); halt

        self.name = self.givenName
示例#7
0
    def __init__(self, sourceFolder, givenFilename, encoding='utf-8') -> None:
        """
        Constructor: just sets up the Bible object.
        """
        # Setup and initialise the base class first
        Bible.__init__(self)
        self.objectNameString = 'MySword Bible object'
        self.objectTypeString = 'MySword'

        # Now we can set our object variables
        self.sourceFolder, self.sourceFilename, self.encoding = sourceFolder, givenFilename, encoding
        self.sourceFilepath = os.path.join(self.sourceFolder,
                                           self.sourceFilename)

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

        filenameBits = os.path.splitext(self.sourceFilename)
        self.name = filenameBits[0]
        self.fileExtension = filenameBits[1]
示例#8
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).
        """
        vPrint( 'Never', debuggingThisModule, f"SwordBible.__init__( {sourceFolder} {moduleName} {encoding} ) for '{SwordResources.SwordType}'" )

        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 SwordResources.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:
                        vPrint( 'Quiet', debuggingThisModule, "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 SwordResources.SwordType is not None:
            self.SwordInterface = SwordResources.SwordInterface() # Load the Sword library
        if self.SwordInterface is None: # still
            logging.critical( _("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 SwordResources.SwordType=='CrosswireLibrary':
            availableGlobalOptions = [str(option) for option in self.SwordInterface.library.getGlobalOptions()]
            vPrint( 'Quiet', debuggingThisModule, "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( str(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 SwordResources.SwordType == 'CrosswireLibrary':
                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:
                #vPrint( 'Quiet', debuggingThisModule, "{} {} ({}) {} {!r}".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) )
                #try: vPrint( 'Quiet', debuggingThisModule, "    {} {!r} {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) )
                #except UnicodeDecodeError: vPrint( 'Quiet', debuggingThisModule, "   Description is not Unicode!" )
            #vPrint( 'Quiet', debuggingThisModule, "moduleID", repr(moduleID) )
            availableModuleCodes.append( moduleID )
        #vPrint( 'Quiet', debuggingThisModule, "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:
                vPrint( 'Quiet', debuggingThisModule, "Available module codes:", availableModuleCodes )

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