From c13069d9cf136a8f3ae26e9919b278c7414a0086 Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Wed, 23 Jun 2004 14:16:40 +0000 Subject: New code to write urpmi.cfg. --- urpm/cfg.pm | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'urpm/cfg.pm') diff --git a/urpm/cfg.pm b/urpm/cfg.pm index f30c8b0d..0d9238d2 100644 --- a/urpm/cfg.pm +++ b/urpm/cfg.pm @@ -34,18 +34,21 @@ appropriate error message.) =item dump_config($file, $config) +Does the opposite: write the configuration file, from the same data structure. +Returns 1 on success, 0 on failure. + =cut our $err; -sub _syntax_error () { $err = N("syntax error in config file at line %s" } +sub _syntax_error () { $err = N("syntax error in config file at line %s") } sub load_config ($) { my ($file) = @_; my %config; my $medium = undef; $err = ''; - open my $f, $file or do { $err = "Can't read $file: $!\n"; return } + open my $f, $file or do { $err = "Can't read $file: $!\n"; return }; local $_; while (<$f>) { chomp; @@ -67,7 +70,7 @@ sub load_config ($) { $medium = ''; next; } - if (/^(.*?[^\\])\s+(?:(.*?[^\\])\s+)?{$/ { #-} medium definition + if (/^(.*?[^\\])\s+(?:(.*?[^\\])\s+)?{$/) { #-} medium definition $config{ $medium = unquotespace $1 }{url} = unquotespace $2; next; } @@ -114,6 +117,30 @@ sub load_config ($) { sub dump_config ($$) { my ($file, $config) = @_; + my @media = sort { + return 0 if $a eq $b; + return -1 if $a eq ''; + return 1 if $b eq ''; + return $a cmp $b; + } keys %$config; + open my $f, '>', $file or do { + $err = "Can't write to $file: $!\n"; + return 0; + }; + print $f "# generated ".(scalar localtime)."\n"; + for my $m (@media) { + print $f quotespace($m), ' ', quotespace($config->{$m}{url}), " {\n"; + for (grep { $_ ne 'url' } keys %{$config->{$m}}) { + if (/^(update|ignore|synthesis|virtual)$/) { + print $f " $_\n"; + } else { + print $f " $_: $config->{$m}{$_}\n"; + } + } + print $f "}\n\n"; + } + close $f; + return 1; } __END__ -- cgit v1.2.1