Skip to content

Commit

Permalink
add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
sirfoga committed Apr 24, 2018
1 parent 6faeaf8 commit eaef6a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
27 changes: 24 additions & 3 deletions hal/streams/pretty_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

""" Pretty prints table in SQL style """

from pyparsing import Literal, Word, nums, Combine, Optional, delimitedList, \
alphas, oneOf, Suppress


def get_optimal_column_widths(labels, data):
"""
Expand All @@ -29,8 +32,9 @@ def get_optimal_column_widths(labels, data):
"""

columns = len(data[0]) # number of columns
str_labels = [str(l) for l in labels] # labels as strings
str_data = [[str(col) for col in row] for row in data] # values as strings
str_labels = [parse_colorama(str(l)) for l in labels] # labels as strings
str_data = [[parse_colorama(str(col)) for col in row] for row in data]
# values as strings

widths = [0] * columns # length of longest string in each column
for row in str_data: # calculate max width in each column
Expand Down Expand Up @@ -60,7 +64,7 @@ def get_pretty_row(data, widths, filler, splitter):

row = [str(d) for d in data]
for i, val in enumerate(row):
length_diff = widths[i] - len(val)
length_diff = widths[i] - len(parse_colorama(val))
if length_diff > 0: # value is shorter than foreseen
row[i] = str(filler * length_diff) + row[i] # adjust content
pretty_row = splitter # start of row
Expand Down Expand Up @@ -131,3 +135,20 @@ def pretty_format_table(labels, data, line_separator="\n"):
pretty_table += pretty_format_row(row, widths) + line_separator
pretty_table += get_blank_row(widths) # ending line
return pretty_table


def parse_colorama(text):
"""
:param text: str
Colorama text to parse
:return: str
Parsed colorama text
"""

esc_key = Literal('\x1b')
integer = Word(nums)
escape_seq = Combine(
esc_key + '[' + Optional(delimitedList(integer, ';')) +
oneOf(list(alphas)))
non_ansi_string = lambda s: Suppress(escape_seq).transformString(s)
return non_ansi_string(text)
19 changes: 19 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# coding: utf_8

# Copyright 2017-2018 Stefano Fogarollo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


pip3 install . --upgrade --force-reinstall

0 comments on commit eaef6a6

Please sign in to comment.