zopefoundation / zope.configuration

Extensible system for supporting various kinds of configurations
https://zopeconfiguration.readthedocs.io
Other
1 stars 6 forks source link

`fields.Path` doesn't handle home directories #3

Closed tseaver closed 5 years ago

tseaver commented 9 years ago

In https://bugs.launchpad.net/zope.configuration/+bug/494493, @batlock666 reported:

The fieldtype Path from zope.configuration.fields doesn't handle home directories, indicated by a ~ in the path. The path ~/some.file will be interpreted as /path/to/some/package/~/some.file, while it should be something like /home/someuser/some.file.

@freddrake followed up:

How much need is there for ~/some.file or ~user/some.file in ZCML?

If you're not using this from ZCML, could you describe you use case?

@batlock666 replied:

I use it in a custom ZCML-directive. The directive defines a configuration-file in INI-format. The handler for the directive reads the file, and makes the contents available in a global utility:

In ZCML, I define:

<ugent:configurationFile path="~/some.config.ini"
                         name="some_config" />

Then in Zope, I can do this:

config = getUtility(IConfigurationFile, name="some_config")
print config.getSections()
['some_section', 'some_other_section']

I use this to define connection-settings for MySQL and LDAP.

jamadden commented 5 years ago

It seems like it would be trivial to add a call to os.path.expanduser to either the Path field, or more generally, to the ConfigurationContext.path method. Even more useful would be to also include a call to os.path.expandvars for environment variable expansions. (ZConfig gained something similar in 3.1.0 ) Both of those functions document that if anything goes wrong, the strings are returned unchanged.