Python Forum
Announcing the configoose module!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Announcing the configoose module!
#1
I uploaded a new module in Github, it is named « configoose ». It is not yet in Pypi and it is at an early stage of its life, but you can already install it as described on the Github page.

It is not yet documented, but I'll give you here an idea and a small example of what it does.

I wrote this module because when I write a program that needs configuration files, I want to be free as a user to store these files anywhere in my file system, and perhaps in more exotic places such as inside a zip file or a database or on the web etc.

The problem is: how can the program or the module find its configuration files if they can be anywhere on the file system?

The solution is: the program uses an abstract 'address' for the configuration file and it asks someone to find the configuration
file registered with that address. This someone is the configoose module.

Here is a small example of how it works with a program configured with configparser (this is called a protocol in configoose's jargon)

I first create a configuration file for the configparser protocol by running the command

Output:
python -m configoose template configoose.protocol.configparser.Protocol > paillasse/tmp/french.cfg
Now I edit the configuration file and populate it
Output:
{ "address" : "s8dzw5y5anduiodmrdrxdgxaa", "protopath" : "configoose.protocol.configparser.Protocol", } [spam] ham = slice A slice B slice C [more] eggs = 1000
It is a normal configparser file except that there is a small python dictionary at the beginning called a « preamble ». I don't touch this preamble.

Now I register my configuration file in the configoose system so that other modules can find it
Output:
python -m configoose moor -a s8dzw5y5anduiodmrdrxdgxaa initial paillasse/tmp/french.cfg
It remains to write a module that uses this configuration. Here is one
from configoose import Configurator

cfg = Configurator("s8dzw5y5anduiodmrdrxdgxaa")

@cfg.add_protocol("configoose.protocol.configparser.Protocol")
def handler(ap, preamble, parser):
    s = parser["spam"]["ham"]
    ham = [y.strip() for y in s.strip().split("\n") if y.strip()]
    print('ham = ', ham)
    print(f"There are {parser['more']['eggs']} eggs!")

cfg.run()
Here the handler function receives a ConfigParser instance among other arguments, which read the configuration file. Here is the output
Output:
λ python paillasse/tmp/frenchman.py ham = ['slice A', 'slice B', 'slice C'] There are 1000 eggs!
There are a huge amount of details to be explained about configoose. It is an infinitely extensible module. Arbitrary configuration protocols can be defined (3 are included by default) and there is potentially no limit as to where the configuration files can be stored.

The next step for me in the next days is to develop the basic documentation.

Play with the module, enjoy and post feedback! Big Grin
snippsat likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020