Closed wvmarle closed 11 years ago
Order of reading config files is not mentioned in the python docs unfortunately. A major omission imho. It reads files from the list in that order, each subsequent file overriding options from the previous file, if they have overlapping options. See also: http://stackoverflow.com/questions/4029946/multiple-configuration-files-with-python-configparser http://arunsag.wordpress.com/2011/02/07/behaviour-of-configparser-read-python/
Agreed not everyone uses Linux, but there is no cross-platform place to put such files. If the file /etc/glacier.cnf doesn't exist, it is ignored. To have a global config file for Windows, you could add a proper name for that at the start of the list, too (I don't know Windows so no idea what could be used there).
By the way, the same accounts for ~/.glacier or does have Windows a /home/user type directory layout? This is also typical Linux/Unix.
Just did some extra testing on reading of config files, and indeed they're read in order with the later config file overruling previous config file.
#!/usr/bin/env python
import ConfigParser
config = ConfigParser.SafeConfigParser()
config.read(['./config1', './config2'])
name = dict(config.items("test"))
print "config1, config2: %s"% name
config.read(['./config2', './config1'])
name = dict(config.items("test"))
print "config2, config1: %s"% name
content of .config1:
[test]
name = 'this is config1'
content of .config2:
[test]
name = 'this is config2'
Running the script:
$ ./cfgtest.py
config1, config2: {'name': "'this is config2'"}
config2, config1: {'name': "'this is config1'"}
So for glacier-cmd the order of reading config files should be:
config.read(["/etc/glacier.cnf, os.path.expanduser('~/.glacier'), args.conf])
Hum, that's pretty interesting, because as i understood the docs, it should use the first file that's avalible. Which python version are you using? On Sep 28, 2012 3:25 AM, "wvmarle" notifications@github.com wrote:
Just did some extra testing on reading of config files, and indeed they're read in order with the later config file overruling previous config file.
!/usr/bin/env python
import ConfigParser config = ConfigParser.SafeConfigParser()config.read(['./config1', './config2'])name = dict(config.items("test"))print "config1, config2: %s"% name config.read(['./config2', './config1'])name = dict(config.items("test"))print "config2, config1: %s"% name
content of .config1:
[test] name = 'this is config1'
content of .config2:
[test] name = 'this is config2'
Running the script:
$ ./cfgtest.py config1, config2: {'name': "'this is config2'"} config2, config1: {'name': "'this is config1'"}
So for glacier-cmd the order of reading config files should be:
config.read(["/etc/glacier.cnf, os.path.expanduser('~/.glacier'), args.conf])
— Reply to this email directly or view it on GitHubhttps://github.com/uskudnik/amazon-glacier-cmd-interface/pull/43#issuecomment-8960629.
This was 2.6.6; later will repeat with 2.7 and 3.something. But expect results are the same.
Actually ALL config files are read, in order of how they are listed, files that do not exist are silently ignored, duplicate keys are overwritten by later entries. It is possible to have some settings in one, some in another config file. So you can have a system wide config, with user-specific overrides.
So we can easily add default global config files for various platforms, just list them all. /etc/glacier.cnf
for Linux, something for Windows, something for Mac (if that doesn't use /etc, not sure), whatever.
Resolved; closing.
Added /etc/glacier-cmd.conf as additional config file. Amended order in which config is read so command line overrules local config file, and local config file overrules global config file. Amended readme.md to reflect this change. Fixed some minor typos in the readme.
Finally a commit suggesting to change the .glacier config file to .glacier-cmd to reflect change of the name of the tool itself (and to prevent further clashes with boto's tool).