Skip to content

Commit 3e90aa7

Browse files
committed
Made code comply to PEP8 and work with python3.
1 parent 99d8cf3 commit 3e90aa7

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pep8:
2+
pep8 --filename=*.py --exclude=.tox,build
3+
4+
pyflakes:
5+
pyflakes *.py
6+
7+
audit: pep8 pyflakes
8+
9+
clean:
10+
rm -vfr dist *.egg-info *.pyc __pycache__ build .coverage htmlcov \
11+
testsuite/*.pyc testsuite/__pycache__
12+

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import re
32
from setuptools import setup
43

@@ -24,7 +23,6 @@
2423
py_modules=['whiptail'],
2524
namespace_packages=[],
2625
include_package_data=True,
27-
install_requires=['utile>=0.1'],
2826
classifiers=[
2927
'Development Status :: 5 - Production/Stable',
3028
'Environment :: Console',

tox.ini

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tox]
2+
envlist = py27, py32, py33
3+
4+
[testenv]
5+
commands =
6+
python setup.py install
7+
8+

whiptail.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,42 @@
22
# Copyright (C) 2013 Marwan Alsabbagh
33
# license: BSD, see LICENSE for more details.
44

5-
__version__ = '0.2.dev'
6-
5+
from __future__ import print_function
76
import sys
87
import shlex
9-
from utile import save_args, flatten
8+
import itertools
109
from subprocess import Popen, PIPE
1110
from collections import namedtuple
1211

12+
__version__ = '0.2.dev'
13+
PY3 = sys.version_info[0] == 3
14+
string_types = str if PY3 else basestring
1315
Response = namedtuple('Response', 'returncode value')
1416

1517

18+
def flatten(data):
19+
return list(itertools.chain.from_iterable(data))
20+
21+
1622
class Whiptail(object):
17-
@save_args
18-
def __init__(self, title='', backtitle='', height=10, width=50, auto_exit=True):
19-
pass
23+
def __init__(self, title='', backtitle='', height=10, width=50,
24+
auto_exit=True):
25+
self.title = title
26+
self.backtitle = backtitle
27+
self.height = height
28+
self.width = width
29+
self.auto_exit = auto_exit
2030

2131
def run(self, control, msg, extra=(), exit_on=(1, 255)):
22-
cmd = ['whiptail', '--title', self.title, '--backtitle', self.backtitle,
23-
'--' + control, msg, str(self.height), str(self.width)] + list(extra)
32+
cmd = [
33+
'whiptail', '--title', self.title, '--backtitle', self.backtitle,
34+
'--' + control, msg, str(self.height), str(self.width)
35+
]
36+
cmd += list(extra)
2437
p = Popen(cmd, stderr=PIPE)
2538
out, err = p.communicate()
2639
if self.auto_exit and p.returncode in exit_on:
27-
print 'User cancelled operation.'
40+
print('User cancelled operation.')
2841
sys.exit(p.returncode)
2942
return Response(p.returncode, err)
3043

@@ -47,15 +60,15 @@ def calc_height(self, msg):
4760
return [str(self.height - height_offset)]
4861

4962
def menu(self, msg='', items=(), prefix=' - '):
50-
if isinstance(items[0], basestring):
63+
if isinstance(items[0], string_types):
5164
items = [(i, '') for i in items]
5265
else:
5366
items = [(k, prefix + v) for k, v in items]
5467
extra = self.calc_height(msg) + flatten(items)
5568
return self.run('menu', msg, extra).value
5669

5770
def showlist(self, control, msg, items, prefix):
58-
if isinstance(items[0], basestring):
71+
if isinstance(items[0], string_types):
5972
items = [(i, '', 'OFF') for i in items]
6073
else:
6174
items = [(k, prefix + v, s) for k, v, s in items]

0 commit comments

Comments
 (0)