Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #15631: Rudder-pkg prints tables on a dict base source, which lead to unconsistent columns ordering #2439

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions relay/sources/rudder-pkg/lib/rudder-pkg/rudderPkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ def package_list_installed():
else:
latestRelease.append("")

table = { "Plugin Name" : pluginName,
"Version" : version,
}
table = [
{ "title": "Plugin Name", "value": pluginName },
{ "title": "Version" , "value": version },
]
if printLatest:
table["Latest release"] = latestRelease
table.append({ "title": "Latest release", "value": latestRelease })
print(utils.dictToAsciiTable(table))

"""
Expand All @@ -87,10 +88,11 @@ def package_list_name():
pluginName.append(str(p))
shortName.append(str(pluginDict[p][0]))
description.append(str(pluginDict[p][1]))
table = { "Plugin Name" : pluginName,
"Plugin Short Name" : shortName,
"Description" : description,
}
table = [
{ "title": "Plugin Name" , "value": pluginName },
{ "title": "Plugin Short Name", "value": shortName },
{ "title": "Description" , "value": description },
]
print(utils.dictToAsciiTable(table))

"""
Expand Down Expand Up @@ -133,11 +135,12 @@ def package_search(name):
version.append(data[2])
compatible.append(data[3])

table = { "Plugin Name" : pluginName,
"Release Mode" : releaseMode,
"Version" : version,
"Compatible" : compatible,
}
table = [
{ "title": "Plugin Name" , "value": pluginName },
{ "title": "Release Mode", "value": releaseMode },
{ "title": "Version" , "value": version },
{ "title": "Compatible" , "value": compatible },
]
print(utils.dictToAsciiTable(table))

"""
Expand Down
22 changes: 12 additions & 10 deletions relay/sources/rudder-pkg/lib/rudder-pkg/rudderPkgUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ def createPath(path):
fail("Could not create dir %s"%(path))
"""
Print dict list in a fancy manner
Assume the dict is following the format:
{ "strkey1" : [ "str", "str2", ... ],
"strkey2" : [ "str", "str2", ... ],
}
Assume the list is following the format:
[
{ "title": "strkey1", "value" : [ "str", "str2", ... ] },
{ "tilte": "strkey2", "value" : [ "str", "str2", ... ] },
...
]
"""
def dictToAsciiTable(data):
# Get maximum text length to print
lengths = [ len(max(data.get(k) + [k], key=len)) for k in data.keys() ]
lengths = [ len(max([column["title"]] + column["value"], key=len)) for column in data ]
lenstr = "| " + " | ".join("{:<%s}" % m for m in lengths) + " |"
lenstr += "\n"

Expand All @@ -117,16 +119,16 @@ def dictToAsciiTable(data):
sepBar += "+" + "-" * (int(iSep) + 2)
sepBar += "+\n"

outmsg = sepBar + lenstr.format(*data.keys()) + sepBar
outmsg = sepBar + lenstr.format(*[column["title"] for column in data]) + sepBar

# Write rows, at least an empty one if everything is empty
printedRows = 0
maxRows = max([len(data.get(k)) + 1 for k in data.keys()])
maxRows = max([len(column["value"]) + 1 for column in data])
while True:
row = []
for k in data.keys():
if len(data.get(k)) > printedRows:
row.append(data.get(k)[printedRows])
for column in data:
if len(column["value"]) > printedRows:
row.append(column["value"][printedRows])
else:
row.append("")
outmsg += lenstr.format(*row)
Expand Down