Exemplo n.º 1
0
 def test_printFilesDigests(self):
     path, name = os.path.split(self.tmpFile)
     log = io.StringIO()
     with contextlib.redirect_stdout(log):
         EmergeHash.printFilesDigests(path, [name], "test", EmergeHash.HashAlgorithm.SHA256)
     self.assertEquals("self.targetDigests['test'] = (['4fc1e96dc5ecf625efe228fce1b0964b6302cfa4d4fb2bb8d16c665d23f6ff30'], EmergeHash.HashAlgorithm.SHA256)\n",
                       log.getvalue())
Exemplo n.º 2
0
def unmergeFileList(rootdir, fileList, forced=False):
    """ delete files in the fileList if has matches or forced is True """
    for filename, filehash in fileList:
        fullPath = os.path.join(rootdir, os.path.normcase( filename))
        if os.path.isfile(fullPath):
            algorithm = EmergeHash.HashAlgorithm.getAlgorithmFromPrefix(filehash)
            if not algorithm:
                currentHash = EmergeHash.digestFile(fullPath, EmergeHash.HashAlgorithm.MD5)
            else:
                currentHash = algorithm.stringPrefix() + EmergeHash.digestFile(fullPath, algorithm)
            if currentHash == filehash or filehash == "":
                EmergeDebug.debug("deleting file %s" % fullPath, 2)
                try:
                    os.remove(fullPath)
                except OSError:
                    system( "cmd /C \"attrib -R %s\"" % fullPath )
                    os.remove(fullPath)
            else:
                if forced:
                    EmergeDebug.warning("file %s has different hash: %s %s, deleting anyway" % \
                            (fullPath, currentHash, filehash ))
                try:
                    os.remove(fullPath)
                except OSError:
                    system( "cmd /C \"attrib -R %s\"" % fullPath )
                    os.remove(fullPath)
                else:
                    EmergeDebug.warning("file %s has different hash: %s %s, run with option --force to delete it anyway" % \
                            (fullPath, currentHash, filehash ))
        elif not os.path.isdir(fullPath):
            EmergeDebug.warning("file %s does not exist" % fullPath)
Exemplo n.º 3
0
    def checkDigest(self):
        EmergeDebug.debug("ArchiveSource.checkDigest called", 2)
        filenames = self.localFileNames()

        if self.subinfo.hasTargetDigestUrls():
            EmergeDebug.debug("check digests urls", 1)
            if not EmergeHash.checkFilesDigests(
                    EmergeStandardDirs.downloadDir(), filenames):
                EmergeDebug.error("invalid digest file")
                return False
        elif self.subinfo.hasTargetDigests():
            EmergeDebug.debug("check digests", 1)
            digests, algorithm = self.subinfo.targetDigest()
            if not EmergeHash.checkFilesDigests(
                    EmergeStandardDirs.downloadDir(), filenames, digests,
                    algorithm):
                EmergeDebug.error("invalid digest file")
                return False
        else:
            EmergeDebug.debug("print source file digests", 1)
            EmergeHash.printFilesDigests(
                EmergeStandardDirs.downloadDir(),
                filenames,
                self.subinfo.buildTarget,
                algorithm=EmergeHash.HashAlgorithm.SHA256)
        return True
Exemplo n.º 4
0
    def createPackage( self ):
        """ create a package """
        print("packaging using the PortablePackager")
        
        self.internalCreatePackage()

        self.createPortablePackage()
        EmergeHash.createDigestFile(os.path.join(self.packageDestinationDir(), self.defines["setupname"]))
        return True
Exemplo n.º 5
0
 def test_printFilesDigests(self):
     path, name = os.path.split(self.tmpFile)
     log = io.StringIO()
     with contextlib.redirect_stdout(log):
         EmergeHash.printFilesDigests(path, [name], "test",
                                      EmergeHash.HashAlgorithm.SHA256)
     self.assertEquals(
         "self.targetDigests['test'] = (['4fc1e96dc5ecf625efe228fce1b0964b6302cfa4d4fb2bb8d16c665d23f6ff30'], EmergeHash.HashAlgorithm.SHA256)\n",
         log.getvalue())
    def createPackage( self ):
        """ create a package """
        self.isInstalled()
        print("packaging using the NullsoftInstallerPackager")

        self.internalCreatePackage()
        self.preArchive()
        self.generateNSISInstaller()
        EmergeHash.createDigestFile(self.defines["setupname"])
        return True
Exemplo n.º 7
0
    def createPackage(self):
        """ create a package """
        self.isNsisInstalled()

        EmergeDebug.debug("packaging using the NullsoftInstallerPackager")

        self.internalCreatePackage()
        self.preArchive()
        self.generateNSISInstaller()
        EmergeHash.createDigestFiles(self.defines["setupname"])
        return True
Exemplo n.º 8
0
    def createPackage(self):
        """ create a package """
        print("packaging using the PortablePackager")

        self.internalCreatePackage()

        self.createPortablePackage()
        EmergeHash.createDigestFiles(
            os.path.join(self.packageDestinationDir(),
                         self.defines["setupname"]))
        return True
Exemplo n.º 9
0
    def checkDigest(self):
        EmergeDebug.debug("ArchiveSource.checkDigest called", 2)
        filenames = self.localFileNames()

        if self.subinfo.hasTargetDigestUrls():
            EmergeDebug.debug("check digests urls", 1)
            if not EmergeHash.checkFilesDigests(EmergeStandardDirs.downloadDir(), filenames):
                EmergeDebug.error("invalid digest file")
                return False
        elif self.subinfo.hasTargetDigests():
            EmergeDebug.debug("check digests", 1)
            digests, algorithm = self.subinfo.targetDigest()
            if not EmergeHash.checkFilesDigests( EmergeStandardDirs.downloadDir(), filenames, digests, algorithm):
                EmergeDebug.error("invalid digest file")
                return False
        else:
            EmergeDebug.debug("print source file digests", 1)
            EmergeHash.printFilesDigests(EmergeStandardDirs.downloadDir(), filenames, self.subinfo.buildTarget, algorithm = EmergeHash.HashAlgorithm.SHA256)
        return True
Exemplo n.º 10
0
def unmergeFileList(rootdir, fileList, forced=False):
    """ delete files in the fileList if has matches or forced is True """
    for filename, filehash in fileList:
        fullPath = os.path.join(rootdir, os.path.normcase( filename))
        if os.path.isfile(fullPath):
            algorithm = EmergeHash.HashAlgorithm.getAlgorithmFromPrefix(filehash)
            if not algorithm:
                currentHash = EmergeHash.digestFile(fullPath, EmergeHash.HashAlgorithm.MD5)
            else:
                currentHash = algorithm.stringPrefix() + EmergeHash.digestFile(fullPath, algorithm)
            if currentHash == filehash or filehash == "":
                OsUtils.rm(fullPath, True)
            else:
                if forced:
                    EmergeDebug.warning("file %s has different hash: %s %s, deleting anyway" % \
                            (fullPath, currentHash, filehash ))
                    OsUtils.rm(fullPath, True)
                else:
                    EmergeDebug.warning("file %s has different hash: %s %s, run with option --force to delete it anyway" % \
                            (fullPath, currentHash, filehash ))
        elif not os.path.isdir(fullPath):
            EmergeDebug.warning("file %s does not exist" % fullPath)
Exemplo n.º 11
0
def getFileListFromDirectory( imagedir ):
    """ create a file list containing hashes """
    ret = []

    myimagedir = imagedir
    if ( not imagedir.endswith( "\\" ) ):
        myimagedir = myimagedir + "\\"

    algorithm = EmergeHash.HashAlgorithm.SHA256
    for root, _, files in os.walk( imagedir ):
        for fileName in files:
            ret.append( ( os.path.join( root, fileName ).replace( myimagedir, "" ), algorithm.stringPrefix() + EmergeHash.digestFile( os.path.join( root, fileName), algorithm) ) )
    return ret
Exemplo n.º 12
0
 def test_createDigestFiles(self):
     # TODO: check file content
     EmergeHash.createDigestFiles(self.tmpFile)
     for algorithms in EmergeHash.HashAlgorithm.__members__.values():
         self.assertEquals(
             os.path.exists(self.tmpFile + algorithms.fileEnding()), True)
Exemplo n.º 13
0
 def hashTest(self, hash, algorithm):
     path, name = os.path.split(self.tmpFile)
     self.assertEquals(
         EmergeHash.checkFilesDigests(path, [name], hash, algorithm), True)
Exemplo n.º 14
0
 def test_createDigestFiles(self):
     # TODO: check file content
     EmergeHash.createDigestFiles(self.tmpFile)
     for algorithms in EmergeHash.HashAlgorithm.__members__.values():
         self.assertEquals(os.path.exists(self.tmpFile + algorithms.fileEnding()), True)
Exemplo n.º 15
0
 def hashTest(self, hash, algorithm):
     path, name = os.path.split(self.tmpFile)
     self.assertEquals(EmergeHash.checkFilesDigests(path, [name], hash, algorithm), True)