archive
/
Printr
Archived
1
Fork 0

Merge branch 'development' of github.com:RealOrangeOne/Printr

This commit is contained in:
Jake Howard 2015-10-08 22:31:35 +01:00
commit 7a4aed96c0
13 changed files with 101 additions and 72 deletions

3
.gitignore vendored
View File

@ -58,4 +58,5 @@ target/
# Other
MANIFEST
MANIFEST
README.rst

View File

@ -4,10 +4,21 @@ 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.3
```
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.

View File

@ -1 +1 @@
pandoc --from=markdown --to=rst --output=README README.md
pandoc --from=markdown --to=rst --output=README.rst README.md

View File

@ -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.3",
"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"]
}

View File

@ -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()

View File

@ -1,3 +1,7 @@
from printr.exceptions import FormattingError
from printr.utils import write
class ItterPrintr():
def __init__(self, string, maxValue, start, diff=1):
self.string = string
@ -8,16 +12,18 @@ 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
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()
def inc(self):
self.value += self.diff
self.value += self.diff

View File

@ -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():

View File

@ -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')

5
printr/exceptions.py Normal file
View File

@ -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)

View File

@ -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()

6
printr/utils.py Normal file
View File

@ -0,0 +1,6 @@
def write(string, commit=False):
ending = '\n' if commit else '\r'
print(string, end=ending)
def commit():
print()

View File

@ -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']
)

7
tests/context_manager.py Normal file
View File

@ -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)