Author: sparky
Date: Wed Sep 30 00:33:50 2009
New Revision: 10637

Modified:
   toys/rsget.pl/rsget.pl   (contents, props changed)
Log:
- prepare for config file


Modified: toys/rsget.pl/rsget.pl
==============================================================================
--- toys/rsget.pl/rsget.pl      (original)
+++ toys/rsget.pl/rsget.pl      Wed Sep 30 00:33:50 2009
@@ -15,6 +15,7 @@
 use Time::HiRes;
 use RSGet::Line;
 use RSGet::Tools;
+use RSGet::AutoUpdate;
 use RSGet::Processor;
 use RSGet::Curl;
 use RSGet::FileList;
@@ -25,44 +26,58 @@
 use RSGet::ListManager;
 $SIG{CHLD} = "IGNORE";
 
+set_rev qq$Id$;
+
 %settings = (
+       auto_update => undef,
        backup => "copy,move",
-       # backup_suf => "~",
+       backup_suf => undef,
        logging => 0,
        list_lock => '.${file}.swp', # vim-like swap file
+       http_port => undef,
+       list_file => undef,
        errorlog => 0,
        outdir => '.',
        workdir => '.',
 );
 
+my @save_ARGV = @ARGV;
+
+sub set
+{
+       my ( $key, $val ) = @_;
+       if ( exists $settings{ $key } ) {
+               $settings{ $key } = $val;
+       } else {
+               warn "Option '$key' does not exist\n";
+       }
+}
+
 # read options
-my $http = undef;
-my $flist = undef;
 while ( my $arg = shift @ARGV ) {
-       if ( $arg eq '-i' ) {
+       if ( $arg eq '-h' ) {
+               die "No help here, sorrt. For real help read documentation.\n";
+       } elsif ( $arg eq '-i' ) {
                my $ifs = shift @ARGV || die "argument missing";
                RSGet::Dispatch::add_interface( $ifs );
        } elsif ( $arg eq '-p' ) {
-               require RSGet::HTTPServer;
-               my $port = shift @ARGV || die "port missing";
-               $http = new RSGet::HTTPServer( $port );
-               p "HTTP server " . ( $http ? "started on port $port" : "failed" 
) ;
-       } elsif ( $arg eq '-s' ) {
-               my $data = shift @ARGV;
-               my $o = eval "{ $data }";
-               die "Can't process settings: $...@\n" if $@;
-               if ( $o and ref $o ) {
-                       hadd \%settings, %$o;
-               }
+               set( "http_port", shift @ARGV || die "port missing" );
        } elsif ( $arg =~ s/^--(.*?)=// ) {
-               $settings{ $1 } = $arg;
+               set( $1, $arg );
        } elsif ( $arg =~ s/^--(.*)// ) {
                my $key = $1;
                my $var = shift @ARGV;
                die "argument missing" unless defined $var;
-               $settings{ $key } = $var;
+               set( $key, $var );
        } else {
-               $flist = $arg;
+               set( "list_file", $arg );
+       }
+}
+
+if ( $settings{auto_update} ) {
+       if ( RSGet::AutoUpdate::update() ) {
+               warn "Update successfull, restarting\n";
+               exec $0, @save_ARGV;
        }
 }
 if ( keys %settings ) {
@@ -70,7 +85,18 @@
        hprint \%settings;
 }
 
-RSGet::FileList::set_file( $flist );
+RSGet::FileList::set_file( $settings{list_file} );
+
+my $http = undef;
+if ( $settings{http_port} ) {
+       require RSGet::HTTPServer;
+       $http = new RSGet::HTTPServer( $settings{http_port} );
+       p "HTTP server " . ( $http ? "started on port $settings{http_port}" : 
"failed" ) ;
+}
+
+if ( $settings{interfaces} ) {
+       RSGet::Dispatch::add_interface( $settings{interfaces} );
+}
 
 new RSGet::Line();
 
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to