当前位置: 首页>>代码示例>>Python>>正文


Python BibleOrgSysGlobals.backupAnyExistingFile方法代码示例

本文整理汇总了Python中BibleOrgSysGlobals.backupAnyExistingFile方法的典型用法代码示例。如果您正苦于以下问题:Python BibleOrgSysGlobals.backupAnyExistingFile方法的具体用法?Python BibleOrgSysGlobals.backupAnyExistingFile怎么用?Python BibleOrgSysGlobals.backupAnyExistingFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BibleOrgSysGlobals的用法示例。


在下文中一共展示了BibleOrgSysGlobals.backupAnyExistingFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: saveAnyChangedGlosses

# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import backupAnyExistingFile [as 别名]
    def saveAnyChangedGlosses( self, exportAlso=False ):
        """
        Save the glossing dictionary to a pickle file.
        """
        if debuggingThisModule: print( "saveAnyChangedGlosses()" )

        if self.haveGlossingDictChanges:
            BibleOrgSysGlobals.backupAnyExistingFile( self.glossingDictFilepath, 9 )
            if BibleOrgSysGlobals.verbosityLevel > 2 or debuggingThisModule:
                print( "  Saving Hebrew glossing dictionary ({}->{} entries) to '{}'…".format( self.loadedGlossEntryCount, len(self.glossingDict), self.glossingDictFilepath ) )
            elif BibleOrgSysGlobals.verbosityLevel > 1:
                print( "  Saving Hebrew glossing dictionary ({}->{} entries)…".format( self.loadedGlossEntryCount, len(self.glossingDict) ) )
            with open( self.glossingDictFilepath, 'wb' ) as pickleFile:
                pickle.dump( self.glossingDict, pickleFile )

            if exportAlso: self.exportGlossingDictionary()
开发者ID:openscriptures,项目名称:BibleOrgSys,代码行数:18,代码来源:HebrewWLCBible.py

示例2: save

# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import backupAnyExistingFile [as 别名]
    def save( self ):
        """
        Save all of the program settings to disk.
            They must have already been saved into self.data.
        """
        if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
            print( exp("ApplicationSettings.save() in {!r}").format( self.settingsFilepath ) )
            assert self.data
            assert self.settingsFilepath

        BibleOrgSysGlobals.backupAnyExistingFile( self.settingsFilepath, numBackups=8 )
        with open( self.settingsFilepath, 'wt', encoding='utf-8' ) as settingsFile: # It may or may not have previously existed
            # Put a (comment) heading in the file first
            settingsFile.write( '# ' + _("{} {} settings file").format( APP_NAME, SettingsVersion ) + '\n' )
            settingsFile.write( '# ' + _("Originally saved {} as {}") \
                .format( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), self.settingsFilepath ) + '\n\n' )

            self.data.write( settingsFile )
开发者ID:openscriptures,项目名称:Biblelator,代码行数:20,代码来源:Settings.py

示例3: exportGlossingDictionary

# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import backupAnyExistingFile [as 别名]
    def exportGlossingDictionary( self, glossingDictExportFilepath=None ):
        """
        Export the glossing dictionary to a text file
            plus a reversed text file (without the references).

        Also does a few checks while exporting.
            (These can be fixed and then the file can be imported.)
        """
        #print( "exportGlossingDictionary()" )
        if glossingDictExportFilepath is None: glossingDictExportFilepath = DEFAULT_GLOSSING_EXPORT_FILEPATH
        if BibleOrgSysGlobals.verbosityLevel > 1:
            print( _("Exporting glossing dictionary ({} entries) to '{}'…").format( len(self.glossingDict), glossingDictExportFilepath ) )

        BibleOrgSysGlobals.backupAnyExistingFile( glossingDictExportFilepath, 5 )
        with open( glossingDictExportFilepath, 'wt' ) as exportFile:
            for word,(genericGloss,genericReferencesList,specificReferencesDict) in self.glossingDict.items():
                if ' ' in word or '/' in word:
                    logging.error( _("Word {!r} has illegal characters").format( word ) )
                if ' ' in genericGloss:
                    logging.error( _("Generic gloss {!r} for {!r} has illegal characters").format( genericGloss, word ) )
                if word.count('=') != genericGloss.count('='):
                    logging.error( _("Generic gloss {!r} and word {!r} has different numbers of morphemes").format( genericGloss, word ) )
                if not genericReferencesList:
                    logging.error( _("Generic gloss {!r} for {!r} has no references").format( genericGloss, word ) )
                exportFile.write( '{}  {}  {}  {}\n'.format( genericReferencesList, specificReferencesDict, genericGloss, word ) ) # Works best in editors with English on the left, Hebrew on the right

        if self.glossingDict:
            if BibleOrgSysGlobals.verbosityLevel > 1:
                print( _("Exporting reverse glossing dictionary ({} entries) to '{}'…").format( len(self.glossingDict), DEFAULT_GENERIC_GLOSSING_REVERSE_EXPORT_FILEPATH ) )
            BibleOrgSysGlobals.backupAnyExistingFile( DEFAULT_GENERIC_GLOSSING_REVERSE_EXPORT_FILEPATH, 5 )
            doneGlosses = []
            with open( DEFAULT_GENERIC_GLOSSING_REVERSE_EXPORT_FILEPATH, 'wt' ) as exportFile:
                for word,(genericGloss,genericReferencesList,specificReferencesDict) in sorted( self.glossingDict.items(), key=lambda theTuple: theTuple[1][0].lower() ):
                    if genericGloss in doneGlosses:
                        logging.warning( _("Generic gloss {!r} has already appeared: currently for word {!r}").format( genericGloss, word ) )
                    exportFile.write( '{}  {}\n'.format( genericGloss, word ) ) # Works best in editors with English on the left, Hebrew on the right
                    doneGlosses.append( genericGloss )
开发者ID:openscriptures,项目名称:BibleOrgSys,代码行数:39,代码来源:HebrewWLCBible.py

示例4: searchReplaceText

# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import backupAnyExistingFile [as 别名]

#.........这里部分代码省略.........
                            willBeText = contextBefore + regexReplacementText + contextAfter
                            result = confirmCallback( ref, contextBefore, regexFoundText, contextAfter, willBeText, resultDict['numReplaces']>0 )
                            #print( "searchReplaceText got", result )
                            assert result in 'YNASU'
                            if result == 'A': replaceAllFlag = True
                            elif result == 'S': stopFlag = True; break
                            elif result == 'U': undoFlag = True; break
                        if replaceAllFlag or result == 'Y':
                            #print( "  ix={:,}, ixAfter={:,}, diffLen={}".format( ix, ixAfter, diffLen ) )
                            bookText = bookText[:ix] + regexReplacementText + bookText[ixAfter:]
                            ix += len( regexReplacementText ) # Start searching after the replacement
                            #print( "  ix={:,}, ixAfter={:,}, now={!r}".format( ix, ixAfter, bookText ) )
                            resultDict['numReplaces'] += 1
                            if BBB not in resultDict['replacedBookList']: resultDict['replacedBookList'].append( BBB )
                            filesToSave[BBB] = (bookFilepath,bookText)
                        else: ix += 1 # So don't keep repeating the same find
                else: # not regExp
                    ix = 0
                    while True:
                        ix = bookText.find( ourSearchText, ix )
                        if ix == -1: break # none / no more found
                        #print( "Found {!r} at {:,} in {}".format( ourSearchText, ix, BBB ) )
                        resultDict['numFinds'] += 1
                        if BBB not in resultDict['foundBookList']: resultDict['foundBookList'].append( BBB )

                        ixAfter = ix + searchLen
                        if optionsDict['wordMode'] == 'Whole':
                            #print( "BF", repr(bookText[ix-1]) )
                            #print( "AF", repr(bookText[ixAfter]) )
                            if ix>0 and bookText[ix-1].isalpha(): ix+=1; continue
                            if ixAfter<len(bookText) and bookText[ixAfter].isalpha(): ix+=1; continue
                        elif optionsDict['wordMode'] == 'Begins':
                            if ix>0 and bookText[ix-1].isalpha(): ix+=1; continue
                        elif optionsDict['wordMode'] == 'EndsWord':
                            if ixAfter<len(bookText) and bookText[ixAfter].isalpha(): ix+=1; continue
                        elif optionsDict['wordMode'] == 'EndsLine':
                            if ixAfter<len(bookText): ix+=1; continue

                        if optionsDict['contextLength']: # Find the context in the original (fully-cased) string
                            contextBefore = bookText[max(0,ix-optionsDict['contextLength']):ix]
                            contextAfter = bookText[ixAfter:ixAfter+optionsDict['contextLength']]
                        else: contextBefore = contextAfter = None
                        #print( "  After  {!r}".format( contextBefore ) )
                        #print( "  Before {!r}".format( contextAfter ) )

                        result = None
                        if not replaceAllFlag:
                            ref = BBB
                            willBeText = contextBefore + ourReplaceText + contextAfter
                            result = confirmCallback( ref, contextBefore, ourSearchText, contextAfter, willBeText, resultDict['numReplaces']>0 )
                            #print( "searchReplaceText got", result )
                            assert result in 'YNASU'
                            if result == 'A': replaceAllFlag = True
                            elif result == 'S': stopFlag = True; break
                            elif result == 'U': undoFlag = True; break
                        if replaceAllFlag or result == 'Y':
                            #print( "  ix={:,}, ixAfter={:,}, diffLen={}".format( ix, ixAfter, diffLen ) )
                            bookText = bookText[:ix] + ourReplaceText + bookText[ixAfter:]
                            ix += replaceLen # Start searching after the replacement
                            #print( "  ix={:,}, ixAfter={:,}, now={!r}".format( ix, ixAfter, bookText ) )
                            resultDict['numReplaces'] += 1
                            if BBB not in resultDict['replacedBookList']: resultDict['replacedBookList'].append( BBB )
                            filesToSave[BBB] = (bookFilepath,bookText)
                        else: ix += 1 # So don't keep repeating the same find

            if stopFlag:
                if BibleOrgSysGlobals.verbosityLevel > 2:
                    print( "Search/Replace was aborted in {} after {} replaces.".format( BBB, resultDict['numReplaces'] ) )
                resultDict['aborted'] = True
                break
            if undoFlag:
                if resultDict['numReplaces']>0:
                    if BibleOrgSysGlobals.verbosityLevel > 2:
                        print( "Search/Replace was aborted in {} for undo in {} books.".format( BBB, len(resultDict['replacedBookList']) ) )
                elif BibleOrgSysGlobals.verbosityLevel > 2:
                    print( "Search/Replace was aborted (by undo) in {}.".format( BBB ) )
                filesToSave = {}
                resultDict['replacedBookList'] = []
                resultDict['numReplaces'] = 0
                resultDict['aborted'] = True
                break

    else:
        logging.critical( exp("No book files to search/replace in {}!").format( self.sourceFolder ) )

    for BBB,(filepath,fileText) in filesToSave.items():
        if optionsDict['doBackups']:
            if BibleOrgSysGlobals.verbosityLevel > 2:
                print( "Making backup copy of {} file: {}…".format( BBB, filepath ) )
            BibleOrgSysGlobals.backupAnyExistingFile( filepath, numBackups=4 )
        if BibleOrgSysGlobals.verbosityLevel > 2:
            print( "Writing {:,} bytes for {} to {}…".format( len(fileText), BBB, filepath ) )
        elif BibleOrgSysGlobals.verbosityLevel > 1:
            print( "Saving {} with {} encoding".format( filepath, encoding ) )
        with open( filepath, 'wt', encoding=encoding, newline='\r\n' ) as bookFile:
            bookFile.write( fileText )
        self.bookNeedsReloading[BBB] = True

    #print( exp("searchReplaceText: returning {}/{}  {}/{}/{} books  {}").format( resultDict['numReplaces'], resultDict['numFinds'], len(resultDict['replacedBookList']), len(resultDict['foundBookList']), len(resultDict['searchedBookList']), optionsDict ) )
    return optionsDict, resultDict
开发者ID:,项目名称:,代码行数:104,代码来源:


注:本文中的BibleOrgSysGlobals.backupAnyExistingFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。