Package: ageliaco.recipe.csvconfig
- Code repository:https://github.com/renfers/ageliaco.recipe.csvconfig- Questions and comments to serge.renfer at gmail dot com=========================ageliaco.recipe.csvconfig=========================The idea behind this recipe is to have only one source of information for your buildoutvariable settings.When one is confronted with several deployments which are very similar, then you gatherthe variable elements into a csv file (just like a flat representation of several columns).For instance, let's say you need to generate several Plone instances and you want to gatherthem in a same buildout, because you will add a supervisor and a cache with varnish, plusa config for the nginx that runs on your server.Your CSV file, main.csv::instance,port,domain,subdomain,plone,emailadminalbertcair,15004,albertcair.ch,base.albertcair.ch,/,albert.cair@gmail.comalbertcair,15004,albertcair.ch,albertcair.ch,/alberto,albert.cair@gmail.comalbertcair,15004,albertcair.ch,www.albertcair.ch,/alberto,albert.cair@gmail.comalbertcair,15004,albertcair.ch,histoire.albertcair.ch,/bestie,albert.cair@gmail.comalbertcair,15004,albertcair.ch,images.albertcair.ch,/images,albert.cair@gmail.comalbertcair,15004,albertcair.ch,italiano.albertcair.ch,/italiano,albert.cair@gmail.combopip,15005,bopip.ch,base.bopip.ch,/,jm.del@gmail.combopip,15005,bopip.ch,bopip.ch,/bopip,jm.del@gmail.combopip,15005,bopip.ch,www.bopip.ch,/bopip,jm.del@gmail.combopip,15005,bopip.ch,jaun.bopip.ch,/jaun,jm.del@gmail.combopip,15005,bopip.ch,java.bopip.ch,/java,jm.del@gmail.combopip,15005,bopip.ch,math.bopip.ch,/math,jm.del@gmail.combopip,15005,bopip.ch,ecole-en-sauvygnon.ch,/ensauvygnon,jm.del@gmail.combopip,15005,bopip.ch,www.ecole-en-sauvygnon.ch,/ensauvygnon,jm.del@gmail.comIn your buildout you will be able to spread those information at different levels,that means on different templates.Let's make a *templates* directory in our buildout and we put our first templateinstances.cfg.in::[$${subdomain}-parameters]port = $${port}host = 127.0.0.1plone = $${plone}name = $${instance}and a second onevarsetting.cfg.in::[var-settings]vh-targets =$${subdomain}:$${subdomain}-parametersinstances-targets =$${instance}:$${instance}-parametersbackup-targets =backup-$${instance}:$${instance}-parameterscron-targets =cron-$${instance}:$${instance}-parameterssupervisor =20 $${instance} ${buildout:directory}/bin/$${instance} [console] true ${users:zope}eventlistener =$${instance}-HttpOk TICK_60 ${buildout:bin-directory}/httpok [-m $${emailadmin} -p $${instance} http://localhost:11011]Notice that our variables have the ``$${var}`` format.In a buildout file you will have a part that has the following form:main.cfg::[buildout]parts = maineggs = ageliaco.recipe.csvconfig[main]recipe = ageliaco.recipe.csvconfig:defaultcsvfile = main.csvtemplates = templates/varsetting.cfg.intemplates/instances.cfg.inRunning the following commands::../Python-2.7/bin/python bootstrap.py -c main.cfgbin/buildout -c main.cfgIt will generate 2 files in your buildout directory,varsetting.cfg::[var-settings]vh-targets =base.albertcair.ch:base.albertcair.ch-parametersalbertcair.ch:albertcair.ch-parameterswww.albertcair.ch:www.albertcair.ch-parametershistoire.albertcair.ch:histoire.albertcair.ch-parametersimages.albertcair.ch:images.albertcair.ch-parametersitaliano.albertcair.ch:italiano.albertcair.ch-parametersbase.bopip.ch:base.bopip.ch-parametersbopip.ch:bopip.ch-parameterswww.bopip.ch:www.bopip.ch-parametersjaun.bopip.ch:jaun.bopip.ch-parametersjava.bopip.ch:java.bopip.ch-parametersmath.bopip.ch:math.bopip.ch-parametersecole-en-sauvygnon.ch:ecole-en-sauvygnon.ch-parameterswww.ecole-en-sauvygnon.ch:www.ecole-en-sauvygnon.ch-parametersinstances-targets =albertcair:albertcair-parametersbopip:bopip-parametersbackup-targets =backup-albertcair:albertcair-parametersbackup-bopip:bopip-parameterscron-targets =cron-albertcair:albertcair-parameterscron-bopip:bopip-parameterssupervisor =20 albertcair ${buildout:directory}/bin/albertcair [console] true ${users:zope}20 bopip ${buildout:directory}/bin/bopip [console] true ${users:zope}eventlistener =albertcair-HttpOk TICK_60 ${buildout:bin-directory}/httpok [-m albert.cair@gmail.com -p albertcair http://localhost:11011]bopip-HttpOk TICK_60 ${buildout:bin-directory}/httpok [-m jm.del@gmail.com -p bopip http://localhost:11011]andinstances.cfg::[base.albertcair.ch-parameters]port = 15004host = 127.0.0.1plone = /name = albertcair[albertcair.ch-parameters]port = 15004host = 127.0.0.1plone = /albertoname = albertcair[www.albertcair.ch-parameters]port = 15004host = 127.0.0.1plone = /albertoname = albertcair[histoire.albertcair.ch-parameters]port = 15004host = 127.0.0.1plone = /bestiename = albertcair[images.albertcair.ch-parameters]port = 15004host = 127.0.0.1plone = /imagesname = albertcair[italiano.albertcair.ch-parameters]port = 15004host = 127.0.0.1plone = /italianoname = albertcair[base.bopip.ch-parameters]port = 15005host = 127.0.0.1plone = /name = bopip[bopip.ch-parameters]port = 15005host = 127.0.0.1plone = /bopipname = bopip[www.bopip.ch-parameters]port = 15005host = 127.0.0.1plone = /bopipname = bopip[jaun.bopip.ch-parameters]port = 15005host = 127.0.0.1plone = /jaunname = bopip[java.bopip.ch-parameters]port = 15005host = 127.0.0.1plone = /javaname = bopip[math.bopip.ch-parameters]port = 15005host = 127.0.0.1plone = /mathname = bopip[ecole-en-sauvygnon.ch-parameters]port = 15005host = 127.0.0.1plone = /ensauvygnonname = bopip[www.ecole-en-sauvygnon.ch-parameters]port = 15005host = 127.0.0.1plone = /ensauvygnonname = bopipvarsetting.cfg.in exposes one kind of variable substitution, when a variable is present inan option value => the option value is repeated based on the number of different result wehave in the csv file configuration, for instance the "instance" column in my csv file has2 different values then, based on that the "eventlistner" option expands in a 2 lines value.instances.cfg.in exposes another kind of variable substitution, where the variable is presentin the section identifier => the section with the "subdomain" variable will epxand in asmany sections as there are different values for this variable in the csv file.CSV as flat database :----------------------Let's see another example to show you that the csv file can be just a flat representationof a relational database.The csv file, testmultikey.csv::prenom, nom, naissance, professionbob,wut,1961,docmarie,wut,1962,maitresseserge,ren,1960,profcoco,ren,1961,maitresseThe template, templates/contact.cfg.in::[contact]$${prenom}-$${nom}-$${naissance} = $${profession}[famille-$${nom}]$${prenom}-naissance = $${naissance}$${prenom}-profession = $${profession}[annee-de-naissance-$${naissance}]$${prenom}-$${nom} = $${profession}[$${profession}]nom = $${prenom}-$${nom}-$${naissance}and now the buildout, buildout.cfg::[buildout]parts = maindevelop = src/ageliaco.recipe.csvconfigeggs =ageliaco.recipe.csvconfig[main]recipe = ageliaco.recipe.csvconfigtemplates = templates/contact.cfg.incsvfile = testmultikey.csvand the result of `bin/buildout`, contact.cfg::[contact]bob-wut-1961 = doccoco-ren-1961 = maitressemarie-wut-1962 = maitresseserge-ren-1960 = prof[famille-ren]coco-naissance = 1961serge-naissance = 1960coco-profession = maitresseserge-profession = prof[famille-wut]bob-naissance = 1961marie-naissance = 1962bob-profession = docmarie-profession = maitresse[annee-de-naissance-1961]bob-wut = doccoco-ren = maitresse[annee-de-naissance-1962]marie-wut = maitresse[annee-de-naissance-1960]serge-ren = prof[maitresse]nom = marie-wut-1962coco-ren-1961[doc]nom = bob-wut-1961[prof]nom = serge-ren-1960Detailed Documentation**********************Supported options=================The recipe supports the following options:.. Note to recipe author!----------------------For each option the recipe uses you should include a descriptionabout the purpose of the option, the format and semantics of thevalues it accepts, whether it is mandatory or optional and what thedefault value is if it is omitted.csvfilethis is a path (relative or absolute) to csv file that will be used by the recipetemplatesone (or more) path to a template file => by default, it is expected a name with ".in"suffix and a file with the same name without the suffix ".in" will be generate in thebuildout directory. If you want to use another suffix or naming convention you will haveto use an alternative format with a ":" to separate the template path to the target path,This alternate format with ":" is also interesting if you want to generate a file ina different directory than the buildout-directory!for instance::templates = templates/instances.cfg.inthat will generate a ./instances.cfg file (in the buildout directory) ortemplates = templates/init-cache.cfg:production/cache.cfgthat will generate a production/cache.cfg file (notice that in this example it is a relative path,but it can also be a full path)Contributors************"renfers", AuthorChange history**************0.7 (2013-01-10)----------------- changed from ConfigParser to configparser- added "+=" and "-=" to the delimiters, but could not recreate the same operator on optionsit passes automatically to "=" (=> still a feature to implement)["renfers"]0.6 (2013-01-07)----------------- change variable call from ${} to $${} to easily substitute variables embedded in buildout variables- added "+" to the generated file mode ("wb+" instead of "wb")["renfers"]0.5 (2012-12-28)----------------- Documentation updated["renfers"]0.4 (2012-12-26)----------------- rewrite to be sure to take into account multiple value keys. For instance, if you haveone or several variables on a part name, you can consider this set becomes a key and if there arevariables in the options we only consider values that for which key values match those ofthe part. The same can apply when the left part of an option has one or several variablesthen variables on the right part can only apply to values that have the same key values(the ones from the left part).["renfers"]0.3 (2012-12-19)----------------- Documentation updated["renfers"]0.2 (2012-12-19)----------------- Changed "update" to redo the install on update["renfers"]0.1 (2012-12-18)----------------- Created recipe with ZopeSkel["renfers"]Download********