當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。