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