1
0
mirror of https://github.com/fspc/dswim.git synced 2025-04-04 08:13:24 -04:00

A little prettfycation.

This commit is contained in:
freesource 2001-10-12 03:47:09 +00:00
parent 755d28ab44
commit 3ef714b05c

224
swim
View File

@ -1,5 +1,5 @@
#!/usr/bin/perl -w
#use diagnostics;
require 5.004;
use strict;
use Getopt::Long;
@ -8,32 +8,38 @@ use SWIM::Global;
use SWIM::Library;
################################################################################
# Package administration and research tool for Debian #
# Copyright (C) 1999-2000 Jonathan D. Rosenbaum #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#
################################################################################
############################################################################
#
# Package administration and research tool for Debian
#
# Copyright (C) 1999-2000 Jonathan D. Rosenbaum
#
#
#
# This program is free software; you can redistribute it and/or modify
#
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA
#
#############################################################################
=pod
Description: Show World Intelligent Management
Show World Packaging Method or ....
Description: System Wide Information System
Swim is a program which adds rpm-like quering capabilities to the Debian
SWIM is a program which adds rpm-like quering capabilities to the Debian
system. Information for an installed Debian system is extracted from the
/var/lib/dpkg/info* files and the status file, information for an uninstalled
(not-installed) system is extracted from Packages and Contents files which can
@ -83,6 +89,8 @@ anyone, find the program to do the job easily.
# The MAIN
# First let's determine what options are being used.
my $home = $ENV{'HOME'};
Getopt::Long::config("bundling","no_auto_abbrev"); # will use pass_through
@ -206,46 +214,60 @@ sub command {
menuindex();
}
# Turn on pager for everything, -t value is usefull, since we don't
# want the pager working if the output is short. In situations where -t
# isn't prompted for, -t shouldn't be used, pretty beta.
# The best way is to read the output into a variable than use the pager.
# This can be done simply.
# if ($commands{"t"}) {
# open(STDOUT, "|$pager");
# }
if ($#ARGV == -1 && !defined %commands){
if ($Getopt::Long::error != 1) {
pager(usage());
exit;
}
}
elsif (($commands{"n"} || $commands{"nopager"}) &&
$#ARGV == -1 && !($commands{"q"} || $commands{"ps"} ||
$commands{"research"} || $commands{"refinesearch"} ||
$commands{"powersearch"} || $commands{"search"} ||
$commands{"ramdiskon"} || $commands{"ramdiskoff"} ||
$#ARGV == -1 && !($commands{"q"} ||
$commands{"ps"} ||
$commands{"research"} ||
$commands{"refinesearch"} ||
$commands{"powersearch"} ||
$commands{"search"} ||
$commands{"ramdiskon"} ||
$commands{"ramdiskoff"} ||
$commands{"help"})) {
print nusage() if !($commands{"history"} || $commands{"h"});
exit if !($commands{"history"} || $commands{"h"});
}
elsif (!($commands{"n"} || $commands{"nopager"}) && $commands{"help"}
&& $#ARGV == -1 && !($commands{"q"} || $commands{"ps"} ||
$commands{"research"} || $commands{"refinesearch"} ||
$commands{"powersearch"} || $commands{"search"} ||
$commands{"ramdiskon"} || $commands{"ramdiskoff"})) {
elsif (!($commands{"n"} || $commands{"nopager"}) &&
$commands{"help"} &&
$#ARGV == -1 &&
!($commands{"q"} ||
$commands{"ps"} ||
$commands{"research"} ||
$commands{"refinesearch"} ||
$commands{"powersearch"} ||
$commands{"search"} ||
$commands{"ramdiskon"} ||
$commands{"ramdiskoff"})) {
pager(help()) if !($commands{"history"} || $commands{"h"});
exit if !($commands{"history"} || $commands{"h"});
}
elsif ((($commands{"n"} || $commands{"nopager"}) && $commands{"help"})
&& $#ARGV == -1 && !($commands{"q"} || $commands{"ps"} ||
$commands{"research"} || $commands{"refinesearch"} ||
$commands{"powersearch"} || $commands{"search"} ||
$commands{"ramdiskon"} || $commands{"ramdiskoff"})) {
elsif ((($commands{"n"} || $commands{"nopager"}) &&
$commands{"help"})
&& $#ARGV == -1 &&
!($commands{"q"} ||
$commands{"ps"} ||
$commands{"research"} ||
$commands{"refinesearch"} ||
$commands{"powersearch"} ||
$commands{"search"} ||
$commands{"ramdiskon"} ||
$commands{"ramdiskoff"})) {
print help() if !($commands{"history"} || $commands{"h"});
exit if !($commands{"history"} || $commands{"h"});
}
# version of the program
@ -257,8 +279,10 @@ sub command {
# Do the the dpkg -C thing, nice no need for a separate approach
if (($commands{"C"} || $commands{"audit"} || $commands{"status"}) &&
defined $dpkg) {
system "$dpkg", "-C";
exit;
}
@ -306,7 +330,8 @@ sub command {
}
# this will handle options with arguments
if ($Getopt::Long::error == 1 || $commands{"root"} || $commands{"dbpath"}) {
if ($Getopt::Long::error == 1 || $commands{"root"} ||
$commands{"dbpath"}) {
# If two options are used
if ($Getopt::Long::error == 1) {
if ($commands{"dbpath"} && !$commands{"root"}) {
@ -319,17 +344,25 @@ sub command {
# Check whether a different filesystem is being used with --root
my($arch, $dist) = which_archdist(\%commands);
if ($commands{"root"} && !$commands{"dbpath"}) {
if ($commands{"q"} || $commands{"query"} || $commands{"search"} ||
$commands{"refinesearch"} || $commands{"research"} ||
$commands{"powersearch"} || $commands{"ps"} ||
$commands{"ramdiskon"} || $commands{"history"} ||
if ($commands{"root"} &&
!$commands{"dbpath"}) {
if ($commands{"q"} ||
$commands{"query"} ||
$commands{"search"} ||
$commands{"refinesearch"} ||
$commands{"research"} ||
$commands{"powersearch"} ||
$commands{"ps"} ||
$commands{"ramdiskon"} ||
$commands{"history"} ||
$commands{"h"}) {
if ($commands{"root"} =~ m,^\/.*,) {
$parent = $commands{"root"};
my $root;
if (!($commands{"n"} || $commands{"initndb"} ||
$commands{"rebuildndb"} || $commands{"p"} ||
if (!($commands{"n"} ||
$commands{"initndb"} ||
$commands{"rebuildndb"} ||
$commands{"p"} ||
$commands{"ndb"})) {
$root = "$parent$base/packages.deb";
}
@ -347,9 +380,13 @@ sub command {
}
}
else {
if ($commands{"initdb"} || $commands{"rebuilddb"} ||
$commands{"db"} || $commands{"initndb"} || $commands{"ndb"} ||
$commands{"rebuildndb"} || $commands{"rebuildflatdb"} ||
if ($commands{"initdb"} ||
$commands{"rebuilddb"} ||
$commands{"db"} ||
$commands{"initndb"} ||
$commands{"ndb"} ||
$commands{"rebuildndb"} ||
$commands{"rebuildflatdb"} ||
$commands{"rebuildflatndb"}) {
if ($commands{"root"} =~ m,^\/.*,) {
$parent = $commands{"root"};
@ -371,18 +408,26 @@ sub command {
}
}
# check whether a different database location is being used with --dbpath.
elsif ($commands{"dbpath"} && !$commands{"root"}) {
if ($commands{"q"} || $commands{"query"} || $commands{"search"} ||
$commands{"refinesearch"} || $commands{"research"} ||
$commands{"powersearch"} || $commands{"ps"} ||
$commands{"ramdiskon"} || $commands{"history"} ||
elsif ($commands{"dbpath"} &&
!$commands{"root"}) {
if ($commands{"q"} ||
$commands{"query"} ||
$commands{"search"} ||
$commands{"refinesearch"} ||
$commands{"research"} ||
$commands{"powersearch"} ||
$commands{"ps"} ||
$commands{"ramdiskon"} ||
$commands{"history"} ||
$commands{"h"}) {
if ($commands{"dbpath"} =~ m,^\/.*,) {
my $dbpath;
$library = $commands{"dbpath"};
if (!($commands{"n"} || $commands{"initndb"} ||
if (!($commands{"n"} ||
$commands{"initndb"} ||
$commands{"rebuildndb"} ||
$commands{"p"} || $commands{"ndb"})) {
$commands{"p"} ||
$commands{"ndb"})) {
$dbpath = "$library/packages.deb";
}
else {
@ -403,10 +448,14 @@ sub command {
print "swim: arguments to --dbpath must begin with a /\n";
}
else {
if ($commands{"initdb"} || $commands{"rebuilddb"} ||
$commands{"db"} || $commands{"rebuildndb"} ||
$commands{"initndb"} || $commands{"rebuildflatdb"}
|| $commands{"ndb"} || $commands{"rebuildflatndb"}) {
if ($commands{"initdb"} ||
$commands{"rebuilddb"} ||
$commands{"db"} ||
$commands{"rebuildndb"} ||
$commands{"initndb"} ||
$commands{"rebuildflatdb"} ||
$commands{"ndb"} ||
$commands{"rebuildflatndb"}) {
if ($commands{"dbpath"} =~ m,^\/.*,) {
$library = $commands{"dbpath"};
my $dbpath = "$library";
@ -427,14 +476,20 @@ sub command {
}
}
}
# check whether a different database location is being used with --dbpath
# check whether a different database location is being used with
# --dbpath
# and --root / are being used, dbpath takes priority but uses --root as
# the base.
elsif ($commands{"dbpath"} && $commands{"root"}) {
if ($commands{"q"} || $commands{"query"} || $commands{"search"} ||
$commands{"refinesearch"} || $commands{"research"} ||
$commands{"powersearch"} || $commands{"ps"} ||
$commands{"ramdiskon"} || $commands{"history"} ||
if ($commands{"q"} ||
$commands{"query"} ||
$commands{"search"} ||
$commands{"refinesearch"} ||
$commands{"research"} ||
$commands{"powersearch"} ||
$commands{"ps"} ||
$commands{"ramdiskon"} ||
$commands{"history"} ||
$commands{"h"}) {
if ($commands{"dbpath"} =~ m,^\/.*, &&
$commands{"root"} =~ m,^\/.*,) {
@ -442,8 +497,10 @@ sub command {
$library = $commands{"dbpath"};
my $root = "$parent$library";
my $dbpath;
if (!($commands{"n"} || $commands{"initndb"} ||
$commands{"rebuildndb"} || $commands{"p"} ||
if (!($commands{"n"} ||
$commands{"initndb"} ||
$commands{"rebuildndb"} ||
$commands{"p"} ||
$commands{"ndb"})) {
$dbpath = "$parent$library/packages.deb";
}
@ -469,9 +526,13 @@ sub command {
print "swim: arguments to --dbpath must begin with a /\n";
exit;
}
if ($commands{"initdb"} || $commands{"rebuilddb"} ||
$commands{"db"} || $commands{"initndb"} || $commands{"ndb"} ||
$commands{"rebuildndb"} || $commands{"rebuildflatdb"} ||
if ($commands{"initdb"} ||
$commands{"rebuilddb"} ||
$commands{"db"} ||
$commands{"initndb"} ||
$commands{"ndb"} ||
$commands{"rebuildndb"} ||
$commands{"rebuildflatdb"} ||
$commands{"rebuildflatndb"}) {
if ($commands{"dbpath"} =~ m,^\/.*, &&
$commands{"root"} =~ m,^\/.*,) {
@ -510,9 +571,12 @@ sub command {
# need Package(s) and Contents file(s) --ftp
if ($commands{"ftp"} && !($commands{"q"} ||
$commands{"search"} || $commands{"powersearch"} ||
$commands{"ps"} || $commands{"research"} ||
if ($commands{"ftp"} &&
!($commands{"q"} ||
$commands{"search"} ||
$commands{"powersearch"} ||
$commands{"ps"} ||
$commands{"research"} ||
$commands{"refinesearch"})) {
require SWIM::Apt;
SWIM::Apt->import(qw(ftp));