Exemple #1
0
    def test_custom_bar_with_scale(self):
        """Test a custom progress bar with a custom scale"""

        total = 50
        fill_char = '#'
        empty_char = ' '
        head = '>'
        left_limit = '['
        right_limit = ']'
        scale_start = 415
        scale_end = 431
        bar = CustomProgressBar(length=total,
                                left_limit=left_limit,
                                right_limit=right_limit,
                                head_repr=head,
                                empty_repr=empty_char,
                                filled_repr=fill_char,
                                start=0,
                                scale_start=scale_start,
                                scale_end=scale_end)

        head = fill_char if not head else head
        bar.increase((scale_end - scale_start) // 2)
        test_str = self.format_string(total, left_limit, right_limit,
                                      fill_char, empty_char, head)
        self.assertEqual(test_str, bar.progress_bar)
Exemple #2
0
    def test_custom_bar_with_scale(self):
        """Test a custom progress bar with a custom scale"""

        total = 50
        fill_char = '#'
        empty_char = ' '
        head = '>'
        left_limit = '['
        right_limit = ']'
        scale_start = 415
        scale_end = 431
        bar = CustomProgressBar(length=total,
                                left_limit=left_limit,
                                right_limit=right_limit,
                                head_repr=head,
                                empty_repr=empty_char,
                                filled_repr=fill_char,
                                start=0,
                                scale_start=scale_start,
                                scale_end=scale_end)

        head = fill_char if not head else head
        bar.increase((scale_end - scale_start) // 2)
        test_str = self.format_string(total, left_limit, right_limit, fill_char,
                                    empty_char, head)
        self.assertEqual(test_str, bar.progress_bar)
Exemple #3
0
def show_custom_animation():
    total = 50
    fill_char = "|"
    empty_char = "_"
    head = None
    left_limit = ""
    right_limit = ""
    scale_start = 0
    scale_end = 1000
    bar = CustomProgressBar(
        length=total,
        left_limit=left_limit,
        right_limit=right_limit,
        head_repr=head,
        empty_repr=empty_char,
        filled_repr=fill_char,
        start=0,
        scale_start=scale_start,
        scale_end=scale_end,
    )
    bar.show_progress_bar()
    while not bar.completed():
        time.sleep(0.03)
        bar.increase(10)
        bar.show_progress_bar()
Exemple #4
0
def download_file():
    big_file_url = "http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tgz"

    # Download the file
    if sys.version_info[0] == 3:
        f = urllib.request.urlopen(big_file_url)
    else:
        f = urllib.urlopen(big_file_url)

    # Get the total length of the file
    scale = int(f.headers["content-length"])
    chunk_size = 500

    bar = CustomProgressBar(length=50,
                            left_limit='[',
                            right_limit=']',
                            head_repr=None,
                            empty_repr=' ',
                            filled_repr='|',
                            start=0,
                            scale_start=0,
                            scale_end=scale)

    print("Downloading a big txt file: ")

    print_flag = 0
    # Load all the data chunk by chunk
    while not bar.completed():
        f.read(chunk_size)
        bar.increase(chunk_size)

        # Don't print always
        if print_flag == 100:
            bar.show_progress_bar()
            print_flag = 0
        else:
            print_flag += 1

    bar.show_progress_bar()
    print("")
    print("Finished :)")
Exemple #5
0
    def test_custom_bar(self):
        """Test a custom progress bar"""
        total = 100
        fill_char = '#'
        empty_char = '.'
        head = '|'
        left_limit = '('
        right_limit = ')'
        scale_start = 0
        scale_end = 100
        bar = CustomProgressBar(length=total,
                                left_limit=left_limit,
                                right_limit=right_limit,
                                head_repr=head,
                                empty_repr=empty_char,
                                filled_repr=fill_char,
                                start=0,
                                scale_start=scale_start,
                                scale_end=scale_end)

        bar.increase((scale_end - scale_start) // 2)
        test_str = self.format_string(total, left_limit, right_limit,
                                      fill_char, empty_char, head)
        self.assertEqual(test_str, bar.progress_bar)
Exemple #6
0
    def test_custom_bar(self):
        """Test a custom progress bar"""
        total = 100
        fill_char = '#'
        empty_char = '.'
        head = '|'
        left_limit = '('
        right_limit = ')'
        scale_start = 0
        scale_end = 100
        bar = CustomProgressBar(length=total,
                                left_limit=left_limit,
                                right_limit=right_limit,
                                head_repr=head,
                                empty_repr=empty_char,
                                filled_repr=fill_char,
                                start=0,
                                scale_start=scale_start,
                                scale_end=scale_end)

        bar.increase((scale_end - scale_start) // 2)
        test_str = self.format_string(total, left_limit, right_limit, fill_char,
                                    empty_char, head)
        self.assertEqual(test_str, bar.progress_bar)
Exemple #7
0
def download_file():
    big_file_url = "http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tgz"

    # Download the file
    if sys.version_info[0] == 3:
        f = urllib.request.urlopen(big_file_url)
    else:
        f = urllib.urlopen(big_file_url)

    # Get the total length of the file
    scale = int(f.headers["content-length"])
    chunk_size = 500

    bar = CustomProgressBar(
        length=50,
        left_limit="[",
        right_limit="]",
        head_repr=None,
        empty_repr=" ",
        filled_repr="|",
        start=0,
        scale_start=0,
        scale_end=scale,
    )

    print("Downloading a big txt file: ")

    print_flag = 0
    # Load all the data chunk by chunk
    while not bar.completed():
        f.read(chunk_size)
        bar.increase(chunk_size)

        # Don't print always
        if print_flag == 100:
            bar.show_progress_bar()
            print_flag = 0
        else:
            print_flag += 1

    bar.show_progress_bar()
    print("")
    print("Finished :)")
Exemple #8
0
def show_custom_animation():
    total = 50
    fill_char = '|'
    empty_char = '_'
    head = None
    left_limit = ''
    right_limit = ''
    scale_start = 0
    scale_end = 1000
    bar = CustomProgressBar(length=total,
                            left_limit=left_limit,
                            right_limit=right_limit,
                            head_repr=head,
                            empty_repr=empty_char,
                            filled_repr=fill_char,
                            start=0,
                            scale_start=scale_start,
                            scale_end=scale_end)
    bar.show_progress_bar()
    while (not bar.completed()):
        time.sleep(0.03)
        bar.increase(10)
        bar.show_progress_bar()