Beispiel #1
0
 def perform(cls, release_type, package_name, diff_numbers):
     ancestor_build = manager.ValidateAndDownload(release_type, package_name, diff_numbers[0])
     child_build = manager.ValidateAndDownload(release_type, package_name, diff_numbers[1])
     if ancestor_build != None and child_build != None:
         if os.path.exists(ancestor_build) == True and os.path.exists(child_build) == True:
             # download was successful
             diff_path = os.path.join(config.getDownloadDir(), package_name+'.diff')
             logging_helper.getLogger().info('Creating source diff...')
             cls.make(ancestor_build, child_build, diff_path)
             logging_helper.getLogger().info('Package diff written to "'+diff_path+'"!')
         else:
             logging_helper.getLogger().error('There was an error with finding the downloaded packages!')
     else:
         logging_helper.getLogger().error('One or more of the build numbers supplied was not valid. Please use the "--list" command to see available build numebrs.')
Beispiel #2
0
    def DownloadPackageTarball(cls, release_type, package_name, build_number, \
            release_version = '', dest_dir = '', check_hash = True):
        
        downloaded_directory_path = ''
        tarball_address = cls.CreateTarballURL(release_type, package_name, build_number)
        package_file_name = os.path.basename(tarball_address)

        if dest_dir != '':
            output_directory = dest_dir
        else:
            output_directory = os.path.expanduser(config.getDownloadDir())

        if release_version != '':
            output_directory = output_directory + '/' + release_version
        
        try:
            os.makedirs(output_directory)
        except OSError:
            pass

        output_file = os.path.join(output_directory, package_file_name)
        download_successful = cls.DownloadFileFromURLToPath(tarball_address, output_file)
        tar_name = os.path.splitext(package_file_name)[0]
        file_name = os.path.splitext(tar_name)[0]
        if check_hash == True:
            logging_helper.getLogger().info('Downloaded "'+file_name+'" to "'+output_file+'"')
            # check the downloaded file against the stored hash
            hash_result = Hashes.ValidateDownloadedFileByHash(output_file, release_type, package_name, build_number, False)
            if hash_result[0] == True:
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Decompressing "'+output_file+'" -> "'+tar_name+'"...')
                gz_archive = gzip.open(output_file, 'rb')
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Reading file contents...')
                file_content = gz_archive.read()
                tar_path = os.path.join(output_directory, tar_name)
                dump_tar = open(tar_path, 'wb')
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Dumping tar file...')
                dump_tar.write(file_content)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Closing files...')
                dump_tar.close()
                gz_archive.close()
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Removing archive...')
                os.remove(output_file)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Opening tar file...')
                tar_archive = tarfile.open(tar_path)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Decompressing tar file...')
                tar_archive.extractall(output_directory)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Closing tar file...')
                tar_archive.close()
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Removing tar file...')
                os.remove(tar_path)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Decompression Complete!')
                logging_helper.getLogger().info('The package "'+file_name+'" has been downloaded to "'+output_directory+'".')
                downloaded_directory_path = os.path.join(output_directory, file_name)
            else:
                logging_helper.getLogger().info('The package "'+file_name+'" has hash of "'+hash_result[1]+'" which doesn\'t match the hash on record ('+hash_result[2]+')')
        else:
            if download_successful == True:
                downloaded_directory_path = output_file
        return downloaded_directory_path