Exemple #1
0
    def checkSettings(self):
        """
        Check the sanity of the settings in this object.

        This method is called after all calls to parseSetting(...) have been done.
        Any defaults may be set here as well.

        An Exception is raised in the case of insanity.
        """
        core.file.file.checkSettings(self)

        if not self.path:
            raise Exception( "file:local {0} must have a local path specified".format( self.name ) )
        if self.metaFile and self.generateTorrent:
            raise Exception( "file:local {0} has requested automated torrent generation, but a meta file was already given".format( self.name ) )
        for cs in self.generateRootHashes:
            if cs in self.rootHashes:
                raise Exception( "Generation of root hash for chunksize {0} was requested, but that root hash was already set on the file.".format( cs ) )
        if os.path.isdir( self.path ):
            if len(self.generateRootHashes) > 0:
                raise Exception( "file:local {0} has requested automated root hash calculation, but {1} is a directory, for which root hashes aren't supported".format( self.name, self.path ) )
            if self.renameFile:
                raise Exception( "file:local {0} has requested the uploaded file to be renamed, but {1} is a directory, for which this is not supported".format( self.name, self.path ) )
        if len(self.generateRootHashes) > 0 or self.generateTorrent:
            meta = Campaign.loadCoreModule('meta')
            # PyLint really doesn't understand dynamic loading
            # pylint: disable-msg=E1101
            for cs in self.generateRootHashes:
                if type(cs) != int and cs[-1:] == 'L':
                    self.rootHashes[cs] = meta.calculateMerkleRootHash( self.path, False, int(cs[:-1]) ).encode( 'hex' )
                else:
                    self.rootHashes[cs] = meta.calculateMerkleRootHash( self.path, True, cs).encode( 'hex' )
                if cs == 1:
                    self.rootHash = self.rootHashes[1]
            if self.generateTorrent:
                if self.isInCleanup():
                    return
                tempfd, self.tempMetaFile = tempfile.mkstemp('.torrent')
                os.close(tempfd)
                self.metaFile = self.tempMetaFile
                meta.generateTorrentFile( self.path, self.metaFile )