From ff0631a790acd4ceed7d71649e6421a4d4765753 Mon Sep 17 00:00:00 2001 From: ztimson Date: Fri, 15 Dec 2023 17:26:51 -0500 Subject: [PATCH] Updated library files & readme --- MANIFEST | 4 - README.md | 184 +++++++++++++++++++---------------- ZProgressbar/ZProgressbar.py | 140 -------------------------- ZProgressbar/__init__.py | 1 - __init__.py | 0 dist/ZProgressbar-1.0.tar.gz | Bin 2279 -> 0 bytes dist/ZProgressbar-1.1.tar.gz | Bin 2274 -> 0 bytes setup.py | 13 --- 8 files changed, 99 insertions(+), 243 deletions(-) delete mode 100644 MANIFEST delete mode 100644 ZProgressbar/ZProgressbar.py delete mode 100644 ZProgressbar/__init__.py delete mode 100644 __init__.py delete mode 100644 dist/ZProgressbar-1.0.tar.gz delete mode 100644 dist/ZProgressbar-1.1.tar.gz delete mode 100644 setup.py diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 8ead968..0000000 --- a/MANIFEST +++ /dev/null @@ -1,4 +0,0 @@ -# file GENERATED by distutils, do NOT edit -setup.py -ZProgressbar/ZProgressbar.py -ZProgressbar/__init__.py diff --git a/README.md b/README.md index 4287c83..ed053a3 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,121 @@ -# progressbar + +
+
+ + + Logo + + + ### py-bar + + + Python ASCII Progress Bar + + + [![Version](https://img.shields.io/badge/dynamic/json.svg?label=Version&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/py-bar/tags&query=$[0].name)](https://git.zakscode.com/ztimson/py-bar/tags) + [![Pull Requests](https://img.shields.io/badge/dynamic/json.svg?label=Pull%20Requests&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/py-bar&query=open_pr_counter)](https://git.zakscode.com/ztimson/py-bar/pulls) + [![Issues](https://img.shields.io/badge/dynamic/json.svg?label=Issues&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/py-bar&query=open_issues_count)](https://git.zakscode.com/ztimson/py-bar/issues) + + + + --- +
+ Release Notes + • Report a Bug + • Request a Feature +
+ + --- +
+ +## Table of Contents +- [py-bar](#top) + - [About](#about) + - [Built With](#built-with) + - [Setup](#setup) + - [Production](#production) + - [Documentation](#documentation) + - [License](#license) + +## About + Python CLI Progress bar. This module is an iterator that can not only, iterate, but display its self as a progressbar along with some other usefull iformation such as iterations a second, estimated time, elapsed time, etc. `00:25 100% [====================] [100/100] 3.99/s 00:00` -### Authors - * [Zak Timson](http://zakscode.com) +### Built With +[![Python](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python)](https://www.python.org/) -### License -GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007. read LICENSE for more +## Setup -### Install -Copy the script to your project and import it with: +
+ +

+ Production +

+
-`import progressbar` +#### Prerequisites +- [Python](https://www.python.org/downloads/) -or +#### Instructions +1. Download and add script to project: `curl https://git.zakscode.com/ztimson/py-bar/raw/branch/develop/progressbar.py` +2. Use in python script: -`from progressbar import Progressbar` +```python +from progressbar import Progressbar -### Quick Start -Use in a forloop: +for i in Progressbar(100): + ... -`for i in Progressbar(100)` +# OR -Dont like it auto writing to the stdout? Do it your self. - -``` -progress = Progressbar(100, display=False) # display false stops the auto writing +progress = Progressbar(100, display=False) # Output manually for i in progress: - print(str(progress)) # using the to string will maunually write it + print(str(progress)) # Print progress bar + ... ``` -Maybe you dont want to use it as an iterable and you just want a progressbar. You can manually control its progress. Example, you want to view download progress: +
-``` -progress = Progressbar(download_size, unit=" MB/s") # create the object +## Documentation -... +### Progressbar -progress.__iter__() # This will start the clock and initiate the iterable +#### Constructor Arguments +| Name | Description | +|------------|---------------------------------------------| +| start | Iterator starting position | +| end | Iterator ending position | +| current | Current iteration position | +| step | Added to current index after each iteration | +| length | ASCII progress bar string length | +| units | Unit to append to progress rate | +| color | ANSI escape code to color progress bar | +| display | Automatically output to sdtout | +| bar_format | Custom progress bar format string | -... +#### Properties +| Name | Description | +|------------|----------------------------------------------------| +| elapsed | Time ellapsed since first iteration: mm:ss | +| percentage | Percentage of completion: 50% | +| bar | ASCII progress bar: \|==========\| | +| fraction | Position as a fraction: \[index/total\] | +| rate | Iterations per second: 2.00/s | +| eta | Estimated time until complete: mm:ss | -progress.current = 220 # set the curent progress ex. 200/1000 Mb downloaded -download_speed = progress.rate() # get any sort of stistics you may want, the download rate for exmple -print(progress) # display progress bar. Manually iterating the object it will not display automaticly -``` +#### Methods +| Name | Description | +|----------------------|----------------------------------------------| +| elapsed(self) | Elapsed time in seconds | +| estimated_time(self) | Estimated time until completion in seconds | +| fraction(self) | Create fraction string | +| generate_bar | Progress bar ASCII string | +| per_second | Calculate iteration rate per second as float | +| percentage | Percentage as a floating point | -This would print (Underscores to maintain spacing): +## License +Copyright © 2023 Zakary Timson | Available under the GNU General Public License -`00:53 20% [====________________] [ 200/1000] 3.75 Mb/s 03:32` - -### API -**Class: Progressbar** - -**Attributes** - -start - iterator starting position - -end - iterator ending position - -current - curent iteration - -step - number to be added to current each iteraton - -length - length of characters in the progress bar - -units - unit to append to rate - -color - ANSI escape code to change color of text - -display - automaticly display the to string with each iteration - -bar_format - string which dictates how things are displayed ex "{elapesed} - {eta}" could look like: 00:00 - 00:10. See the statistics portion to see what can be displayed - -**Available Statistics** - -elapsed - running time of iterator. displayed as: mm:ss - -percentage - percentage of completion. displayed as: 100% - -bar - the progress bar. displayed as: |==========| - -fraction - current / end. displayed as: [100/100] - -rate - iterations per second. displayed as: 2.00/s (unit can be changed, see units attribute) - -eta - estimated time until completion. displayed as: mm:ss - -**Methods** - -elapsed(self) - running time of iterator - -estimated_time(self) - estimated time until iterator completes - -fraction(self) - create string representing the fraction, complete over total - -generate_bar - generates the progress bar and returns string - -per_second - calculates the rate or speed of iterations per second - -percentage - floating point of completion - -### Bug Reporting - -Please submit bugs to the github [issue tracker](https://github.com/zaktimson/progressbar/issues) +See the [license](./LICENSE) for more information. diff --git a/ZProgressbar/ZProgressbar.py b/ZProgressbar/ZProgressbar.py deleted file mode 100644 index 1db4dcc..0000000 --- a/ZProgressbar/ZProgressbar.py +++ /dev/null @@ -1,140 +0,0 @@ -from time import time -from sys import stdout - - -class ZProgressbar: - """ - An iterable object that can display statics about its self such as time elapsed, percentage, progress as a fraction, - iterations per second, estimated time and can generate an ascii progressbar. - """ - - def __init__(self, start, end=None, step=1, length=20, unit="/s", color="\033[0;31m", display=True, - bar_format="{elapsed} {percentage} {bar} {rate} {eta}"): - """ - Create an iterable object with the following properties. If no end is specified the start is assumed the end. - :param start: starting position of iterator (inclusive) - :param end: ending position of iterator (exclusive) - :param step: how many integers to add each iteration - :param length: length of the progress bar (default is 20) - :param unit: unit to display with the rate (default is /s) - :param color: ANSI escape codes prepended to output to change color (default is \033[0;31m ) - :param display: automatically display statistics on every iteration (default True) - :param bar_format: format the way statistics are displayed. Components to display are: elapsed, percentage, bar, - fraction, rate and eta. These keywords are swapped out for the actual information. (default is - "{elapsed} {percentage} {bar} {rate} {eta}") - """ - if end is None: - self.start = 0 - self.end = start - else: - self.start = start - self.end = end - self.step = step - self.length = length - self.unit = unit - self.color = color - self.display = display - self.bar_format = bar_format - - def __iter__(self): - """ - initiate iterator which sets the starting point and gets the current time which is used for statistics - :return: returns the new object - """ - self.start_time = time() - self.current = self.start - return self - - def __next__(self): - """ - next overload. If display is true the latest stetistics are displayed - :return: The next number in iterator - """ - if self.display: - self.__restart_line() - stdout.write(str(self)) - stdout.flush() - if self.current >= self.end: - raise StopIteration - self.current += self.step - return self.current - self.step - - def __str__(self): - """ - displays the iterator as a string of statistics - :return: formatted string - """ - return self.color + self.bar_format.format(bar=self.generate_bar(), - elapsed=self.__time_format(self.elapsed()), - eta=self.__time_format(self.estimated_time()), - fraction=self.fraction(), - percentage=(str(int(self.percentage() * 100)) + "%").rjust(4), - rate=str(self.per_second()) + self.unit) - - def elapsed(self): - """ - calculate the time that has elapsed - :return: long elapsed time - """ - return time() - self.start_time - - def estimated_time(self): - """ - Use the current percentage and elapsed time to determine an ETA - :return: how much time is left - """ - try: - return self.elapsed() / self.percentage() - self.elapsed() - except ZeroDivisionError: - return 0 - - def fraction(self): - """ - create a fraction representing the progress and the end of the iterator - :return: string representing current/end of iterator - """ - return "%s/%d" % (str(self.current).rjust(len(str(self.end))), self.end) - - def generate_bar(self): - """ - creates an ascii progressbar - :return: string progressbar - """ - bar = "[{0}]".format(("=" * int(self.percentage() * self.length)).ljust(self.length)) - return bar - - def per_second(self): - """ - use the current number of iterations and the amount of elapsed time to determine how many iterations per second - :return: - """ - try: - return round(self.current / self.step / self.elapsed(), 2) - except ZeroDivisionError: - return 0 - - def percentage(self): - """ - use current position / (end - start) to calculate percentage of completion - :return: float of percentage to completion - """ - return self.current / (self.end - self.start) - - @staticmethod - def __restart_line(): - """ - Writes return carriage to stdout and flushes. This allows writing to the same line. - :return: None - """ - stdout.write('\r') - stdout.flush() - - @staticmethod - def __time_format(time_to_format): - """ - formats time to mm:ss - :param time_to_format: long to format - :return: string of time - """ - m, s = divmod(time_to_format, 60) - return "%02d:%02d" % (m, s) diff --git a/ZProgressbar/__init__.py b/ZProgressbar/__init__.py deleted file mode 100644 index ed0d2d0..0000000 --- a/ZProgressbar/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from ZProgressbar import ZProgressbar \ No newline at end of file diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/dist/ZProgressbar-1.0.tar.gz b/dist/ZProgressbar-1.0.tar.gz deleted file mode 100644 index 873de3a8af66c9896504332c6425738eeb48d6e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2279 zcmVF@cd?T2YH&mQW$KK@R>x&1nSS<7tr2W+2r*rRoHl5EdFV0WA z>3lI?oREu?N03}9DhN3doU3Ew?(1(K?tetyw*CL=<=@U;T>bT@NA&+<-uC~6hyM4R z|NrCiBU5xm6+QbW6EfndPp0E(?}{eOC-vCq)%v~O>pV%Qxbw-glthXNs<LZ{KJ9aFN@o7gBaD|Gbib6@^=#~+gF}502(`dRP z4EhtQKr=j9@9#WeXBpkVcDG7p(w|H=k=o`r8 zb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hpz@fec9MR09yq;5u0!bYujz_JcmNo_^!^f5^r0(ZF~CQre90e zsuQ){4Jm1COw%0(S(yT2A#eZg>S@n`G^@qSlex@EsJW|sMMH@$I5so0$_6qcyFqc% z8Pwnv??aX=@`efiEPfZ`3*YaA;G%yiuW7m}o)3H4UR|o;pbJQ^guNk1wb(dX(cVHz zroLM}D&tw0YpJuYnOO~Y)E;}P;bS>_91Y21Qq_+VqRRvVE>!n{@-aX{RViBG--5nR zu#D`z$L>FF@1T}mywe0^`1XVM@z-Gq&7)y31Z>!c84cz)9#0c}=2qK|(e(QDu^ZTM z@X$pkhb&L1e5Kz4lyN{)UceZ>I*?oS#jx)!!mb@ZH@gIEA!@}$nPHkj&pMekA*Wv^ zyBZF<)1Va~m3QkI+^E5ZCx-5h^^LMZ+y-ocWka~4C9HFIt|$V~Lv8=Y9Msh_XFq4C ztX5@D3zDns`Nq6mN}1a5sL6)f>~EhTentW)%cVmqL~OTf$e)fXO#t!5$khhleBdh+ zNsu~fEaK*hfPXQ=wWd85!3*6!R^KF|$G?c<@lIdGKkqnklaT1|irb%ik8iqVl_6>B zOSyB4Z!5DE6-Jl$t$nD2XuQAPrhtX|Zuc(bQD?&wa_)_LAlEyMeEiU`iwaiC%?fhf^Kfs-T|2ey;-v4{2XGh*Cw0Q3Q|AW2%@BEpkeCgk4b&2A{i4!MIoH%jf w#EBCpPMkP#;>3v)Cr+F=apJ^@6DLlbIC0{{i4!MIocs^T@2SrgBmhtV0LMa#ZU6uP diff --git a/setup.py b/setup.py deleted file mode 100644 index 52ef45a..0000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -from distutils.core import setup -setup( - name = 'ZProgressbar', - packages = ['ZProgressbar'], - version = '1.2', - description = 'An iterator that can be displayed as an Ascii progress bar as well as display statistics like speed, progress and estimated time', - author = 'Zak Timson', - author_email = 'zaktimson@gmail.com', - url = 'https://github.com/zaktimson/progressbar', - download_url = 'https://github.com/zaktimson/progressbar/tarball/1.2', - keywords = ['iterator', 'progressbar', 'estimated time', 'timer'], - classifiers = [], -) \ No newline at end of file