From 1c6cefcfba1a1d382fdd5e854c90692701bf4f17 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 26 Sep 2015 21:50:36 +0100 Subject: [PATCH 1/7] Added error --- printr/itterPrintr.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/printr/itterPrintr.py b/printr/itterPrintr.py index fff155a..c179eb5 100644 --- a/printr/itterPrintr.py +++ b/printr/itterPrintr.py @@ -1,3 +1,9 @@ +class FormattingException(Exception): + message = "Provided string doesn't contain formatting placeholders for {c} and/or {m}" + def __init__(self): + super().__init__(self.message) + + class ItterPrintr(): def __init__(self, string, maxValue, start, diff=1): self.string = string @@ -8,7 +14,10 @@ class ItterPrintr(): self.buildString() def buildString(self): - return self.string.format(c=self.value, m=self.maxValue) + try: + return self.string.format(c=self.value, m=self.maxValue) + except: + raise FormattingError() def reachedLimit(self): return self.maxValue <= self.value @@ -20,4 +29,4 @@ class ItterPrintr(): self.inc() def inc(self): - self.value += self.diff + self.value += self.diff \ No newline at end of file From dd83e3143aa0c20a4e421df4ba19b4479be7c3ab Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 28 Sep 2015 21:05:31 +0100 Subject: [PATCH 2/7] Changed readme information --- .gitignore | 3 ++- README | 18 ------------------ README.md | 11 ++++++++++- 3 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 README diff --git a/.gitignore b/.gitignore index 6db6608..9ce7e8f 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,5 @@ target/ # Other -MANIFEST \ No newline at end of file +MANIFEST +README.rst \ No newline at end of file diff --git a/README b/README deleted file mode 100644 index 2244dd6..0000000 --- a/README +++ /dev/null @@ -1,18 +0,0 @@ -Printr -====== - -Printr is a simple PyPi module that allows for print statements to be -replaces with a new line. Particularly useful for displaying progress -messages. - -Installation ------------- - -Installation can be done using pip in the standard way; - -:: - - pip install python-printr - -If you have python 3 installed, then install using ``pip3``. There are -no dependancies for this package, so installation should go ahead fine. diff --git a/README.md b/README.md index fd9acc3..299924c 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,19 @@ Printr is a simple PyPi module that allows for print statements to be replaces w ## Installation -Installation can be done using pip in the standard way; +Installation can be done using pip in the standard way: ``` pip install python-printr ``` If you have python 3 installed, then install using `pip3`. There are no dependancies for this package, so installation should go ahead fine. +Alternatively, you can download directly from Pypi [here](https://pypi.python.org/pypi/Python-Printr/). +## Usage +``` +import printr + +printr.get_version() +>>> 0.0.1 +``` +The printr module contains various different printrs to assist you. You can find more information about these printrs on the wiki. \ No newline at end of file From 0baaaf60842418a718da88cc27ea970841def7a2 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 28 Sep 2015 21:08:20 +0100 Subject: [PATCH 3/7] Changed details and readme format --- convert-readme.sh | 2 +- details.json | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/convert-readme.sh b/convert-readme.sh index 6c4fcce..025c0a1 100644 --- a/convert-readme.sh +++ b/convert-readme.sh @@ -1 +1 @@ -pandoc --from=markdown --to=rst --output=README README.md \ No newline at end of file +pandoc --from=markdown --to=rst --output=README.rst README.md \ No newline at end of file diff --git a/details.json b/details.json index da0c39f..2cd76b8 100644 --- a/details.json +++ b/details.json @@ -1,11 +1,11 @@ { - 'name' : 'Python-Printr', - 'packages' : ['printr'], - 'version' : '0.0.1', - 'description' : 'Python module to allow a print line to be updated after printing', - 'author' : 'Jake Howard', - 'author_email' : 'me@theorangeone.net ', - 'url' : 'https://github.com/RealOrangeOne/Printr', - 'license':'MIT', - 'platforms':['any'] + "name" : "Python-Printr", + "packages" : ["printr"], + "version" : "0.0.1", + "description" : "Python module to allow a print line to be updated after printing", + "author" : "Jake Howard", + "author_email" : "me@theorangeone.net ", + "url" : "https://github.com/RealOrangeOne/Printr", + "license":"MIT", + "platforms":["any"] } \ No newline at end of file From 33b3db6dce5f830018eb3b8535dd49e11b5b032d Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 28 Sep 2015 21:13:31 +0100 Subject: [PATCH 4/7] Added seperate exceptions file --- printr/exceptions.py | 5 +++++ printr/itterPrintr.py | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 printr/exceptions.py diff --git a/printr/exceptions.py b/printr/exceptions.py new file mode 100644 index 0000000..cca1126 --- /dev/null +++ b/printr/exceptions.py @@ -0,0 +1,5 @@ +class FormattingError(Exception): + message = "Provided string doesn't contain formatting placeholders for {c} and/or {m}" + def __init__(self): + super().__init__(self.message) + diff --git a/printr/itterPrintr.py b/printr/itterPrintr.py index c179eb5..08de82a 100644 --- a/printr/itterPrintr.py +++ b/printr/itterPrintr.py @@ -1,7 +1,4 @@ -class FormattingException(Exception): - message = "Provided string doesn't contain formatting placeholders for {c} and/or {m}" - def __init__(self): - super().__init__(self.message) +from exceptions import FormattingError class ItterPrintr(): From bc9b9d3762829d150cd8322611f7fc3a919df790 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 28 Sep 2015 21:17:01 +0100 Subject: [PATCH 5/7] JSON Formatting --- details.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/details.json b/details.json index 2cd76b8..6191b39 100644 --- a/details.json +++ b/details.json @@ -1,11 +1,11 @@ { - "name" : "Python-Printr", - "packages" : ["printr"], - "version" : "0.0.1", - "description" : "Python module to allow a print line to be updated after printing", - "author" : "Jake Howard", - "author_email" : "me@theorangeone.net ", - "url" : "https://github.com/RealOrangeOne/Printr", - "license":"MIT", - "platforms":["any"] + "name": "Python-Printr", + "packages": ["printr"], + "version": "0.0.1", + "description": "Python module to allow a print line to be updated after printing", + "author": "Jake Howard", + "author_email": "me@theorangeone.net ", + "url": "https://github.com/RealOrangeOne/Printr", + "license": "MIT", + "platforms": ["any"] } \ No newline at end of file From 1329866b2c5fddcc9951b86aa678bb704f96c629 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 8 Oct 2015 15:39:22 +0100 Subject: [PATCH 6/7] Large restructure --- printr/EllipsisPrintr/__init__.py | 32 +++++++++++++++++++ .../__init__.py} | 6 ++-- printr/__init__.py | 16 ++++------ printr/ellipsisPrintr.py | 23 ------------- printr/simplePrintr.py | 11 ------- printr/utils.py | 6 ++++ setup.py | 23 +++++++------ tests/context_manager.py | 7 ++++ 8 files changed, 65 insertions(+), 59 deletions(-) create mode 100644 printr/EllipsisPrintr/__init__.py rename printr/{itterPrintr.py => ItterPrintr/__init__.py} (76%) delete mode 100644 printr/ellipsisPrintr.py delete mode 100644 printr/simplePrintr.py create mode 100644 printr/utils.py create mode 100644 tests/context_manager.py diff --git a/printr/EllipsisPrintr/__init__.py b/printr/EllipsisPrintr/__init__.py new file mode 100644 index 0000000..5229888 --- /dev/null +++ b/printr/EllipsisPrintr/__init__.py @@ -0,0 +1,32 @@ +from printr.utils import write + +class EllipsisPrintr(): + def __init__(self, string, max=3, erase_after=False): + self.string = string + self.max = max + self.count = -1 + self.erase_after = erase_after + + def update(self, commit=False): + self.clear() + ellipsis = "." * self.count + write(self.string + ellipsis, commit=commit) + if self.count >= self.max: + self.zero() + self.count += 1 + + def zero(self): + self.count = -1 + + def commit(self): + print() + + def clear(self): + print(' ' * (len(self.string) + self.max), end='\r') + + def __enter__(self): + return self + def __exit__(self, type, value, traceback): + if self.erase_after: + self.clear() + self.commit() \ No newline at end of file diff --git a/printr/itterPrintr.py b/printr/ItterPrintr/__init__.py similarity index 76% rename from printr/itterPrintr.py rename to printr/ItterPrintr/__init__.py index 08de82a..0ff24fc 100644 --- a/printr/itterPrintr.py +++ b/printr/ItterPrintr/__init__.py @@ -1,4 +1,5 @@ -from exceptions import FormattingError +from printr.exceptions import FormattingError +from printr.utils import write class ItterPrintr(): @@ -20,8 +21,7 @@ class ItterPrintr(): return self.maxValue <= self.value def update(self, inc=True): - ending = '\r' if not self.reachedLimit() else '\n' - print(self.buildString(), end=ending) + write(self.buildString(), commit=(not self.reachedLimit())) if inc: self.inc() diff --git a/printr/__init__.py b/printr/__init__.py index dbc1e59..540259b 100644 --- a/printr/__init__.py +++ b/printr/__init__.py @@ -1,17 +1,13 @@ -# Import python modules import os -from json import loads as json_loads +from json import load as json_load -# Import Printr Modules -from .simplePrintr import SimplePrintr -from .itterPrintr import ItterPrintr -from .ellipsisPrintr import EllipsisPrintr - -# Initialise PRINTR_PATH = os.path.dirname(os.path.abspath(__file__)) -with open(PRINTR_PATH + '/details.json') as file: - PRINTR_DETAILS = json_loads(file) +from .ItterPrintr import ItterPrintr +from .EllipsisPrintr import EllipsisPrintr + +with open(PRINTR_PATH + '/../details.json') as file: + PRINTR_DETAILS = json_load(file) def get_version(): diff --git a/printr/ellipsisPrintr.py b/printr/ellipsisPrintr.py deleted file mode 100644 index f257bf6..0000000 --- a/printr/ellipsisPrintr.py +++ /dev/null @@ -1,23 +0,0 @@ -class EllipsisPrintr(): - def __init__(self, string, max=5): - self.string = string - self.max = max - self.count = -1 - - def update(self, commit=False): - self.clear() - ellipsis = "." * self.count - ending = '\r' if not commit else '\n' - print(self.string + ellipsis, end=ending) - if self.count >= self.max: - self.zero() - self.count += 1 - - def zero(self): - self.count = -1 - - def commit(self): - print() - - def clear(self): - print(' ' * (len(self.string) + self.max), end='\r') \ No newline at end of file diff --git a/printr/simplePrintr.py b/printr/simplePrintr.py deleted file mode 100644 index bce5911..0000000 --- a/printr/simplePrintr.py +++ /dev/null @@ -1,11 +0,0 @@ -class SimplePrintr(): - @classmethod - def write(string, commit=False): - if commit: - print(string) - else: - print(string, end='\r') - - @classmethod - def commit(): - print() \ No newline at end of file diff --git a/printr/utils.py b/printr/utils.py new file mode 100644 index 0000000..53d3e0a --- /dev/null +++ b/printr/utils.py @@ -0,0 +1,6 @@ +def write(string, commit=False): + ending = '\n' if commit else '\r' + print(string, end=ending) + +def commit(): + print() \ No newline at end of file diff --git a/setup.py b/setup.py index 8bbee43..a97ef88 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ from distutils.core import setup -from json import loads as json_loads +from json import load as json_load LONG_DESCRIPTION = None try: LONG_DESCRIPTION = open('README.md').read() @@ -8,17 +8,16 @@ except: DETAILS = None with open('details.json') as file: - DETAILS = json_loads(file) - + DETAILS = json_load(file) setup( - name = DETAILS.name, - packages = DETAILS.packages, - version = DETAILS.version, - description = DETAILS.description, + name = DETAILS['name'], + packages = DETAILS['packages'], + version = DETAILS['version'], + description = DETAILS['description'], long_description = LONG_DESCRIPTION, - author = DETAILS.author, - author_email = DETAILS.author_email, - url = DETAILS.url, - license = DETAILS.license, - platforms = DETAILS.platform + author = DETAILS['author'], + author_email = DETAILS['author_email'], + url = DETAILS['url'], + license = DETAILS['license'], + platforms = DETAILS['platforms'] ) \ No newline at end of file diff --git a/tests/context_manager.py b/tests/context_manager.py new file mode 100644 index 0000000..de70e80 --- /dev/null +++ b/tests/context_manager.py @@ -0,0 +1,7 @@ +from printr import EllipsisPrintr +from time import sleep + +with EllipsisPrintr('Printing') as p: + for i in range(30): + p.update() + sleep(0.1) From 97a54b6cffb570b7a91b3c4dc994bdc40c22258d Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 8 Oct 2015 22:25:40 +0100 Subject: [PATCH 7/7] Update version --- README.md | 6 ++++-- details.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 299924c..5ab857b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Alternatively, you can download directly from Pypi [here](https://pypi.python.or import printr printr.get_version() ->>> 0.0.1 +>>> 0.0.3 ``` -The printr module contains various different printrs to assist you. You can find more information about these printrs on the wiki. \ No newline at end of file +The printr module contains various different printrs to assist you. You can find more information about these printrs on the wiki. + +The main reason I wrote this project was to simplify status output for my projects, and because I'd never written a PyPi package before. \ No newline at end of file diff --git a/details.json b/details.json index 6191b39..2d4f862 100644 --- a/details.json +++ b/details.json @@ -1,7 +1,7 @@ { "name": "Python-Printr", "packages": ["printr"], - "version": "0.0.1", + "version": "0.0.3", "description": "Python module to allow a print line to be updated after printing", "author": "Jake Howard", "author_email": "me@theorangeone.net ",