Commits

Palmer, 2E0EOL committed 20f9d21

Migrate from Daybo::ConfReader to Config::IniFiles for wider compatibility.
This is essentially a politicial decision; it makes the dlpodget tool less
effort to install on a standard Debian system, because libconfig-inifiles-perl
is already packaged, and has been for some time.

It requires only a very minor change in dlpodget.rc in order to support it.

Comments (0)

Files changed (3)

 Depends: ${shlibs:Depends}, ${misc:Depends},
  libwww-perl,
  libxml-feed-perl,
- dl-libconfreader-perl,
+ libconfig-inifiles-perl,
  liburi-perl,
  libio-interactive-perl
 Description: Podcast downloader and management system
 use LWP::UserAgent;
 use XML::Feed;
 use Data::Dumper;
-use Daybo::ConfReader;
+use Config::IniFiles;
 use Getopt::Std;
 use URI::Escape;
 use IO::Interactive qw(is_interactive);
 	$ua = LWP::UserAgent->new( show_progress => $is_interactive );
 	printf(STDERR "Downloading %s ... ", $entry->{uri}) if ( !$is_interactive );
 
-	unless ( $Feeds->{_main}->{NOOP} ) {
+	unless ( $Feeds->{main}->{NOOP} ) {
 		if ( open($f, '>>:raw', $local_podcast) ) {
 			binmode($f);
 		} else {
 		%get_params,
 		':content_cb' => sub {
 			my ( $chunk ) = @_;
-			print $f $chunk unless ( $Feeds->{_main}->{NOOP} );
+			print $f $chunk unless ( $Feeds->{main}->{NOOP} );
 		}
 	);
-	close($f) if ( !$Feeds->{_main}->{NOOP} );
+	close($f) if ( !$Feeds->{main}->{NOOP} );
 	printf(STDERR "done.\n") if ( !$is_interactive );
 }
 
 	while ( (my $idx = index($V, '$', $avoid)) > -1 ) { # Find remaining user-variable references
 		my $var = substr($V, $idx);
 		if ( $var =~ $tagRx ) {
-			my $v = $Feeds->{_main}->{ uc($1) };
+			my $v = $Feeds->{main}->{ uc($1) };
 			warn(sprintf('%s -> %s', $1, $v || '(undef)')) if ( $Debug );
 			if ( !defined($v) ) {
 				$avoid = $idx+1;
 	my %feeds = ( );
 	my %opts = ( );
 	my %pids;
-	my $confSeen = 0;
 	my @confFiles = (
 		'dlpodget.rc',
 		"$ENV{HOME}/.dlpodget.rc"
 	$Debug = 1 if ( $opts{'d'} );
 	print(STDERR "Explicit debug mode enabled by -d\n") if ( $Debug );
 
-	$conf = Daybo::ConfReader->new();
 	foreach my $confFile ( @confFiles ) {
 		next unless ( -f $confFile );
-		if ( $conf->SetFn($confFile) ) {
-			$conf->Reload();
-			$confSeen++;
-			last;
+		$conf = Config::IniFiles->new(-file => $confFile, -commentchar => ';');
+		if ( !$conf ) {
+			print(STDERR "Fault with $confFile: " . join(',', @Config::IniFiles::errors) . "\n");
+			return 1;
 		}
+		last;
 	}
-	$conf = undef if ( !$confSeen );
 
-	if ( $conf && $conf->GetKeys(undef, \@defKeys) ) {
-		if ( 'enable' ~~ @defKeys ) {
-			if ( !$conf->GetDatum(undef, 'enable') ) {
-				print(STDERR "Configuration disabled.\n");
-				$conf = undef;
-			}
+	if ( $conf && (@defKeys = $conf->Parameters('main')) ) {
+		if ( !$conf->val('main', 'enable', 1) ) {
+			print(STDERR "Configuration disabled.\n");
+			$conf = undef;
 		}
 	}
 	if ( $conf ) {
-		my %reserveSec = map {  $_ => 1 } ( '_main', 'paths' ); # Reserved section names
+		my %reserveSec = map {  $_ => 1 } ( 'main', 'paths' ); # Reserved section names
 		my ( @sections, $secC );
-		$secC = $conf->GetSections(\@sections);
+		@sections = $conf->Sections();
+		$secC = scalar(@sections);
 
 		# First load the generation configuration information
 		# Include environment variables.
 		foreach my $ek ( keys(%ENV) ) {
-			$feeds{_main}->{ uc($ek) } = $ENV{$ek};
+			$feeds{main}->{ uc($ek) } = $ENV{$ek};
 		}
 		if ( scalar(@defKeys) ) {
 			foreach my $mk ( @defKeys ) {
-				$feeds{_main}->{ uc($mk) } = $conf->GetDatum(undef, $mk);
+				$feeds{main}->{ uc($mk) } = $conf->val('main', $mk);
 			}
 			# Set debug flag via config if it existed.
-			if ( $feeds{_main}->{DEBUG} ) {
-				$Debug = $feeds{_main}->{DEBUG};
+			if ( $feeds{main}->{DEBUG} ) {
+				$Debug = $feeds{main}->{DEBUG};
 				printf(STDERR "Set Debug via config: %s\n", $Debug);
 			}
 		}
 
 		if ( 'paths' ~~ @sections ) { # Has a paths section?
 			my @secKeys;
-			if ( $conf->GetKeys('paths', \@secKeys) ) {
+			if ( (@secKeys = $conf->Parameters('paths')) ) {
 				foreach my $pk ( @secKeys ) {
-					$feeds{_main}->{ uc($pk) } = $conf->GetDatum('paths', $pk);
+					$feeds{main}->{ uc($pk) } = $conf->val('paths', $pk);
 				}
 				# For backward compatibility, set localpfx with [paths] root
-				$feeds{_main}->{'LOCALPFX'} = $feeds{_main}->{'ROOT'}
-					if ( $feeds{_main}->{'ROOT'} );
+				$feeds{main}->{'LOCALPFX'} = $feeds{main}->{'ROOT'}
+					if ( $feeds{main}->{'ROOT'} );
 			}
 		}
 
 		for ( my $secI = 0; $secI < $secC; $secI++ ) {
-			my @secKeys;
+			my ( @secKeys, $keyC );
 			next if ( $opts{'n'} && $sections[$secI] ne $opts{'n'} );
-			my $keyC = $conf->GetKeys($sections[$secI], \@secKeys);
+			@secKeys = $conf->Parameters($sections[$secI]);
+			$keyC = scalar(@secKeys);
 			foreach ( my $keyI = 0; $keyI < $keyC; $keyI++ ) {
 				next if ( $reserveSec{$sections[$secI]} ); # Skip reserved sections
-				my $v = $conf->GetDatum($sections[$secI], $secKeys[$keyI]);
+				my $v = $conf->val($sections[$secI], $secKeys[$keyI]);
 				$v = ProcessTags(\%feeds, $v);
 				printf(
 					STDERR
 		}
 	}
 
-	$0 = "$proctitle [MASTER]" if ( $feeds{_main}->{MAXCHILDREN} != 0 );
+	$0 = "$proctitle [MASTER]" if ( $feeds{main}->{MAXCHILDREN} != 0 );
 	foreach my $feedName ( keys(%feeds) ) {
 		my $reaped_pid;
 		my $child_limit_reached = 0;
 		next if ( !$feed->{enable} );
 		next if ( !$feed->{download} );
 		$feed->{name} = $feedName;
-		if ( $feeds{_main}->{MAXCHILDREN} == 0 ) { # Master performs downloads
+		if ( $feeds{main}->{MAXCHILDREN} == 0 ) { # Master performs downloads
 			$0 = "$proctitle [$feedName]";
 			Child(\%feeds, $feed);
 			next;
-		} elsif ( $feeds{_main}->{MAXCHILDREN} < 0 || scalar(keys(%pids)) < $feeds{_main}->{MAXCHILDREN} ) {
+		} elsif ( $feeds{main}->{MAXCHILDREN} < 0 || scalar(keys(%pids)) < $feeds{main}->{MAXCHILDREN} ) {
 			my $pid = fork();
 			die "cannot fork: $!" if ( !defined($pid) );
 			if ( $pid == 0 ) { # Child process
 ;                 is less efficient than 0, since a dedicated child is cloned for each feed.
 ;                 -1 means no limit (no more than the number of feeds in the configuration).
 
+[main]
 enable    = 1
 noop      = 0
 debug     = 0
 download  = 1
 enable    = 1
 
-[acooke]  ; Letter From America
+; Letter From America
+[acooke]
 localpath = $BBC/acooke
 rss       = http://downloads.bbc.co.uk/podcasts/radio4/acooke/rss.xml
 check     = 1