Skip to content
This repository has been archived by the owner on Nov 12, 2017. It is now read-only.

Commit

Permalink
Merge branch 'development' of github.com:RealOrangeOne/Printr
Browse files Browse the repository at this point in the history
  • Loading branch information
RealOrangeOne committed Oct 8, 2015
2 parents d0b5eee + 97a54b6 commit 7a4aed9
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ target/


# Other
MANIFEST
MANIFEST
README.rst
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion convert-readme.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pandoc --from=markdown --to=rst --output=README README.md
pandoc --from=markdown --to=rst --output=README.rst README.md
18 changes: 9 additions & 9 deletions details.json
Original file line number Diff line number Diff line change
@@ -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"]
}
32 changes: 32 additions & 0 deletions printr/EllipsisPrintr/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 10 additions & 4 deletions printr/itterPrintr.py → printr/ItterPrintr/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,16 +12,18 @@ def __init__(self, string, maxValue, start, diff=1):
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
16 changes: 6 additions & 10 deletions printr/__init__.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
23 changes: 0 additions & 23 deletions printr/ellipsisPrintr.py

This file was deleted.

5 changes: 5 additions & 0 deletions printr/exceptions.py
Original file line number Diff line number Diff line change
@@ -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)

11 changes: 0 additions & 11 deletions printr/simplePrintr.py

This file was deleted.

6 changes: 6 additions & 0 deletions printr/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def write(string, commit=False):
ending = '\n' if commit else '\r'
print(string, end=ending)

def commit():
print()
23 changes: 11 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -8,17 +8,16 @@

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 changes: 7 additions & 0 deletions tests/context_manager.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7a4aed9

Please sign in to comment.