From: Michael Tremer Date: Fri, 5 Dec 2025 16:31:58 +0000 (+0000) Subject: dnsbl: Add a command to show information about a list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7641a2c38cd016a2c93a01c2eb6dc7daf2f0230d;p=dbl.git dnsbl: Add a command to show information about a list Signed-off-by: Michael Tremer --- diff --git a/configure.ac b/configure.ac index faaaf23..5f232b1 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ AC_PROG_MKDIR_P # Python AM_PATH_PYTHON([3.13]) +AX_PYTHON_MODULE([rich], [fatal]) AX_PYTHON_MODULE([sqlmodel], [fatal]) # ------------------------------------------------------------------------------ diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index a771ba7..04eaf94 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -23,12 +23,18 @@ import argparse import dnsbl import logging import os +import rich.console +import rich.table import sys # i18n from dnsbl.i18n import _ class CLI(object): + def __init__(self): + # Initialize the console + self.console = rich.console.Console() + def parse_cli(self): """ Main Function. @@ -56,6 +62,11 @@ class CLI(object): help=_("The license of the list")) list_create.set_defaults(func=self.__list_create) + # list-show + list_show = subparsers.add_parser("list-show", help=_("Shows details about a list")) + list_show.add_argument("list", help=_("The name of the list")) + list_show.set_defaults(func=self.__list_show) + # list-add-source list_add_source = subparsers.add_parser("list-add-source", help=_("Creates a new source to a list")) @@ -120,6 +131,44 @@ class CLI(object): license = args.license, ) + def __list_show(self, backend, args): + """ + Shows information about a list + """ + list = backend.lists.get_by_slug(args.list) + + table = rich.table.Table(title=list.name) + table.add_column(_("Property")) + table.add_column(_("Value")) + + table.add_row(_("Name"), list.name) + table.add_row(_("License"), list.license) + table.add_row(_("Created At"), list.created_at.isoformat()) + table.add_row(_("Created By"), list.created_by) + + # Print list properties + self.console.print(table) + + # Show all sources + table = rich.table.Table(title=_("Sources")) + table.add_column(_("Name")) + table.add_column(_("License")) + table.add_column(_("URL")) + table.add_column(_("Created At")) + table.add_column(_("Created_By")) + + for source in list.sources: + table.add_row( + source.name, + source.license, + source.url, + source.created_at.isoformat(), + source.created_by, + ) + + # Print the sources + self.console.print(table) + def __list_add_source(self, backend, args): """ Adds a new source to a list