[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is this really the right thing to do?



Hello,

> An option for showing only those packages that nothing depends on 
> could be useful.

That bit's easy. My first PERL script did that. But what about alternatives?

Jiri <jiri@baum.com.au>
--
#!/usr/bin/perl

print <<ENDDOC and exit if $ARGV[0] =~ /-h/;
List installed packages which are "wanted". This means they are not essential
or required, and are not depended or recommended by another installed package.

$0 [-h|--help|-v|--verbose]

  -h, --help      show this help

  -v, --verbose   show the description of each package as well as its name

BUGS

* alternatives aren't handled properly

* virtual packages aren't handled

* the descriptions are shown without the proper formatting
ENDDOC
# ' #(fix apostrophes for syntax highlighting)

$v=1 if $ARGV[0] =~ /-v/;

$/="";

open(status,'/var/lib/dpkg/status') or die "$0: can't open status file.\n";

while (<status>) {
  next unless /^Status:\s*\S+ ok installed\s*?$/mi;

  s/^(\S+?:)/lc($1)/emg;
  %pkg = ('',split /^(\S+?):\s*/m); chomp %pkg;

  $_ = "$pkg{depends},$pkg{recommends},$pkg{'pre-depends'}";
  s/\(.*?\)//g; s/\|/,/g; s/\s+//g; s/,,/,/g; s/,$//; s/^,//;
  for (split /,/) {$used{$_}=1};

  next if $pkg{essential} =~ /yes/i or $pkg{priority} =~ /required/i;

  push @inst,$pkg{package};
  $desc{$pkg{package}}=$pkg{description} if $v;
}

if ($v) {
  for (sort @inst) {print "$_ - $desc{$_}\n\n" unless $used{$_}};
} else {
  for (sort @inst) {print "$_\n" unless $used{$_}};
}


Reply to: