def case(**kwargs):
     bar = ProgressBar(total, bar_length=length, **kwargs)
     for x in range(total):
         bar.iter()
         time.sleep(bar.update_period)
         printed = out.getvalue().split('\r')[-1].rstrip(bar._last_char)
         self.assertEqual(len(printed), length)
Exemplo n.º 2
0
 def test_prefix(self):
     with patch('sys.stdout', new=io.StringIO()) as out:
         total = 3
         bar = ProgressBar(total, use_thread=False)
         for x in range(total):
             bar.iter()
             self.assertTrue(out.getvalue().split('\r')[-1].startswith(
                 bar.prefix))
 def test_prefix(self):
     with patch('sys.stdout', new=io.StringIO()) as out:
         total = 3
         bar = ProgressBar(total)
         for x in range(total):
             bar.iter()
             time.sleep(bar.update_period)
             self.assertTrue(out.getvalue().split('\r')[-1].startswith(
                 bar.prefix))
Exemplo n.º 4
0
 def case(**kwargs):
     bar = ProgressBar(total,
                       bar_length=length,
                       use_thread=False,
                       **kwargs)
     for x in range(total):
         bar.iter()
         printed = out.getvalue().split('\r')[-1].rstrip(bar._last_char)
         self.assertEqual(len(printed), length)
Exemplo n.º 5
0
def progress():
    """ Print Progress bar (without inbuilt threading) """
    try:
        total = round(tag.duration)  # Total time to print progress
        bar = ProgressBar(total,
                          bar_length=os.get_terminal_size()[0],
                          use_thread=False)
        for x in range(total):
            sleep(1)
            bar.iter()  # iter to update animation
        console.print('\nPlayback finished', style="b cyan")
    except KeyboardInterrupt:
        print("\n")
Exemplo n.º 6
0
 def test_time(self):
     with patch('sys.stdout', new=io.StringIO()) as out:
         bar = ProgressBar(5,
                           time_format='hh hours, mm minutes, ss seconds',
                           use_thread=False)
         bar.iter()
         self.assertTrue(
             '00 hours, 00 minutes, 00 seconds' in out.getvalue())
         bar = ProgressBar(5,
                           time_format='hh hours, mm minutes, ss seconds',
                           use_thread=False,
                           use_eta=True)
         bar.iter()
         self.assertTrue(
             '00 hours, 00 minutes, 00 seconds/00 hours, 00 minutes, 00 seconds'
             in out.getvalue())
Exemplo n.º 7
0
    def test_eta(self):
        with patch('sys.stdout', new=io.StringIO()) as out:
            bar = ProgressBar(300, use_thread=False, use_eta=True)
            for x in range(3):
                time.sleep(0.2)
                bar.iter()
            eta = re.findall(r'\d\d:\d\d', out.getvalue())[1]
            self.assertTrue(eta in [f'01:0{x}' for x in range(5)])

            bar = ProgressBar(5,
                              use_eta=True,
                              eta_format='hh hours, mm minutes, ss seconds',
                              use_thread=False)
            bar.iter()
            self.assertTrue(
                '/00 hours, 00 minutes, 00 seconds' in out.getvalue())
 def test_time(self):
     with patch('sys.stdout', new=io.StringIO()) as out:
         bar = ProgressBar(5,
                           time_format='hh hours, mm minutes, ss seconds')
         time.sleep(bar.update_period * 1.2)
         bar.stop()
         self.assertTrue(
             '00 hours, 00 minutes, 00 seconds' in out.getvalue())
         bar = ProgressBar(5,
                           time_format='hh hours, mm minutes, ss seconds',
                           use_eta=True)
         bar.iter()
         time.sleep(bar.update_period * 1.2)
         bar.stop()
         self.assertTrue(
             '00 hours, 00 minutes, 00 seconds/00 hours, 00 minutes, 00 seconds'
             in out.getvalue())
    def test_eta(self):
        with patch('sys.stdout', new=io.StringIO()) as out:
            bar = ProgressBar(300, use_eta=True)
            for x in range(3):
                time.sleep(0.2)
                bar.iter()
            time.sleep(bar.update_period)
            bar.stop()
            eta = re.findall(f'\d\d:\d\d', out.getvalue())[-1]
            self.assertTrue(eta in [f'01:0{x}' for x in range(10)])

            bar = ProgressBar(5,
                              use_eta=True,
                              eta_format='hh hours, mm minutes, ss seconds')
            bar.iter()
            time.sleep(bar.update_period * 1.2)
            bar.stop()
            self.assertTrue(
                '/00 hours, 00 minutes, 00 seconds' in out.getvalue())
Exemplo n.º 10
0
    def delete(self, UIDs):
        """
        Move specified emails to Trash box

        Args:
            UIDs(list(int)): list of email unique identifiers (UID) that have been marked for deletion

        """
        total = len(UIDs)
        bar = ProgressBar(total,
                          use_eta=True,
                          bar_length=70,
                          spinner_type='db')
        for message in UIDs:
            try:
                self.server.add_gmail_labels(message, '\Trash', silent=True)
                bar.iter(' Moved to Trash')
            except:
                bar.stop()
Exemplo n.º 11
0
class LoggerCallback(Callback):
    def __init__(self, total):
        self._total = total
        
    def on_epoch_begin(self, epoch, logs):
        print(f'Epoch {epoch}:')
        prefix = self._create_prefix(0).rstrip()
        self.bar = ProgressBar(self._total, prefix, '', bar_length=80, new_line_at_end=False)
    
    def on_train_batch_end(self, batch, logs):
        self.bar.prefix = self._create_prefix(batch)
        self.bar.iter(f'   mape: {logs["mape"]:>6.2f}')
    
    def on_test_end(self, logs):
        print(f' - val_mape: {logs["mape"]:>6.2f}')
        
    def _create_prefix(self, batch):
        prefix = f'{batch}/{self._total - 1} '
        return prefix.rjust(len(str(self._total)) * 2 + 4)
Exemplo n.º 12
0
def Downloader(dlList):
    global failedImg

    succeeded = 0
    failed = []
    # 初始化进度条
    bar = ProgressBar(len(dlList), prefix="Downloading", bar_length=60)
    try:
        for num in dlList:
            try:
                imgUrl = getImgURL(num)
                imgName = imgUrl.split("/")[-1]
                imgDL(imgUrl, DlPath.format(imgName))

                sleep(2)
                succeeded += 1
            except:  # 请求错误(超时)处理
                failed.append(num)
                failedImg.append(num)
                sleep(0.5)

            bar.iter()
    except:  # 迭代结束
        bar.stop()
        exit(0)

    bar.wait()
    # 本次下载内容总览
    print("下载完成! | Download Finished!")
    print("本次下载 | You downloaded :")
    print("成功 | Succeeded: " + str(succeeded))
    print("失败 | Failed: " + str(len(failed)))

    if len(failed) == 0:
        exit(0)
    else:
        toDlFailed = input(
            "是否重新下载错误的图片? | Wanna download imgs failed? (y / n) ")
        # if toDlFailed == "y":
        failedImg = failed
        return True
Exemplo n.º 13
0
from awesome_progress_bar import ProgressBar
import time

total = 133
try:
    bar = ProgressBar(total)
    for x in range(total):
        time.sleep(0.1)
        bar.iter()
except:
    bar.stop()
bar.wait()
time_passed = bar.get_time_passed()
print(f'Total time passed: {time_passed}')
# Progress: |==================================== 00:15 =====================================| 100.00%
# Total time passed: 00:15

try:
    bar = ProgressBar(total, 'Prefix', 'Suffix', use_eta=True)
    for x in range(total):
        time.sleep(0.1)
        bar.iter()
except:
    bar.stop()
bar.wait()
time_passed = bar.get_time_passed(False)
print(f'Total seconds passed: {time_passed:.4f}')
# Prefix: |================================== 00:15 ==================================| 100.00% Suffix
# Total seconds passed: 14.5497

# No need to use try/catch without thread