diff options
| author | Arno Bauernöppel <https://github.com/gronkern> | 2022-07-08 20:36:17 -0700 |
|---|---|---|
| committer | Brian Dolbec <dolsen@gentoo.org> | 2022-07-08 20:39:50 -0700 |
| commit | 3e35553df4673ed05615adc088fdbbc3f212c876 (patch) | |
| tree | c8a7da42e5f9a837f310fd92ea2093e01bfeea4e /pym | |
| parent | 6a9be2d05751558d7d34e900dfc06a721278b447 (diff) | |
| download | gentoolkit-3e35553df4673ed05615adc088fdbbc3f212c876.tar.gz | |
equery: Add -F TMPL option to depends module
Like in other modules it is now possible to format the
output of the equery module 'depends' with the commandline
switch '-F' and TMPL.
The man page was adujusted.
A new static method 'print_formated' was created.
In method 'format_depend' is checked if the new option is present.
Depending on the check the PackageFormatter is used to display
the dependencies.
manually apply github PR, some minor editing.
Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
Diffstat (limited to 'pym')
| -rw-r--r-- | pym/gentoolkit/equery/depends.py | 76 |
1 files changed, 54 insertions, 22 deletions
diff --git a/pym/gentoolkit/equery/depends.py b/pym/gentoolkit/equery/depends.py index 581e2b6..93f0ec1 100644 --- a/pym/gentoolkit/equery/depends.py +++ b/pym/gentoolkit/equery/depends.py @@ -18,7 +18,7 @@ from gentoolkit.dependencies import Dependencies from gentoolkit.equery import format_options, mod_usage, CONFIG from gentoolkit.helpers import get_cpvs, get_installed_cpvs from gentoolkit.cpv import CPV - +from gentoolkit.package import PackageFormatter, FORMAT_TMPL_VARS # ======= # Globals # ======= @@ -27,6 +27,7 @@ QUERY_OPTS = { "include_masked": False, "only_direct": True, "max_depth": -1, + "package_format": None, } # ======= @@ -61,6 +62,26 @@ class DependPrinter: pp.uprint(indent + cpv) + @staticmethod + def print_formated(pkg): + """Print pkg as formatted output depending on CONFIG.""" + + if pkg is None: + return + + if CONFIG['verbose']: + print (PackageFormatter( + pkg, + do_format=True, + custom_format=QUERY_OPTS["package_format"] + )) + else: + print (PackageFormatter( + pkg, + do_format=False, + custom_format=QUERY_OPTS["package_format"] + )) + def format_depend(self, dep, dep_is_displayed): """Format a dependency for printing. @@ -76,27 +97,34 @@ class DependPrinter: indent = " " * depth mdep = dep.matching_dep use_conditional = "" - if mdep.use_conditional: - use_conditional = " & ".join( - pp.useflag(u) for u in mdep.use_conditional.split() - ) - if mdep.operator == "=*": - formatted_dep = "=%s*" % str(mdep.cpv) - else: - formatted_dep = mdep.operator + str(mdep.cpv) - if mdep.slot: - formatted_dep += pp.emph(":") + pp.slot(mdep.slot) - if mdep.sub_slot: - formatted_dep += pp.slot("/") + pp.slot(mdep.sub_slot) - if mdep.use: - useflags = pp.useflag(",".join(mdep.use.tokens)) - formatted_dep += pp.emph("[") + useflags + pp.emph("]") - - if dep_is_displayed: - indent = indent + " " * len(str(dep.cpv)) - self.print_fn(indent, "", use_conditional, formatted_dep) + + if QUERY_OPTS["package_format"] != None: + pkg = Package(str(dep.cpv)) + self.print_formated(pkg) else: self.print_fn(indent, str(dep.cpv), use_conditional, formatted_dep) + if mdep.use_conditional: + use_conditional = " & ".join( + pp.useflag(u) for u in mdep.use_conditional.split() + ) + if mdep.operator == '=*': + formatted_dep = '=%s*' % str(mdep.cpv) + else: + formatted_dep = mdep.operator + str(mdep.cpv) + if mdep.slot: + formatted_dep += pp.emph(':') + pp.slot(mdep.slot) + if mdep.sub_slot: + formatted_dep += pp.slot('/') + pp.slot(mdep.sub_slot) + if mdep.use: + useflags = pp.useflag(','.join(mdep.use.tokens)) + formatted_dep += (pp.emph('[') + useflags + pp.emph(']')) + + if dep_is_displayed: + indent = indent + " " * len(str(dep.cpv)) + self.print_fn(indent, '', use_conditional, formatted_dep) + else: + self.print_fn(indent, \ + str(dep.cpv), use_conditional, formatted_dep) # ========= @@ -126,6 +154,7 @@ def print_help(with_description=True): "include dependencies that are not installed (slow)", ), (" -D, --indirect", "search both direct and indirect dependencies"), + (" -F, --format=TMPL", "specify a custom output format"), (" --depth=N", "limit indirect dependency tree to specified depth"), ) ) @@ -145,6 +174,8 @@ def parse_module_options(module_opts): QUERY_OPTS["include_masked"] = True elif opt in ("-D", "--indirect"): QUERY_OPTS["only_direct"] = False + elif opt in ('-F', '--format'): + QUERY_OPTS["package_format"] = posarg elif opt in ("--depth"): if posarg.isdigit(): depth = int(posarg) @@ -159,8 +190,9 @@ def parse_module_options(module_opts): def main(input_args): """Parse input and run the program""" - short_opts = "hadD" # -d, --direct was old option for default action - long_opts = ("help", "all-packages", "direct", "indirect", "depth=") + short_opts = "hadDF:" # -d, --direct was old option for default action + long_opts = ('help', 'all-packages', 'direct', 'indirect', \ + 'format', 'depth=') try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) |
