예제 #1
0
    def preload( self ):
        """
        """
        if BibleOrgSysGlobals.debugFlag or debuggingThisModule or BibleOrgSysGlobals.verbosityLevel > 2:
            print( t("preload() from {}").format( self.sourceFolder ) )

        # Do a preliminary check on the contents of our folder
        foundFiles, foundFolders = [], []
        for something in os.listdir( self.sourceFolder ):
            somepath = os.path.join( self.sourceFolder, something )
            if os.path.isdir( somepath ): foundFolders.append( something )
            elif os.path.isfile( somepath ): foundFiles.append( something )
            else: logging.error( "Not sure what {!r} is in {}!".format( somepath, self.sourceFolder ) )
        if foundFolders:
            unexpectedFolders = []
            for folderName in foundFolders:
                if folderName.startswith( 'Interlinear_'): continue
                if folderName in ('__MACOSX'): continue
                unexpectedFolders.append( folderName )
            if unexpectedFolders:
                logging.info( "ESFMBible.load: Surprised to see subfolders in {!r}: {}".format( self.sourceFolder, unexpectedFolders ) )
        if not foundFiles:
            if BibleOrgSysGlobals.verbosityLevel > 0: print( "ESFMBible: Couldn't find any files in {!r}".format( self.sourceFolder ) )
            return # No use continuing

        self.USFMFilenamesObject = USFMFilenames( self.sourceFolder )
        if BibleOrgSysGlobals.verbosityLevel > 3 or (BibleOrgSysGlobals.debugFlag and debuggingThisModule):
            print( self.USFMFilenamesObject )

        if self.suppliedMetadata is None: self.suppliedMetadata = {}

        # Attempt to load the SSF file
        self.ssfFilepath = None
        ssfFilepathList = self.USFMFilenamesObject.getSSFFilenames( searchAbove=True, auto=True )
        if len(ssfFilepathList) == 1: # Seems we found the right one
            self.ssfFilepath = ssfFilepathList[0]
            PTXSettingsDict = loadPTX7ProjectData( self, self.ssfFilepath )
            if PTXSettingsDict:
                if 'PTX7' not in self.suppliedMetadata: self.suppliedMetadata['PTX7'] = {}
                self.suppliedMetadata['PTX7']['SSF'] = PTXSettingsDict
                self.applySuppliedMetadata( 'SSF' ) # Copy some to BibleObject.settingsDict

        #self.name = self.givenName
        #if self.name is None:
            #for field in ('FullName','Name',):
                #if field in self.settingsDict: self.name = self.settingsDict[field]; break
        #if not self.name: self.name = os.path.basename( self.sourceFolder )
        #if not self.name: self.name = os.path.basename( self.sourceFolder[:-1] ) # Remove the final slash
        #if not self.name: self.name = "ESFM Bible"

        # Find the filenames of all our books
        self.maximumPossibleFilenameTuples = self.USFMFilenamesObject.getMaximumPossibleFilenameTuples() # Returns (BBB,filename) 2-tuples
        self.possibleFilenameDict = {}
        for BBB, filename in self.maximumPossibleFilenameTuples:
            self.availableBBBs.add( BBB )
            self.possibleFilenameDict[BBB] = filename

        self.preloadDone = True
예제 #2
0
    def preload( self ):
        """
        Tries to determine USX filename pattern.
        """
        if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel > 2:
            print( exp("preload() from {}").format( self.sourceFolder ) )

        # Do a preliminary check on the readability of our folder
        if not os.access( self.givenFolderName, os.R_OK ):
            logging.error( "USXXMLBible: File {!r} is unreadable".format( self.givenFolderName ) )

        # Find the filenames of all our books
        self.USXFilenamesObject = USXFilenames( self.givenFolderName )
        #print( "DDFSDF", self.USXFilenamesObject )
        #print( "DFSFGE", self.USXFilenamesObject.getPossibleFilenameTuples() )
        #print( "SDFSDQ", self.USXFilenamesObject.getConfirmedFilenameTuples() )
        self.possibleFilenameDict = OrderedDict()
        filenameTuples = self.USXFilenamesObject.getConfirmedFilenameTuples()
        if not filenameTuples: # Try again
            filenameTuples = self.USXFilenamesObject.getPossibleFilenameTuples()
        for BBB,filename in filenameTuples:
            self.possibleFilenameDict[BBB] = filename
        #print( "GHJGHR", self.possibleFilenameDict ); halt

        if 0: # we don't have a getSSFFilenames function :(
            if self.suppliedMetadata is None: self.suppliedMetadata = {}
            if self.ssfFilepath is None: # it might have been loaded first
                # Attempt to load the SSF file
                #self.suppliedMetadata, self.settingsDict = {}, {}
                ssfFilepathList = self.USXFilenamesObject.getSSFFilenames( searchAbove=True, auto=True )
                #print( "ssfFilepathList", ssfFilepathList )
                if len(ssfFilepathList) > 1:
                    logging.error( exp("preload: Found multiple possible SSF files -- using first one: {}").format( ssfFilepathList ) )
                if len(ssfFilepathList) >= 1: # Seems we found the right one
                    PTXSettingsDict = loadPTX7ProjectData( self, ssfFilepathList[0] )
                    if PTXSettingsDict:
                        if 'PTX' not in self.suppliedMetadata: self.suppliedMetadata['PTX'] = {}
                        self.suppliedMetadata['PTX']['SSF'] = PTXSettingsDict
                        self.applySuppliedMetadata( 'SSF' ) # Copy some to BibleObject.settingsDict

        #self.name = self.givenName
        #if self.name is None:
            #for field in ('FullName','Name',):
                #if field in self.settingsDict: self.name = self.settingsDict[field]; break
        #if not self.name: self.name = os.path.basename( self.sourceFolder )
        #if not self.name: self.name = os.path.basename( self.sourceFolder[:-1] ) # Remove the final slash
        #if not self.name: self.name = "USFM Bible"

        self.preloadDone = True
예제 #3
0
    def preload(self):
        """
        """
        if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel > 2:
            print(t("preload() from {}").format(self.sourceFolder))

        # Do a preliminary check on the contents of our folder
        foundFiles, foundFolders = [], []
        for something in os.listdir(self.sourceFolder):
            somepath = os.path.join(self.sourceFolder, something)
            if os.path.isdir(somepath): foundFolders.append(something)
            elif os.path.isfile(somepath): foundFiles.append(something)
            else:
                logging.error("Not sure what {!r} is in {}!".format(
                    somepath, self.sourceFolder))
        if foundFolders:
            unexpectedFolders = []
            for folderName in foundFolders:
                if folderName.startswith('Interlinear_'): continue
                if folderName in ('__MACOSX'): continue
                unexpectedFolders.append(folderName)
            if unexpectedFolders:
                logging.info(
                    "ESFMBible.load: Surprised to see subfolders in {!r}: {}".
                    format(self.sourceFolder, unexpectedFolders))
        if not foundFiles:
            if BibleOrgSysGlobals.verbosityLevel > 0:
                print("ESFMBible: Couldn't find any files in {!r}".format(
                    self.sourceFolder))
            return  # No use continuing

        self.USFMFilenamesObject = USFMFilenames(self.sourceFolder)
        if BibleOrgSysGlobals.verbosityLevel > 3 or (
                BibleOrgSysGlobals.debugFlag and debuggingThisModule):
            print(self.USFMFilenamesObject)

        if self.suppliedMetadata is None: self.suppliedMetadata = {}

        # Attempt to load the SSF file
        self.ssfFilepath = None
        ssfFilepathList = self.USFMFilenamesObject.getSSFFilenames(
            searchAbove=True, auto=True)
        if len(ssfFilepathList) == 1:  # Seems we found the right one
            self.ssfFilepath = ssfFilepathList[0]
            PTXSettingsDict = loadPTX7ProjectData(self, self.ssfFilepath)
            if PTXSettingsDict:
                if 'PTX7' not in self.suppliedMetadata:
                    self.suppliedMetadata['PTX7'] = {}
                self.suppliedMetadata['PTX7']['SSF'] = PTXSettingsDict
                self.applySuppliedMetadata(
                    'SSF')  # Copy some to BibleObject.settingsDict

        #self.name = self.givenName
        #if self.name is None:
        #for field in ('FullName','Name',):
        #if field in self.settingsDict: self.name = self.settingsDict[field]; break
        #if not self.name: self.name = os.path.basename( self.sourceFolder )
        #if not self.name: self.name = os.path.basename( self.sourceFolder[:-1] ) # Remove the final slash
        #if not self.name: self.name = "ESFM Bible"

        # Find the filenames of all our books
        self.maximumPossibleFilenameTuples = self.USFMFilenamesObject.getMaximumPossibleFilenameTuples(
        )  # Returns (BBB,filename) 2-tuples
        self.possibleFilenameDict = {}
        for BBB, filename in self.maximumPossibleFilenameTuples:
            self.availableBBBs.add(BBB)
            self.possibleFilenameDict[BBB] = filename

        self.preloadDone = True
예제 #4
0
    def preload( self ):
        """
        Loads the SSF file if it can be found.
        Tries to determine USFM filename pattern.
        """
        if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel > 2:
            print( exp("preload() from {}").format( self.sourceFolder ) )
            assert not self.preloadDone
            assert self.sourceFolder is not None

        # Do a preliminary check on the contents of our folder
        foundFiles, foundFolders = [], []
        for something in os.listdir( self.sourceFolder ):
            #print( repr(something) )
            somepath = os.path.join( self.sourceFolder, something )
            if os.path.isdir( somepath ): foundFolders.append( something )
            elif os.path.isfile( somepath ): foundFiles.append( something )
            else: logging.error( exp("preload: Not sure what {!r} is in {}!").format( somepath, self.sourceFolder ) )
        if foundFolders:
            unexpectedFolders = []
            for folderName in foundFolders:
                if folderName.startswith( 'Interlinear_'): continue
                if folderName in ('__MACOSX',): continue
                unexpectedFolders.append( folderName )
            if unexpectedFolders:
                logging.info( exp("preload: Surprised to see subfolders in {!r}: {}").format( self.sourceFolder, unexpectedFolders ) )
        if not foundFiles:
            if BibleOrgSysGlobals.verbosityLevel > 0: print( exp("preload: Couldn't find any files in {!r}").format( self.sourceFolder ) )
            raise FileNotFoundError # No use continuing

        self.USFMFilenamesObject = USFMFilenames( self.sourceFolder )
        if BibleOrgSysGlobals.verbosityLevel > 3 or (BibleOrgSysGlobals.debugFlag and debuggingThisModule):
            print( "USFMFilenamesObject", self.USFMFilenamesObject )

        if self.suppliedMetadata is None: self.suppliedMetadata = {}
        if self.ssfFilepath is None: # it might have been loaded first
            # Attempt to load the SSF file
            #self.suppliedMetadata, self.settingsDict = {}, {}
            ssfFilepathList = self.USFMFilenamesObject.getSSFFilenames( searchAbove=True, auto=True )
            #print( "ssfFilepathList", ssfFilepathList )
            if len(ssfFilepathList) > 1:
                logging.error( exp("preload: Found multiple possible SSF files -- using first one: {}").format( ssfFilepathList ) )
            if len(ssfFilepathList) >= 1: # Seems we found the right one
                from PTX7Bible import loadPTX7ProjectData
                PTXSettingsDict = loadPTX7ProjectData( self, ssfFilepathList[0] )
                if PTXSettingsDict:
                    if self.suppliedMetadata is None: self.suppliedMetadata = {}
                    if 'PTX' not in self.suppliedMetadata: self.suppliedMetadata['PTX'] = {}
                    self.suppliedMetadata['PTX']['SSF'] = PTXSettingsDict
                    self.applySuppliedMetadata( 'SSF' ) # Copy some to BibleObject.settingsDict

        #self.name = self.givenName
        #if self.name is None:
            #for field in ('FullName','Name',):
                #if field in self.settingsDict: self.name = self.settingsDict[field]; break
        #if not self.name: self.name = os.path.basename( self.sourceFolder )
        #if not self.name: self.name = os.path.basename( self.sourceFolder[:-1] ) # Remove the final slash
        #if not self.name: self.name = "USFM Bible"

        # Find the filenames of all our books
        self.maximumPossibleFilenameTuples = self.USFMFilenamesObject.getMaximumPossibleFilenameTuples() # Returns (BBB,filename) 2-tuples
        self.possibleFilenameDict = {}
        for BBB, filename in self.maximumPossibleFilenameTuples:
            self.possibleFilenameDict[BBB] = filename

        self.preloadDone = True