#!/usr/bin/env python3
#
# Copyright © 2019-2020 Adélie Linux team. All rights reserved.
# NCSA license.
#
import subprocess
class _Cell:
def __init__(self, content):
self.content = content
_ANSI_CLEAR = "\033[0;00m"
class Yes(_Cell):
symbol = "✓"
cls = "cell-yes"
color = "\033[1;32m"
class No(_Cell):
symbol = "✗"
cls = "cell-no"
color = "\033[1;31m"
class Partial(_Cell):
symbol = "?"
cls = "cell-partial"
color = "\033[1;33m"
PARTIAL_MISSING = Partial("missing")
YES_MISSING = Yes("missing")
_HEADER = r"""
APKINDEX analysis - {date}
APKINDEX analysis - {date}
Base URL: {url}
Repositories: {repos}
Architectures: {arches}
"""
_FOOTER = r"""
"""
def format_tab(_, rows):
for row in rows:
for i, j in enumerate(row):
if isinstance(j, _Cell):
row[i] = f"{j.symbol} {j.content}"
print(*row, sep="\t")
def format_pretty(_, rows):
proc = subprocess.Popen(
("column", "-ts", "\t"),
stdin=subprocess.PIPE,
encoding="utf-8",
)
for row in rows:
for i, j in enumerate(row):
if isinstance(j, _Cell):
row[i] = f"{j.color}{j.symbol} {j.content}{_ANSI_CLEAR}"
else:
# Work around column(1) not liking ANSI escapes by
# always printing some
row[i] = f"{_ANSI_CLEAR}{j}{_ANSI_CLEAR}"
print(*row, file=proc.stdin, sep="\t")
proc.communicate()
def format_html(opts, rows):
print(_HEADER)
first = True
for row in rows:
if first:
print("")
print(
"",
" | ".join(row),
" |
", sep=""
)
print("")
first = False
continue
for i, j in enumerate(row[1:]):
i += 1
if isinstance(j, _Cell):
row[i] = f" class='{j.cls}'>{j.symbol} {j.content}"
else:
row[i] = ">" + j
print("", " | |
", sep="")
if not first:
print("")
print("
")
print(_FOOTER)
FORMATTERS = {
"tab": format_tab,
"pretty": format_pretty,
"html": format_html,
}