-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding lscolumns to the retriever explicitly, since there are still w…
…eird install issues.
- Loading branch information
1 parent
31a7d8e
commit a480a74
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
from term_size import get_terminal_size | ||
|
||
|
||
def get_columns(values, cols): | ||
columns = [] | ||
col_size = len(values) / cols | ||
extra = len(values) % cols | ||
n = 0 | ||
for i in range(cols): | ||
s = col_size | ||
if i+1 <= extra: s += 1 | ||
this_column = values[n:n+s] | ||
columns.append(this_column) | ||
n += s | ||
return columns | ||
|
||
|
||
def printls(values, max_width=None, spacing=2): | ||
if sys.stdout.isatty() and max_width is None: | ||
cols,lines = get_terminal_size() | ||
max_width = cols | ||
|
||
if max_width: | ||
# if output to terminal or max_width is specified, use column output | ||
|
||
for cols in [int(len(values) / float(i) + 0.5) for i in range(1, len(values) + 1)]: | ||
columns = get_columns(values, cols) | ||
widths = [max([len(c) for c in column])+spacing for column in columns] | ||
if sum(widths) < max_width: | ||
break | ||
|
||
for pos in range(len(columns[0])): | ||
for column, width in zip(columns, widths): | ||
if len(column) > pos: | ||
print column[pos].ljust(width-1), | ||
|
||
else: | ||
# otherwise, just output each value, one per line | ||
for value in values: print value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,6 @@ def clean_version(v): | |
}, | ||
install_requires=[ | ||
'xlrd', | ||
'lscolumns', | ||
], | ||
|
||
# py2exe flags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
def get_terminal_size(): | ||
env = os.environ | ||
def ioctl_GWINSZ(fd): | ||
try: | ||
import fcntl, termios, struct, os | ||
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, | ||
'1234')) | ||
except: | ||
return | ||
return cr | ||
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) | ||
if not cr: | ||
try: | ||
fd = os.open(os.ctermid(), os.O_RDONLY) | ||
cr = ioctl_GWINSZ(fd) | ||
os.close(fd) | ||
except: | ||
pass | ||
if not cr: | ||
cr = (env.get('LINES', 25), env.get('COLUMNS', 80)) | ||
|
||
return int(cr[1]), int(cr[0]) |