From 6f1417a87b4dbf737df8d0f56f41dcc806a79d0d Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 27 Jan 2011 16:56:52 +0000 Subject: [PATCH] use Getopt::Long::Descriptive --- bin/BackupPC_ASA_SearchUpdate | 85 +++++++++++++---------------------- 1 file changed, 31 insertions(+), 54 deletions(-) diff --git a/bin/BackupPC_ASA_SearchUpdate b/bin/BackupPC_ASA_SearchUpdate index ede665f..2ce01fc 100755 --- a/bin/BackupPC_ASA_SearchUpdate +++ b/bin/BackupPC_ASA_SearchUpdate @@ -7,7 +7,7 @@ use DBI; use BackupPC::Lib; use BackupPC::View; use Data::Dumper; -use Getopt::Std; +use Getopt::Long::Descriptive; use Time::HiRes qw/time/; use File::Pid; use POSIX qw/strftime/; @@ -57,40 +57,24 @@ my $index_node_url = $Conf{HyperEstraierIndex}; my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); -my %opt; - -if ( !getopts("cdm:v:ijfqh:", \%opt ) ) { - print STDERR <text), exit if $opt->help; + +warn "hosts: ",dump( $opt->host ); #---- subs ---- @@ -111,7 +95,7 @@ sub hest_update { my ($host_id, $share_id, $num) = @_; - my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n"; + my $skip_check = $opt->junk && print STDERR "Skipping check for existing files -- this should be used only with initital import\n"; print curr_time," updating fulltext:"; @@ -204,17 +188,17 @@ sub hest_update { ## update index ## -if ( ( $opt{i} || $opt{j} ) && !$opt{c} ) { +if ( ( $opt->index || $opt->junk ) && !$opt->create ) { # update all print "force update of Hyper Estraier index "; - print "by -i flag" if ($opt{i}); - print "by -j flag" if ($opt{j}); + print "by -i flag" if ($opt->index); + print "by -j flag" if ($opt->junk); print "\n"; hest_update(); } ## create tables ## -if ($opt{c}) { +if ($opt->create) { sub do_index { my $index = shift || return; my ($table,$col,$unique) = split(/:/, $index); @@ -359,7 +343,7 @@ if ($opt{c}) { $dbh->do( qq{ CREATE SEQUENCE $seq } ); } -=cut +=for later print " creating triggers "; $dbh->do( <<__END_OF_TRIGGER__ ); @@ -431,7 +415,7 @@ __END_OF_TRIGGER__ } ## delete data before inseting ## -if ($opt{d}) { +if ($opt->delete) { print "deleting "; foreach my $table (qw(files dvds backups shares hosts)) { print "$table "; @@ -484,18 +468,11 @@ INSERT INTO files my @hosts = keys %{$hosts}; my $host_nr = 0; -my $host_regex; -if ( exists $opt{h} ) { - $host_regex = $opt{h}; - $host_regex =~ s/\s+/|/g; - $host_regex = '^' . $host_regex . '$'; -} - foreach my $host_key (@hosts) { my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key"; - next if $host_regex && $hostname =~ m/$host_regex/; + next if $opt->host && ! grep { m/^$hostname$/ } @{ $opt->host }; $sth->{hosts_by_name}->execute($hostname); @@ -519,7 +496,7 @@ foreach my $host_key (@hosts) { ($#hosts + 1), $incs ); - print $host_header unless ($opt{q}); + print $host_header unless $opt->quiet; my $inc_nr = 0; $beenThere = {}; @@ -527,7 +504,7 @@ foreach my $host_key (@hosts) { foreach my $backup (@backups) { $inc_nr++; - last if (defined $opt{m} && $inc_nr > $opt{m}); + last if defined $opt->max && $inc_nr > $opt->max; my $backupNum = $backup->{'num'}; my @backupShares = (); @@ -540,7 +517,7 @@ foreach my $host_key (@hosts) { strftime($t_fmt,localtime($backup->{startTime})), fmt_time($backup->{endTime} - $backup->{startTime}) ); - print $share_header unless ($opt{q}); + print $share_header unless $opt->quiet; my $files = BackupPC::View->new($bpc, $hostname, \@backups, { only_first => 1 }); @@ -556,7 +533,7 @@ foreach my $host_key (@hosts) { next if ($count > 0); # dump host and share header for -q - if ($opt{q}) { + if ( $opt->quiet ) { if ($host_header) { print $host_header; $host_header = undef; -- 2.20.1