Bug#638295: debmirror: support alternative configuration files

2012-06-25 Thread Matthias Schmitz
Hi Joey, hi everyone, 

i also need to specify an alternative configuration file to debmirror
because i need to mirror Debian and Ubuntu on the same host. 
The attached patch adds the command line switch --config-file=. 

Now i run debmirror like this:  
debmirror --config-file=/etc/debmirror-ubuntu.conf 
debmirror --config-file=/etc/debmirror-debian.conf 

Please review the patch and include if it is fine.

best wishes,
Matthias 

From 7a4f928a0c221e9a8003440cd57216d6bafcdfea Mon Sep 17 00:00:00 2001
From: Matthias Schmitz matth...@sigxcpu.org
Date: Mon, 25 Jun 2012 10:32:01 +0200
Subject: [PATCH] Add switch to specify configuration file at command line.

* Add command line switch --config-file= to allow specification of
  alternate configuration file.
---
 debmirror |   19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/debmirror b/debmirror
index ccb4fbd..9f6d687 100755
--- a/debmirror
+++ b/debmirror
@@ -575,14 +575,11 @@ our $debmarshal=0;
 our $slow_cpu=0;
 our $check_gpg=1;
 our $new_mirror=0;
+our $config_file=undef;
 my @errlog;
 my $HOME;
 ($HOME = $ENV{'HOME'}) or die HOME not defined in environment!\n;
 
-# Load in config files
-require /etc/debmirror.conf if -r /etc/debmirror.conf;
-require $HOME/.debmirror.conf if -r $HOME/.debmirror.conf;
-
 # This hash contains the releases to mirror. If both codename and suite can be
 # determined from the Release file, the codename is used in the key. If not,
 # it can also be a suite (or whatever was requested by the user).
@@ -674,10 +671,24 @@ GetOptions('debug'  = \$debug,
 	   'debmarshal' = \$debmarshal,
 	   'slow-cpu'   = \$slow_cpu,
 	   'help'   = \$help,
+   'config-file=s'  = \$config_file,
 ) or usage;
 usage if $help;
 usage(invalid number of arguments) if $ARGV[1];
 
+# Load in config files
+if ( defined $config_file ) {
+	if ( -r $config_file ) {
+		require $config_file; 
+	} else {
+		die Cannot open config file $config_file.;
+	}
+} else {	
+	require /etc/debmirror.conf if -r /etc/debmirror.conf;
+	require $HOME/.debmirror.conf if -r $HOME/.debmirror.conf;
+}
+
+
 # This parameter is so important that it is the only required parameter,
 # unless specified in a configuration file.
 $mirrordir = shift if $ARGV[0];
-- 
1.7.10



signature.asc
Description: PGP signature


Bug#638295: debmirror: support alternative configuration files

2012-06-25 Thread Joey Hess
Matthias Schmitz wrote:
 -# Load in config files
 @@ -674,10 +671,24 @@ GetOptions('debug'  = \$debug,
 +# Load in config files

This patch changes behavior in an important way: where before
command-line options overrode config file settings, now the config file
is loaded after option parsing and overrides options.

-- 
see shy jo


signature.asc
Description: Digital signature


Bug#638295: debmirror: support alternative configuration files

2012-06-25 Thread Matthias Schmitz
Hi Joey, hi *,

Am Mon, 25 Jun 2012 10:43:02 -0400
schrieb Joey Hess jo...@debian.org:

 Matthias Schmitz wrote:
  -# Load in config files
  @@ -674,10 +671,24 @@ GetOptions('debug'  =
  \$debug, +# Load in config files
 
 This patch changes behavior in an important way: where before
 command-line options overrode config file settings, now the config
 file is loaded after option parsing and overrides options.
arg, you are right. Is it ok to leave the old behavior (cli switch
override configuration file setting) and add a warning to the
--config-file switch that other cli switches will be ignored?


Best wishes,
Matthias 


signature.asc
Description: PGP signature


Bug#638295: debmirror: support alternative configuration files

2012-06-25 Thread Joey Hess
Matthias Schmitz wrote:
 arg, you are right. Is it ok to leave the old behavior (cli switch
 override configuration file setting) and add a warning to the
 --config-file switch that other cli switches will be ignored?

The --config-file could *add* the specified file. Keep it reading
debmirror.conf before options, and then it could be used for setting
defaults that could be overridden by options and --config-file

-- 
see shy jo


signature.asc
Description: Digital signature


Bug#638295: debmirror: support alternative configuration files

2012-06-25 Thread Matthias Schmitz
Hi Joey, hi *,

Am Mon, 25 Jun 2012 12:13:10 -0400
schrieb Joey Hess jo...@debian.org:

 Matthias Schmitz wrote:
  arg, you are right. Is it ok to leave the old behavior (cli switch
  override configuration file setting) and add a warning to the
  --config-file switch that other cli switches will be ignored?
 
 The --config-file could *add* the specified file. Keep it reading
 debmirror.conf before options, and then it could be used for setting
 defaults that could be overridden by options and --config-file
thanks for the quick reply :-). 
With the attached patch the default behavior is untouched (require
debmirror.conf before cli switches) and the file read with --config-file
 is additional. But it still overrides all cli switches. 

Best wishes,
Matthias 
From e2929b2c06c47b9df0c383c5ebcd84312b47fa5b Mon Sep 17 00:00:00 2001
From: Matthias Schmitz matth...@sigxcpu.org
Date: Mon, 25 Jun 2012 20:41:21 +0200
Subject: [PATCH] Add switch to specify an additional configuration file at
 command line.

---
 debmirror |   19 +++
 1 file changed, 19 insertions(+)

diff --git a/debmirror b/debmirror
index ccb4fbd..f8b7da2 100755
--- a/debmirror
+++ b/debmirror
@@ -412,6 +412,14 @@ debmirror cleanup is disabled when this flag is specified.
 Separate pool and snapshot cleanup utilities are available at
 http://code.google.com/p/debmarshal/source/browse/#svn/trunk/repository2
 
+=item B--config-file
+
+Specify an additional configuration file. By default debmirror reads
+/etc/debmirror.conf and ~/.debmirror.conf (see section FILES). 
+
+WARNING: All parameters set in a configuration file specified with
+--config-file cannot be overridden by a command line switch.
+
 =back
 
 =head1 USING DEBMIRROR
@@ -575,6 +583,7 @@ our $debmarshal=0;
 our $slow_cpu=0;
 our $check_gpg=1;
 our $new_mirror=0;
+our $config_file=undef;
 my @errlog;
 my $HOME;
 ($HOME = $ENV{'HOME'}) or die HOME not defined in environment!\n;
@@ -674,10 +683,20 @@ GetOptions('debug'  = \$debug,
 	   'debmarshal' = \$debmarshal,
 	   'slow-cpu'   = \$slow_cpu,
 	   'help'   = \$help,
+   'config-file=s'  = \$config_file,
 ) or usage;
 usage if $help;
 usage(invalid number of arguments) if $ARGV[1];
 
+# Load in additional config file
+if ( defined $config_file ) {
+	if ( -r $config_file ) {
+	require $config_file; 
+	} else {
+		die Cannot open config file $config_file.;
+	}
+}
+
 # This parameter is so important that it is the only required parameter,
 # unless specified in a configuration file.
 $mirrordir = shift if $ARGV[0];
-- 
1.7.10



signature.asc
Description: PGP signature


Bug#638295: debmirror: support alternative configuration files

2012-06-25 Thread Stefan Kisdaroczi
Hi Matthias,

2012/6/25 Matthias Schmitz matth...@sigxcpu.org:
Hi Joey, hi everyone,

i also need to specify an alternative configuration file to debmirror
because i need to mirror Debian and Ubuntu on the same host.

thanks for the trigger!

The attached patch allows loading multiple configuration files instead
of the default configuration files.

use: debmirror --config-file=file1,file2,...

Thats what I need. Does this work for you? ( Not well tested, switch
documentation missing ).

Regards
Stefan


debmirror-config-files.patch
Description: Binary data


Bug#638295: debmirror: support alternative configuration files

2011-08-21 Thread Stefan Kisdaroczi
2011/8/20 Joey Hess jo...@debian.org:
 Stefan Kisdaroczi wrote:
 with the attached patch you can specify a configuration file by
 exporting DEBMIRRORCONF.

 debmirror already has too many switches, but I still think another one
 would be preferable to an environment variable
Yes, a switch like --conf=conf1,conf2,... would be great.

 if this is really needed.
Don't know, me yes. So I decided to open a wishlist bug with a small
non-intrusive patch that
works for me, but I prefer a switch based solution with multiple conf files.

 Did you choose to use an env var simply because the config file is
 loaded before getopt?
Was a reason, yes.

Should I try to make patch with a conf-file switch ?

Stefan



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#638295: debmirror: support alternative configuration files

2011-08-20 Thread Joey Hess
Stefan Kisdaroczi wrote:
 with the attached patch you can specify a configuration file by
 exporting DEBMIRRORCONF.

debmirror already has too many switches, but I still think another one
would be preferable to an environment variable if this is really needed.

Did you choose to use an env var simply because the config file is
loaded before getopt?

-- 
see shy jo


signature.asc
Description: Digital signature


Bug#638295: debmirror: support alternative configuration files

2011-08-18 Thread Stefan Kisdaroczi
Package: debmirror
Version: 1:2.9
Severity: wishlist
Tags: patch

with the attached patch you can specify a configuration file by
exporting DEBMIRRORCONF.

Stefan
diff --git a/debmirror b/debmirror
index 0c50a2f..a36f4ca 100755
--- a/debmirror
+++ b/debmirror
@@ -493,7 +493,8 @@ excluding the section 'debug' and the package 'foo-doc':
   ~/.debmirror.conf
 
 Debmirror will look for the presence of these files and load them
-in the indicated order if they exist.
+in the indicated order if they exist. If you specify a configuration
+file by exporting DEBMIRRORCONF, these files are not loaded.
 See the example in /usr/share/doc/debmirror/examples for syntax.
 
   ~/.gnupg/trustedkeys.gpg
@@ -579,8 +580,13 @@ my $HOME;
 ($HOME = $ENV{'HOME'}) or die HOME not defined in environment!\n;
 
 # Load in config files
-require /etc/debmirror.conf if -r /etc/debmirror.conf;
-require $HOME/.debmirror.conf if -r $HOME/.debmirror.conf;
+my $conf;
+if ($conf = $ENV{'DEBMIRRORCONF'}) {
+  require $conf if -r $conf or die Error reading configuration file $conf;
+} else {
+  require /etc/debmirror.conf if -r /etc/debmirror.conf;
+  require $HOME/.debmirror.conf if -r $HOME/.debmirror.conf;
+}
 
 # This hash contains the releases to mirror. If both codename and suite can be
 # determined from the Release file, the codename is used in the key. If not,