コード例 #1
0
ファイル: FileSpec.py プロジェクト: OldWare/OldToontown
    def __init__(self, filename, pathname):
        self.filename = filename
        self.pathname = pathname

        self.size = pathname.getFileSize()
        self.timestamp = pathname.getTimestamp()

        hv = HashVal()
        hv.hashFile(pathname)
        self.hash = hv.asHex()
コード例 #2
0
    def __init__(self, filename, pathname):
        self.filename = filename
        self.pathname = pathname

        self.size = pathname.getFileSize()
        self.timestamp = pathname.getTimestamp()

        hv = HashVal()
        hv.hashFile(pathname)
        self.hash = hv.asHex()
コード例 #3
0
ファイル: ShardFSM.py プロジェクト: TTGhost/POTCOR-src
 def enterPrepareShard(self, shardId):
     self.cr.distributedDistrict = self.cr.getDo(shardId)
     DistributedSmoothNode.globalActivateSmoothing(1, 0)
     h = HashVal()
     hashPrcVariables(h)
     pyc = HashVal()
     if not __dev__:
         self.cr.hashFiles(pyc)
     
     self.cr.timeManager.d_setSignature(self.cr.userSignature, h.asBin(), pyc.asBin())
     if self.cr.timeManager.synchronize('startup'):
         self.acceptOnce('gotTimeSync', self.request, extraArgs = [
             'ShardReady',
             shardId])
     else:
         self.demand('ShardReady', shardId)
コード例 #4
0
ファイル: HostInfo.py プロジェクト: DankMickey/Toontown-2.0
    def redownloadContentsFile(self, http):
        """ Downloads a new contents.xml file in case it has changed.
        Returns true if the file has indeed changed, false if it has
        not. """
        assert self.hasContentsFile

        if self.appRunner and self.appRunner.verifyContents == self.appRunner.P3DVCNever:
            # Not allowed to.
            return False

        url = self.hostUrlPrefix + 'contents.xml'
        self.notify.info("Redownloading %s" % (url))

        # Get the hash of the original file.
        assert self.hostDir
        hv1 = HashVal()
        if self.contentsSpec.hash:
            hv1.setFromHex(self.contentsSpec.hash)
        else:
            filename = Filename(self.hostDir, 'contents.xml')
            hv1.hashFile(filename)

        # Now download it again.
        self.hasContentsFile = False
        hv2 = HashVal()
        if not self.downloadContentsFile(http, redownload = True,
                                         hashVal = hv2):
            return False

        if hv2 == HashVal():
            self.notify.info("%s didn't actually redownload." % (url))
            return False
        elif hv1 != hv2:
            self.notify.info("%s has changed." % (url))
            return True
        else:
            self.notify.info("%s has not changed." % (url))
            return False
コード例 #5
0
 def enterPrepareShard(self, shardId):
     self.cr.distributedDistrict = self.cr.getDo(shardId)
     DistributedSmoothNode.globalActivateSmoothing(1, 0)
     h = HashVal()
     hashPrcVariables(h)
     pyc = HashVal()
     if not __dev__:
         self.cr.hashFiles(pyc)
     self.cr.timeManager.d_setSignature(self.cr.userSignature, h.asBin(),
                                        pyc.asBin())
     if self.cr.timeManager.synchronize('startup'):
         self.acceptOnce('gotTimeSync',
                         self.request,
                         extraArgs=['ShardReady', shardId])
     else:
         self.demand('ShardReady', shardId)
コード例 #6
0
ファイル: FileSpec.py プロジェクト: jeraldamo/Mayhem
    def readHash(self, pathname):
        """ Reads the hash only from the indicated pathname. """

        hv = HashVal()
        hv.hashFile(pathname)
        self.hash = hv.asHex()
コード例 #7
0
ファイル: HostInfo.py プロジェクト: DankMickey/Toontown-2.0
    def __determineHostDir(self, hostDirBasename, hostUrl):
        """ Hashes the host URL into a (mostly) unique directory
        string, which will be the root of the host's install tree.
        Returns the resulting path, as a Filename.

        This code is duplicated in C++, in
        P3DHost::determine_host_dir(). """

        if hostDirBasename:
            # If the contents.xml specified a host_dir parameter, use
            # it.
            hostDir = self.rootDir.cStr() + '/hosts'
            for component in hostDirBasename.split('/'):
                if component:
                    if component[0] == '.':
                        # Forbid ".foo" or "..".
                        component = 'x' + component
                    hostDir += '/'
                    hostDir += component
            return Filename(hostDir)

        hostDir = 'hosts/'

        # Look for a server name in the URL.  Including this string in the
        # directory name makes it friendlier for people browsing the
        # directory.

        # We could use URLSpec, but we do it by hand instead, to make
        # it more likely that our hash code will exactly match the
        # similar logic in P3DHost.
        p = hostUrl.find('://')
        hostname = ''
        if p != -1:
            start = p + 3
            end = hostUrl.find('/', start)
            # Now start .. end is something like "username@host:port".

            at = hostUrl.find('@', start)
            if at != -1 and at < end:
                start = at + 1

            colon = hostUrl.find(':', start)
            if colon != -1 and colon < end:
                end = colon

            # Now start .. end is just the hostname.
            hostname = hostUrl[start : end]

        # Now build a hash string of the whole URL.  We'll use MD5 to
        # get a pretty good hash, with a minimum chance of collision.
        # Even if there is a hash collision, though, it's not the end
        # of the world; it just means that both hosts will dump their
        # packages into the same directory, and they'll fight over the
        # toplevel contents.xml file.  Assuming they use different
        # version numbers (which should be safe since they have the
        # same hostname), there will be minimal redownloading.

        hashSize = 16
        keepHash = hashSize
        if hostname:
            hostDir += hostname + '_'

            # If we successfully got a hostname, we don't really need the
            # full hash.  We'll keep half of it.
            keepHash = keepHash / 2;

        md = HashVal()
        md.hashString(hostUrl)
        hostDir += md.asHex()[:keepHash * 2]

        hostDir = Filename(self.rootDir, hostDir)
        return hostDir
コード例 #8
0
    def readHash(self, pathname):
        """ Reads the hash only from the indicated pathname. """

        hv = HashVal()
        hv.hashFile(pathname)
        self.hash = hv.asHex()