public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files
@ 2015-10-27  5:52 Mike Frysinger
  2015-10-28  1:53 ` Rick "Zero_Chaos" Farina
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2015-10-27  5:52 UTC (permalink / raw
  To: gentoo-catalyst

There's no real reason people can't load multiple config files, so extend
the --config option into --configs and let people specify multiple ones.
---
 catalyst/defaults.py |  2 ++
 catalyst/main.py     | 55 +++++++++++++++++-----------------------------------
 2 files changed, 20 insertions(+), 37 deletions(-)

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 666afca..c5162d6 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -46,6 +46,8 @@ confdefaults={
 	"storedir": "/var/tmp/catalyst",
 	}
 
+DEFAULT_CONFIG_FILE = '/etc/catalyst/catalyst.conf'
+
 PORT_LOGDIR_CLEAN = \
 	'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
 
diff --git a/catalyst/main.py b/catalyst/main.py
index 9f563cf..176871d 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -21,7 +21,7 @@ from DeComp.contents import ContentsMap
 
 from catalyst import log
 import catalyst.config
-from catalyst.defaults import confdefaults, option_messages
+from catalyst.defaults import confdefaults, option_messages, DEFAULT_CONFIG_FILE
 from catalyst.hash_utils import HashMap, HASH_DEFINITIONS
 from catalyst.support import CatalystError
 from catalyst.version import get_version
@@ -36,40 +36,19 @@ def version():
 	log.info('Copyright 2008-2012 various authors')
 	log.info('Distributed under the GNU General Public License version 2.1')
 
-def parse_config(myconfig):
+def parse_config(config_files):
 	# search a couple of different areas for the main config file
 	myconf={}
-	config_file=""
-	default_config_file = '/etc/catalyst/catalyst.conf'
 
-	# first, try the one passed (presumably from the cmdline)
-	if myconfig:
-		if os.path.exists(myconfig):
-			log.notice('Using command line specified Catalyst configuration file: %s',
-				myconfig)
-			config_file=myconfig
-
-		else:
-			log.critical('Specified configuration file does not exist: %s', myconfig)
-
-	# next, try the default location
-	elif os.path.exists(default_config_file):
-		log.notice('Using default Catalyst configuration file: %s',
-			default_config_file)
-		config_file = default_config_file
-
-	# can't find a config file (we are screwed), so bail out
-	else:
-		log.critical('Could not find a suitable configuration file')
-
-	# now, try and parse the config file "config_file"
-	try:
-#		execfile(config_file, myconf, myconf)
-		myconfig = catalyst.config.ConfigParser(config_file)
-		myconf.update(myconfig.get_values())
-
-	except Exception:
-		log.critical('Could not find parse configuration file: %s', myconfig)
+	# try and parse the config file "config_file"
+	for config_file in config_files:
+		log.notice('Loading configuration file: %s', config_file)
+		try:
+			config = catalyst.config.ConfigParser(config_file)
+			myconf.update(config.get_values())
+		except Exception as e:
+			log.critical('Could not find parse configuration file: %s: %s',
+				config_file, e)
 
 	# now, load up the values into conf_values so that we can use them
 	for x in list(confdefaults):
@@ -209,9 +188,9 @@ $ catalyst -f stage1-specfile.spec"""
 	group.add_argument('-F', '--fetchonly',
 		default=False, action='store_true',
 		help='fetch files only')
-	group.add_argument('-c', '--config',
-		type=FilePath(),
-		help='use specified configuration file')
+	group.add_argument('-c', '--configs',
+		type=FilePath(), action='append',
+		help='use specified configuration files')
 	group.add_argument('-f', '--file',
 		type=FilePath(),
 		help='read specfile')
@@ -241,7 +220,9 @@ def main():
 		color=opts.color)
 
 	# Parse the command line options.
-	myconfig = opts.config
+	myconfigs = opts.configs
+	if not myconfigs:
+		myconfigs = [DEFAULT_CONFIG_FILE]
 	myspecfile = opts.file
 	mycmdline = opts.cli[:]
 
@@ -271,7 +252,7 @@ def main():
 	# made it this far so start by outputting our version info
 	version()
 	# import configuration file and import our main module using those settings
-	parse_config(myconfig)
+	parse_config(myconfigs)
 
 	conf_values["options"].update(options)
 	log.debug('conf_values[options] = %s', conf_values['options'])
-- 
2.5.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files
  2015-10-27  5:52 [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files Mike Frysinger
@ 2015-10-28  1:53 ` Rick "Zero_Chaos" Farina
  2015-10-28  2:58   ` Mike Frysinger
  0 siblings, 1 reply; 4+ messages in thread
From: Rick "Zero_Chaos" Farina @ 2015-10-28  1:53 UTC (permalink / raw
  To: gentoo-catalyst

I support this idea, but maybe we could leave the --config option so as
not to confuse people who are only passing one config?

Thanks,
Zero

On 10/27/2015 01:52 AM, Mike Frysinger wrote:
> There's no real reason people can't load multiple config files, so extend
> the --config option into --configs and let people specify multiple ones.
> ---
>  catalyst/defaults.py |  2 ++
>  catalyst/main.py     | 55 +++++++++++++++++-----------------------------------
>  2 files changed, 20 insertions(+), 37 deletions(-)
> 
> diff --git a/catalyst/defaults.py b/catalyst/defaults.py
> index 666afca..c5162d6 100644
> --- a/catalyst/defaults.py
> +++ b/catalyst/defaults.py
> @@ -46,6 +46,8 @@ confdefaults={
>  	"storedir": "/var/tmp/catalyst",
>  	}
>  
> +DEFAULT_CONFIG_FILE = '/etc/catalyst/catalyst.conf'
> +
>  PORT_LOGDIR_CLEAN = \
>  	'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
>  
> diff --git a/catalyst/main.py b/catalyst/main.py
> index 9f563cf..176871d 100644
> --- a/catalyst/main.py
> +++ b/catalyst/main.py
> @@ -21,7 +21,7 @@ from DeComp.contents import ContentsMap
>  
>  from catalyst import log
>  import catalyst.config
> -from catalyst.defaults import confdefaults, option_messages
> +from catalyst.defaults import confdefaults, option_messages, DEFAULT_CONFIG_FILE
>  from catalyst.hash_utils import HashMap, HASH_DEFINITIONS
>  from catalyst.support import CatalystError
>  from catalyst.version import get_version
> @@ -36,40 +36,19 @@ def version():
>  	log.info('Copyright 2008-2012 various authors')
>  	log.info('Distributed under the GNU General Public License version 2.1')
>  
> -def parse_config(myconfig):
> +def parse_config(config_files):
>  	# search a couple of different areas for the main config file
>  	myconf={}
> -	config_file=""
> -	default_config_file = '/etc/catalyst/catalyst.conf'
>  
> -	# first, try the one passed (presumably from the cmdline)
> -	if myconfig:
> -		if os.path.exists(myconfig):
> -			log.notice('Using command line specified Catalyst configuration file: %s',
> -				myconfig)
> -			config_file=myconfig
> -
> -		else:
> -			log.critical('Specified configuration file does not exist: %s', myconfig)
> -
> -	# next, try the default location
> -	elif os.path.exists(default_config_file):
> -		log.notice('Using default Catalyst configuration file: %s',
> -			default_config_file)
> -		config_file = default_config_file
> -
> -	# can't find a config file (we are screwed), so bail out
> -	else:
> -		log.critical('Could not find a suitable configuration file')
> -
> -	# now, try and parse the config file "config_file"
> -	try:
> -#		execfile(config_file, myconf, myconf)
> -		myconfig = catalyst.config.ConfigParser(config_file)
> -		myconf.update(myconfig.get_values())
> -
> -	except Exception:
> -		log.critical('Could not find parse configuration file: %s', myconfig)
> +	# try and parse the config file "config_file"
> +	for config_file in config_files:
> +		log.notice('Loading configuration file: %s', config_file)
> +		try:
> +			config = catalyst.config.ConfigParser(config_file)
> +			myconf.update(config.get_values())
> +		except Exception as e:
> +			log.critical('Could not find parse configuration file: %s: %s',
> +				config_file, e)
>  
>  	# now, load up the values into conf_values so that we can use them
>  	for x in list(confdefaults):
> @@ -209,9 +188,9 @@ $ catalyst -f stage1-specfile.spec"""
>  	group.add_argument('-F', '--fetchonly',
>  		default=False, action='store_true',
>  		help='fetch files only')
> -	group.add_argument('-c', '--config',
> -		type=FilePath(),
> -		help='use specified configuration file')
> +	group.add_argument('-c', '--configs',
> +		type=FilePath(), action='append',
> +		help='use specified configuration files')
>  	group.add_argument('-f', '--file',
>  		type=FilePath(),
>  		help='read specfile')
> @@ -241,7 +220,9 @@ def main():
>  		color=opts.color)
>  
>  	# Parse the command line options.
> -	myconfig = opts.config
> +	myconfigs = opts.configs
> +	if not myconfigs:
> +		myconfigs = [DEFAULT_CONFIG_FILE]
>  	myspecfile = opts.file
>  	mycmdline = opts.cli[:]
>  
> @@ -271,7 +252,7 @@ def main():
>  	# made it this far so start by outputting our version info
>  	version()
>  	# import configuration file and import our main module using those settings
> -	parse_config(myconfig)
> +	parse_config(myconfigs)
>  
>  	conf_values["options"].update(options)
>  	log.debug('conf_values[options] = %s', conf_values['options'])
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files
  2015-10-28  1:53 ` Rick "Zero_Chaos" Farina
@ 2015-10-28  2:58   ` Mike Frysinger
  2015-10-28  3:25     ` Rick "Zero_Chaos" Farina
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2015-10-28  2:58 UTC (permalink / raw
  To: gentoo-catalyst

[-- Attachment #1: Type: text/plain, Size: 415 bytes --]

On 27 Oct 2015 21:53, Rick "Zero_Chaos" Farina wrote:
> I support this idea, but maybe we could leave the --config option so as
> not to confuse people who are only passing one config?

that already works ;).  python's argparse does partial matching,
so --config will be treated as --configs.

the only breakage will be people who are passing multiple -c but
expecting only the last one to be expected.  meh.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files
  2015-10-28  2:58   ` Mike Frysinger
@ 2015-10-28  3:25     ` Rick "Zero_Chaos" Farina
  0 siblings, 0 replies; 4+ messages in thread
From: Rick "Zero_Chaos" Farina @ 2015-10-28  3:25 UTC (permalink / raw
  To: gentoo-catalyst

On 10/27/2015 10:58 PM, Mike Frysinger wrote:
> On 27 Oct 2015 21:53, Rick "Zero_Chaos" Farina wrote:
>> I support this idea, but maybe we could leave the --config option so as
>> not to confuse people who are only passing one config?
> 
> that already works ;).  python's argparse does partial matching,
> so --config will be treated as --configs.
> 
> the only breakage will be people who are passing multiple -c but
> expecting only the last one to be expected.  meh.

+1 on the meh, if you pass multiple configs and expect it to ignore them
I don't feel the need to save you.

thanks!

-Zero


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-28  3:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-27  5:52 [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files Mike Frysinger
2015-10-28  1:53 ` Rick "Zero_Chaos" Farina
2015-10-28  2:58   ` Mike Frysinger
2015-10-28  3:25     ` Rick "Zero_Chaos" Farina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox