Exemple #1
0
class TransferManager():
    """Handles transfer of a one or several sources to a destination

    One FileTransferManager object will be created for each file
    to transfer.

    """
    def __init__(self, sources, destination):
        self.sources = sources
        self.destination = destination
        self.transfer_info = TransferInfo(sources, destination)
        self.global_pbar = None
        self.file_pbar = None

    def do_transfer(self):
        """Performs the real transfer"""
        errors = dict()
        if pycp.options.global_pbar:
            num_files = len(self.transfer_info.to_transfer)
            total_size = self.transfer_info.size
            self.global_pbar = GlobalPbar(num_files, total_size)
            self.global_pbar.start()
        for (src, dest) in self.transfer_info.to_transfer:
            file_size = os.path.getsize(src)
            ftm = FileTransferManager(self, src, dest)
            self.on_new_transfer(src, dest, file_size)
            error = ftm.do_transfer()
            if error:
                errors[src] = error

        if pycp.options.move and not pycp.options.ignore_errors:
            for to_remove in self.transfer_info.to_remove:
                os.rmdir(to_remove)

        return errors

    def update(self, xferd):
        """Called during transfer of one file"""
        self.on_file_transfer(xferd)

    def on_new_transfer(self, src, dest, size):
        """If global pbar is false:
        create a new progress bar for just one file

        """
        if pycp.options.global_pbar:
            self.global_pbar.new_file(src, size)
        else:
            self.file_pbar = FilePbar(src, dest, size)
            self.file_pbar.start()

    def on_file_transfer(self, xferd):
        """If global pbar is False:
        update the file_pbar

        """
        if pycp.options.global_pbar:
            self.global_pbar.update(xferd)
        else:
            self.file_pbar.update(xferd)
Exemple #2
0
class TransferManager():
    """Handles transfer of a one or several sources to a destination

    One FileTransferManager object will be created for each file
    to transfer.

    """
    def __init__(self, sources, destination):
        self.sources = sources
        self.destination = destination
        self.transfer_info = TransferInfo(sources, destination)
        self.global_pbar = None
        self.file_pbar = None

    def do_transfer(self):
        """Performs the real transfer"""
        errors = dict()
        if pycp.options.global_pbar:
            num_files = len(self.transfer_info.to_transfer)
            total_size = self.transfer_info.size
            self.global_pbar = GlobalPbar(num_files, total_size)
            self.global_pbar.start()
        for (src, dest) in self.transfer_info.to_transfer:
            file_size = os.path.getsize(src)
            ftm = FileTransferManager(self, src, dest)
            self.on_new_transfer(src, dest, file_size)
            error = ftm.do_transfer()
            if error:
                errors[src] = error

        if pycp.options.move and not pycp.options.ignore_errors:
            for to_remove in self.transfer_info.to_remove:
                os.rmdir(to_remove)

        return errors

    def update(self, xferd):
        """Called during transfer of one file"""
        self.on_file_transfer(xferd)

    def on_new_transfer(self, src, dest, size):
        """If global pbar is false:
        create a new progress bar for just one file

        """
        if pycp.options.global_pbar:
            self.global_pbar.new_file(src, size)
        else:
            self.file_pbar = FilePbar(src, dest, size)
            self.file_pbar.start()

    def on_file_transfer(self, xferd):
        """If global pbar is False:
        update the file_pbar

        """
        if pycp.options.global_pbar:
            self.global_pbar.update(xferd)
        else:
            self.file_pbar.update(xferd)
Exemple #3
0
    def on_new_transfer(self, src, dest, size):
        """If global pbar is false:
        create a new progress bar for just one file

        """
        if pycp.options.global_pbar:
            self.global_pbar.new_file(src, size)
        else:
            self.file_pbar = FilePbar(src, dest, size)
            self.file_pbar.start()
Exemple #4
0
    def on_new_transfer(self, src, dest, size):
        """If global pbar is false:
        create a new progress bar for just one file

        """
        if pycp.options.global_pbar:
            self.global_pbar.new_file(src, size)
        else:
            self.file_pbar = FilePbar(src, dest, size)
            self.file_pbar.start()