示例#1
0
def download_deb_file(file, url, disable_md5check, checksum, download_dir, cache_dir, 
                        package_name, bundle_file, package_version, log, notification_object):
    """ Download the deb file """
    log.msg("Inside the file %s\n" %(file))
    is_download_success = utils.download_from_web(url, file, download_dir, notification_object)
    if is_download_success:
        # The package has been downloaded successfully
        if disable_md5check is False:

            # Check if the checksum is valid
            is_valid_checksum = utils.CheckHashDigest(file, checksum)

            if is_valid_checksum:
                if cache_dir and os.access(cache_dir, os.W_OK):
                    try:
                        shutil.copy(file, cache_dir)
                    except shutil.Error:
                        log.msg("%s file is already present in cache dir %s" %(file, cache_dir))
            else:
                log.err("%s checksum mismatch" %(package_name))

        # Bundle the file into an archive
        if bundle_file:
            zipFile = Archiver(None)
            zipFile.compress_the_file(bundle_file, file)

    # Send the notification that this package failed to download
    else:
        notification_object.failed_packages(package_name, package_version)
示例#2
0
def run(request, response, notification_object, disable_md5check, bundle_file, socket_timeout, 
                    download_dir, cache_dir, total_items, log, func=utils.find_first_match):
    """ Get the packages """

    # The counter which actually keeps track of the total amoutn downloaded
    total_handled = 0
    
    # Create an infinite loop and break only when the queue is empty
    while True:

        # If there is no item in the request Queue 
        if request.empty():
            break

        # Get an item from the request queue
        url, file, size, checksum = request.get()
 
        # Get the name of the current thread
        thread_name = threading.currentThread().getName()
        if file.endswith(".deb"):
            # The file is a deb file which needs to be downloaded

            # Try getting the package name and version
            package_details = file.split("_")

            # Check if the filename has the package name or not
            if len(package_details) > 0:
                
                # Get the package name
                package_name = package_details[0]
                
                # Try getting the package version
                try:
                    package_version = package_details[1]
                except IndexError:
                    package_verion = "NA"
                    log.verbose("Package version not found. Is it really a .deb file?\n")

                # Check if the package is on the local cache or not
                response.put(func(cache_dir, file))

                # Find the full file path
                full_file_path = response.get()
                if full_file_path is not False:
                    log.msg("Package %s found in the cache\n" %(package_name))
                    # The file is downloaded and cached in the specified cache folder
                    handle_cached_deb_file  (
                                            file,
                                            url,
                                            disable_md5check,
                                            checksum,
                                            download_dir,
                                            cache_dir,
                                            package_name,
                                            bundle_file,
                                            package_version,
                                            log,
                                            notification_object
                                            )
                    # Add this package's size to total_download
                    total_handled += size

                    # Send a notificiation to the update the data download
                    notification_object.increment_download(file)
                    # Send a notification to increment download_size
                    notification_object.add_downloaded_size(size)

                else:
                    # The file needs to be downloaded
                    download_deb_file   (
                                        file,
                                        url,
                                        disable_md5check,
                                        checksum,
                                        download_dir,
                                        cache_dir,
                                        package_name,
                                        bundle_file,
                                        package_version,
                                        log,
                                        notification_object
                                        )
                    
                    # Add this package's size to the total_download
                    total_handled += size

                    # Send a notification to update the data downloaded
                    notification_object.increment_download(file)
                    # Send a notification to increment download_size
                    notification_object.add_downloaded_size(size)


            else:
                raise DownloadFileFormatError(DOWNLOAD_FILE_NAME_FORMAT_ERROR %(file))
        else:
            # The file is an update file
            
            is_download_success = utils.download_from_web(url, file, download_dir, notification_object)
            if is_download_success:
                log.msg("Successful package download: %s \n" %(file))
                if bundle_file:
                    try:
                        zipFile = Archiver(None)
                        if zipFile.compress_the_file(bundle_file, file) is False:
                            log.err("Archiving of file %s failed" %(file))
                    except:
                        log.err("Archiving of file %s failed" %(file))