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


Python Version.copy方法代码示例

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


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

示例1: __init__

# 需要导入模块: from version import Version [as 别名]
# 或者: from version.Version import copy [as 别名]
class File:
    def __init__(self, fileName, numEdits, fileSize, lastEdited):
        self.fileName = fileName
        self.localVersion = Version(fileName, numEdits, fileSize, lastEdited)
        self.latestVersion = self.localVersion.copy()

        self.numChunksOwned = 0
        self.chunksOwned = [False] * self.localVersion.numChunks
        self.state = ""
        self.readCounter = 0
        self.isDeleted = False

    def ownAllChunks(self):
        numChunks = self.localVersion.numChunks
        self.chunksOwned = [True] * numChunks
        self.numChunksOwned = numChunks

    def ownNoChunks(self):
        numChunks = self.localVersion.numChunks
        self.chunksOwned = [False] * numChunks
        self.numChunksOwned = 0

    def existsLocally(self):
        return self.localVersion.numChunks == self.numChunksOwned

    def receiveChunk(self, chunkIndex):
        if self.chunksOwned[chunkIndex]:
            self.log_.w(self.fileName + ' received chunk ' + chunkIndex + ', but it was already owned!')
            return
        self.chunksOwned[chunkIndex] = True
        self.numChunksOwned += 1

    def setNewVersion(self, version):
        self.localVersion = version.copy()
        self.latestVersion = version.copy()
        self.ownNoChunks()

    def setLocalVersion(self, numEdits, fileSize, lastEdited):
        self.localVersion = Version(self.fileName, numEdits, fileSize, lastEdited)

    def getLocalVersion(self):
        return self.localVersion

    def getLatestVersion(self):
        return self.latestVersion

    def hasLocalChanges(self):
        return self.localVersion.numEdits > self.latestVersion.numEdits

    def isOutOfDate(self, otherFile=None):
        if otherFile:
            if self.latestVersion.numEdits < otherFile.latestVersion.numEdits:
                return True
            elif self.latestVersion.numEdits == otherFile.latestVersion.numEdits and self.latestVersion != otherFile.latestVersion:
                # This is a rare race condition. We will loose data here, but it shouldn't happen often.
                return self.latestVersion.lastEdited < otherFile.latestVersion.lastEdited
            else:
                return False
        return self.localVersion.numEdits < self.latestVersion.numEdits

    def __str__(self):
        flags = []
        if self.isOutOfDate():
            flags.append('Obsolete')
        elif self.hasLocalChanges():
            flags.append('Local Uncomitted')
        elif self.existsLocally():
            flags.append('Local')
        elif self.numChunksOwned > 0:
            flags.append('Partial')

        flagText = ''
        if len(flags) > 0:
            flagText = ' - ' + ' '.join(flags)

        data = (self.fileName, self.numChunksOwned, self.localVersion.numChunks,
                self.localVersion, self.latestVersion, flagText)
        return '%s - %d/%d  local: (%s) latest: (%s)%s' % data
开发者ID:noahsug,项目名称:distributed-file-system,代码行数:80,代码来源:file.py


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