Changeset 8727 for trunk/DataStore/scripts/dsleech
- Timestamp:
- Sep 1, 2006, 11:18:30 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/DataStore/scripts/dsleech (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/scripts/dsleech
r8726 r8727 3 3 # Copyright (C) 2006 Joshua Hoblitt 4 4 # 5 # $Id: dsleech,v 1. 2 2006-08-31 23:04:53jhoblitt Exp $5 # $Id: dsleech,v 1.3 2006-09-01 21:18:30 jhoblitt Exp $ 6 6 7 7 use strict; … … 9 9 10 10 use vars qw( $VERSION ); 11 $VERSION = '0.0 1';11 $VERSION = '0.02'; 12 12 13 13 use DataStore; 14 14 use File::Spec; 15 use YAML (); 15 16 16 17 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 17 18 use Pod::Usage qw( pod2usage ); 18 19 19 my ($dir, $uri, $last_fileset, $ verbose);20 my ($dir, $uri, $last_fileset, $recall, $remember, $verbose); 20 21 21 22 GetOptions( … … 23 24 'uri|u=s' => \$uri, 24 25 'last_fileset|l=s' => \$last_fileset, 25 'verbose|v' => \$verbose, 26 'recall' => \$recall, 27 'remember' => \$remember, 28 'verbose|v' => \$verbose, 26 29 ) or pod2usage( 2 ); 27 30 … … 36 39 ); 37 40 41 # rc file path 42 my $rcfilename = File::Spec->catfile($ENV{'HOME'}, '.dsleechrc'); 43 44 # load rc file 45 my $rc = load_rc($rcfilename) or die "failed to load rcfile"; 46 38 47 $p{last_fileset} = $last_fileset if defined $last_fileset; 48 if ($recall) { 49 # if --last_fileset was specified it's value should override --recall 50 if (defined $last_fileset) { 51 warn "--last_fileset overriding --recall" if defined $verbose; 52 } elsif (defined $rc->{$uri}) { 53 $p{last_fileset} = $rc->{$uri}; 54 } else { 55 warn "--recall couldn't find a previous fileset ID" 56 if defined $verbose; 57 } 58 } 39 59 40 60 my $response = DataStore::Product->new(%p)->request; … … 52 72 53 73 process_filesets($filesets, $dir, $verbose) or die "failed to process filesets"; 74 75 # if we got this far we're assuming that the downloads completed and we can 76 # save the last fileset 77 if ($remember) { 78 my $lowest_fileset = $filesets->[-1]; 79 if (defined $lowest_fileset) { 80 $rc->{$uri} = $lowest_fileset->fileset; 81 } 82 83 save_rc($rcfilename, $rc) or die "failed to save rcfile"; 84 } 54 85 55 86 sub process_filesets … … 127 158 } 128 159 160 sub load_rc { 161 my $rcfilename = shift; 162 163 # initalize $sums with an empty hash so if there isn't a pre-existing 164 # database we still end up with a hashref instead of an undef scalar 165 my $rc; 166 if (-e $rcfilename) { 167 if (-f $rcfilename) { 168 $rc = YAML::LoadFile($rcfilename) or die "failed to load rc file"; 169 } else { 170 warn "$rcfilename is not a plain file"; 171 return; 172 } 173 } 174 175 # if the rcfile exists but is empty YAML will return undef 176 $rc ||= {}; 177 178 return $rc; 179 } 180 181 sub save_rc { 182 my ($rcfilename, $rc) = @_; 183 184 my $yaml = YAML::DumpFile($rcfilename, $rc) 185 or die "failed to write rc file"; 186 187 return 1; 188 } 189 129 190 __END__ 130 191 … … 138 199 139 200 dsproductls --uri <uri> [--dir <dir>] [--last_fileset <filesetid>] 140 [-- verbose]201 [--recall] [--remember] [--verbose] 141 202 142 203 =head1 DESCRIPTION … … 159 220 160 221 The FileSet ID of the last FileSet that you've seen. Only filesets registered after C<filesetid> will be polled for files to retreive. 222 223 This flag is optional. 224 225 =item * --recall 226 227 Load the last fileset ID seen for C<--uri> from the I<rcfile>, if it exists. 228 229 This flag is optional. 230 231 =item * --remember 232 233 Store the last fileset ID seen for C<--uri> in the I<rcfile>. 161 234 162 235 This flag is optional.
Note:
See TracChangeset
for help on using the changeset viewer.
