SVN: toys/rsget.pl: README.config RSGet/AutoUpdate.pm RSGet/Captcha.pm RSGet/Curl.pm RSGet/Dispatch....

sparky sparky at pld-linux.org
Sun Oct 11 20:37:30 CEST 2009


Author: sparky
Date: Sun Oct 11 20:37:30 2009
New Revision: 10756

Modified:
   toys/rsget.pl/README.config
   toys/rsget.pl/RSGet/AutoUpdate.pm
   toys/rsget.pl/RSGet/Captcha.pm
   toys/rsget.pl/RSGet/Curl.pm
   toys/rsget.pl/RSGet/Dispatch.pm
   toys/rsget.pl/RSGet/FileList.pm
   toys/rsget.pl/RSGet/Get.pm
   toys/rsget.pl/RSGet/Main.pm
   toys/rsget.pl/RSGet/Tools.pm
Log:
- reworked configuration options
- slowly preparing for multiuser support


Modified: toys/rsget.pl/README.config
==============================================================================
--- toys/rsget.pl/README.config	(original)
+++ toys/rsget.pl/README.config	Sun Oct 11 20:37:30 2009
@@ -4,12 +4,17 @@
 #
 # Copy it to $HOME/.rsget.pl/config and make necessary adjustments.
 
-# backup allows 4 settings:
-#  copy,move - backups are always made
-#  move - make backup only if starting file from beggining (move old file)
-#  copy - make backup only if continuing partially-downloaded file (copy old)
-#  none - backups are never made
-backup = move
+# backups may be disabled or enabled for 3 different cases:
+#  done - make backup of file in donedir
+#  continue - make backup of file in workdir if continuing partial download
+#  scratch - make backup of file in workdir if downloading it from scratch
+#  no - backups are never made
+# make backups always:
+backup = done,continue,scratch
+# make backups of completed downloads only:
+#backup = done
+# never make make backups:
+#backup = no
 
 # for file FILE_NAME.EXT by default backups will be named as:
 # FILE_NAME-{N}.EXT where {N} is 1, 2, 3...
@@ -21,6 +26,18 @@
 # authentification
 http_port = 5666
 
+# require authentication for http:
+#  user: root
+#  password: qwerty
+http_pass = qwerty
+
+# Some services have no parallel-downloads limitation, set max slots
+# for such services. If you've got fast connection and only one
+# ip address / interface, increase this number to a large value.
+# Number of maximum connections is the number of max_slots multiplied
+# by number of ip addresses / interfaces.
+max_slots = 8
+
 # if you are blessed with multiple interfaces:
 #interfaces = eth0, tun0, tun1
 # same thing for multiple IP addresses:
@@ -43,7 +60,7 @@
 #use_svn = update
 
 # save erroneous pages (only useful for getter debugging):
-#errorlog = 1
+#debug = 1
 
 # be verbose (useful for debugging):
 #verbose = 2

Modified: toys/rsget.pl/RSGet/AutoUpdate.pm
==============================================================================
--- toys/rsget.pl/RSGet/AutoUpdate.pm	(original)
+++ toys/rsget.pl/RSGet/AutoUpdate.pm	Sun Oct 11 20:37:30 2009
@@ -8,12 +8,17 @@
 set_rev qq$Id$;
 
 def_settings(
-	use_svn => [ "Set to 'update' to automatically update rsget.pl components from SVN. " .
-		"Set to 'yes' to use downloaded components without updating first.",
-		"no", qr{no|yes|update} ],
-	svn_uri => [ "SVN path to rsget.pl source code.",
-		'http://svn.pld-linux.org/svn/toys/rsget.pl',
-		qr{(svn|https?)://.{4,}} ],
+	use_svn => {
+		desc => "Set to 'update' to automatically update rsget.pl components from SVN. " .
+			"Set to 'yes' to use downloaded components without updating first.",
+		default => "no",
+		allowed => qr{no|yes|update},
+	},
+	svn_uri => {
+		desc => "SVN path to rsget.pl source code.",
+		default => 'http://svn.pld-linux.org/svn/toys/rsget.pl',
+		allowed => qr{(svn|https?)://.{4,}},
+	},
 );
 
 my @update_dirs = qw(data RSGet Get Link Video);

Modified: toys/rsget.pl/RSGet/Captcha.pm
==============================================================================
--- toys/rsget.pl/RSGet/Captcha.pm	(original)
+++ toys/rsget.pl/RSGet/Captcha.pm	Sun Oct 11 20:37:30 2009
@@ -6,6 +6,21 @@
 use RSGet::Tools;
 set_rev qq$Id$;
 
+=unused
+def_settings(
+	allow_captcha => {
+		desc => "Allow captchas which need to be solved manually.",
+		default => "http",
+		allowed => qr/(http|yes|no)/,
+		dynamic => {
+			http => "Allow only if control page is opened.",
+			yes => "Allow always",
+			no => "Never allow",
+		},
+	},
+);
+=cut
+
 our %needed;
 our %solved;
 

Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm	(original)
+++ toys/rsget.pl/RSGet/Curl.pm	Sun Oct 11 20:37:30 2009
@@ -13,13 +13,37 @@
 set_rev qq$Id$;
 
 def_settings(
-	backup => [ "Make backups if downloaded file exists.",
-	"copy,move", qr/copy,move|copy|move|no(ne)?/ ],
-	backup_suf => [ "Rename backup files with specified suffix. " .
-		"If none defined -N will be added to file name, without disrupting file extension.",
-		undef, qr/.+/ ],
-	outdir => [ "Output directory; where finished files are moved to.", '.', qr/.+/ ],
-	workdir => [ "Work directory; where unfinished files are stored.", '.', qr/.+/ ],
+	backup => {
+		desc => "Make backups if downloaded file exists.",
+		default => "done,continue,scratch",
+		allowed => qr/(no|(done|continue|scratch)(?:,(?2))*)/,
+		dynamic => {
+			'done,continue,scratch' => "Always.",
+			done => "Only if it would replace file in donedir.",
+			'continue,scratch' => "Only if it whould replace file in workdir.",
+			no => "Never.",
+		},
+		user => 1,
+	},
+	backup_suf => {
+		desc => "Rename backup files with specified suffix. " .
+			"If none defined -N will be added to file name, without disrupting file extension.",
+		allowed => qr/\S*/,
+		dynamic => "STRING",
+		user => 1,
+	},
+	outdir => {
+		desc => "Output directory; where finished files are moved to.",
+		default => '.',
+		dynamic => "STRING",
+		user => 1,
+	},
+	workdir => {
+		desc => "Work directory; where unfinished files are stored.",
+		default => '.',
+		dynamic => "STRING",
+		user => 1,
+	},
 );
 
 

Modified: toys/rsget.pl/RSGet/Dispatch.pm
==============================================================================
--- toys/rsget.pl/RSGet/Dispatch.pm	(original)
+++ toys/rsget.pl/RSGet/Dispatch.pm	Sun Oct 11 20:37:30 2009
@@ -6,7 +6,12 @@
 set_rev qq$Id$;
 
 def_settings(
-	max_slots => [ "Number of slots (per IP) to use if getter has no limitation.", 8, qr/0*[1-9]\d*/ ],
+	max_slots => {
+		desc => "Number of slots (per IP) to use if getter has no limitation.",
+		default => 8,
+		allowed => qr/0*[1-9]\d*/,
+		dynamic => "NUMBER",
+	},
 );
 
 our %downloading;

Modified: toys/rsget.pl/RSGet/FileList.pm
==============================================================================
--- toys/rsget.pl/RSGet/FileList.pm	(original)
+++ toys/rsget.pl/RSGet/FileList.pm	Sun Oct 11 20:37:30 2009
@@ -7,8 +7,17 @@
 set_rev qq$Id$;
 
 def_settings(
-	list_lock => [ "If lock file exists, list file won't be updated.", '${dir}/.${file}.swp', qr/.+/ ],
-	list_file => [ "Use specified file as URI list.", undef, qr/.+/ ],
+	list_lock => {
+		desc => "If lock file exists, list file won't be updated.",
+		default => '${dir}/.${file}.swp',
+		allowed => qr/.+/,
+		user => 1,
+	},
+	list_file => {
+		desc => "Use specified file as URI list.",
+		allowed => qr/.+/,
+		user => 1,
+	}
 );
 
 my $file;

Modified: toys/rsget.pl/RSGet/Get.pm
==============================================================================
--- toys/rsget.pl/RSGet/Get.pm	(original)
+++ toys/rsget.pl/RSGet/Get.pm	Sun Oct 11 20:37:30 2009
@@ -8,8 +8,14 @@
 use RSGet::Wait;
 use URI;
 set_rev qq$Id$;
+
 def_settings(
-	errorlog => [ "Save errors.", 0, qr/\d/ ],
+	debug => {
+		desc => "Save errors.",
+		default => 0,
+		allowed => qr/\d/,
+		dynamic => "NUMBER",
+	},
 );
 
 BEGIN {
@@ -237,7 +243,7 @@
 {
 	my $self = shift;
 	my $msg = shift;
-	if ( $self->{body} and setting("errorlog") ) {
+	if ( $self->{body} and setting( "debug" ) ) {
 		my $n = 0;
 		my $name;
 		do {

Modified: toys/rsget.pl/RSGet/Main.pm
==============================================================================
--- toys/rsget.pl/RSGet/Main.pm	(original)
+++ toys/rsget.pl/RSGet/Main.pm	Sun Oct 11 20:37:30 2009
@@ -21,12 +21,30 @@
 set_rev qq$Id$;
 
 def_settings(
-	interfaces => [ "Specify output interfaces or IP addresses.", undef, qr/.+/ ],
-	http_port => [ "Start HTTP server on specified port.", undef, qr/\d+/ ],
-	http_pass => [ "HTTP password, as plain text, user is 'root'.", undef, qr/\S+/ ],
-	verbose => [ "Verbosity level.", 0, qr/\d+/ ],
+	interfaces => {
+		desc => "Specify output interfaces or IP addresses.",
+	},
+	http_port => {
+		desc => "Start HTTP server on specified port.",
+		allowed => qr/\d+/,
+	},
+	http_pass => {
+		desc => "HTTP password, as plain text, user is 'root'.",
+		allowed => qr/\S+/,
+	},
+	verbose => {
+		desc => "Verbosity level.",
+		default => 0,
+		allowed => qr/\d+/,
+	},
+	userconfig => {
+		desc => "User configuration file.",
+		allowed => qr/.+/,
+	},
 );
 
+our %usettings;
+
 my $http = undef;
 sub init
 {
@@ -41,6 +59,7 @@
 
 	$SIG{CHLD} = "IGNORE";
 	maybe_update( $argv );
+	read_userconfig();
 	RSGet::Line::init();
 	print_settings() if verbose( 1 );
 	RSGet::FileList::set_file();
@@ -77,8 +96,8 @@
 		} else {
 			print $option . " " x ( $optlen - $l );
 		}
-		my @text = split /\s+/, $main::def_settings{ $s }->[0];
-		my $defval = $main::def_settings{ $s }->[1];
+		my @text = split /\s+/, $main::def_settings{ $s }->{desc};
+		my $defval = $main::def_settings{ $s }->{default};
 		push @text, "Default:", $defval if defined $defval;
 		my $line = "";
 		foreach my $word ( @text ) {
@@ -119,11 +138,12 @@
 			next;
 		}
 		my $value = $v->[0];
-		my $re = $def->[2];
-		unless ( $value =~ m/^$re$/ ) {
-			warn "Setting '$s' has invalid value: '$value' -- defined in $v->[1].\n";
-			$die = 1;
-			next;
+		if ( my $re = $def->{allowed} ) {
+			unless ( $value =~ m/^$re$/ ) {
+				warn "Setting '$s' has invalid value: '$value' -- defined in $v->[1].\n";
+				$die = 1;
+				next;
+			}
 		}
 	}
 	die "ERROR: Found invalid settings.\n" if $die;
@@ -154,6 +174,36 @@
 	}
 }
 
+sub read_userconfig
+{
+	my $cfg = setting( "userconfig" );
+	return unless $cfg;
+	die "Cannot read user config '$cfg' file\n" unless -r $cfg;
+
+	my $line = 0;
+	my $user = undef;
+	open F_IN, "<", $cfg;
+	while ( <F_IN> ) {
+		$line++;
+		next if /^\s*(?:#.*)?$/;
+		chomp;
+		if ( /^\s*\[([a-zA-Z0-9_]+)\]\s*$/ ) {
+			$user = $1;
+			$usettings{ $user } = {};
+			next;
+		} elsif ( /^\s*([a-z_]+)\s*=\s*(.*?)\s*$/ ) {
+			die "User not defined, at user config file, line ($line):\n$_\n"
+				unless $user;
+			$usettings{ $user }->{$1} = [ $2, "user config file, line $line" ];
+			next;
+		}
+		warn "Incorrect config line: $_\n";
+	}
+	close F_IN;
+
+
+}
+
 sub set_interfaces
 {
 	my $ifs = shift;

Modified: toys/rsget.pl/RSGet/Tools.pm
==============================================================================
--- toys/rsget.pl/RSGet/Tools.pm	(original)
+++ toys/rsget.pl/RSGet/Tools.pm	Sun Oct 11 20:37:30 2009
@@ -130,10 +130,25 @@
 sub def_settings
 {
 	my %s = @_;
+	my %options = (
+		desc => "Setting description.",
+		default => "Default value.",
+		allowed => "RegExp that defines allowed values.",
+		dynamic => "May be changed after start.",
+		user => "May be modified by user.",
+	);
 	foreach my $k ( keys %s ) {
 		my $v = $s{ $k };
-		die "Incorrect setting '$k' declaration\n"
-			if ref $v ne "ARRAY" or scalar @$v != 3;
+		if ( ref $v ne "HASH" ) {
+			die "Setting '$k' is not a HASH\n";
+		}
+		if ( not $v->{desc} ) {
+			die "Setting '$k' is missing description\n";
+		}
+		foreach ( keys %$v ) {
+			die "Setting '$k' has unknown option: $_\n"
+				unless exists $options{ $_ };
+		}
 		$main::def_settings{ $k } = $v;
 	}
 }
@@ -143,7 +158,7 @@
 	my $name = shift;
 	die "Setting '$name' is not defined\n" unless exists $main::def_settings{ $name };
 	return $main::settings{ $name }->[0] if exists $main::settings{ $name };
-	return $main::def_settings{ $name }->[1];
+	return $main::def_settings{ $name }->{default};
 }
 
 sub verbose


More information about the pld-cvs-commit mailing list