commit 88d792d3ac73bfc6305dae91bd0c46a2dd918506
parent 8f8e4048dd066683cc87eceff083e26849b8db0b
Author: bsandro <brian.drosan@gmail.com>
Date: Wed, 4 Aug 2021 02:40:11 +0300
Added -i argument to exclude installed packages from the output
Packages that were already displayed in tree are being ignored now.
Diffstat:
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/pkg_tree.pl b/pkg_tree.pl
@@ -5,7 +5,23 @@ use warnings;
# time pkg_tree.pl surf
# 2m48.79s real 0m40.46s user 0m24.75s system
+my $PROGRAM_NAME = $0;
my %deps_cache;
+my %installed_cache;
+my %displayed_cache;
+my $package_name;
+
+sub print_usage {
+ print("Usage: $PROGRAM_NAME [-i] package_name\
+ -i: exclude installed packages from tree
+");
+}
+
+sub create_installed_cache {
+ my $packages_str = `pkg_info -Aq`;
+ my @packages_vec = split('\n', $packages_str);
+ %installed_cache = map { $_ => 1 } @packages_vec;
+}
sub print_deps {
my $packagename = shift;
@@ -23,8 +39,21 @@ sub print_deps {
@{$deps_cache{$packagename}} = @ret;
}
foreach my $r (@ret) {
- print_deps($r, $level);
+ if (!exists($installed_cache{$r}) && !exists($displayed_cache{$r})) {
+ $displayed_cache{$r} = 1;
+ print_deps($r, $level);
+ }
}
}
-print_deps($ARGV[0], 0);
+if (@ARGV == 1) {
+ $package_name = $ARGV[0]
+} elsif (@ARGV == 2 && $ARGV[0] eq "-i") {
+ create_installed_cache();
+ $package_name = $ARGV[1];
+} else {
+ print_usage();
+ exit();
+}
+
+print_deps($package_name, 0);