Handle boolean settings
authorThierry Florac <thierry.florac@onf.fr>
Mon, 15 Jan 2018 16:27:44 +0100
changeset 27 610088bc5214
parent 26 f5de6b8a05b6
child 28 68a6f23fcf38
Handle boolean settings
cookiecutter.json
hooks/post_gen_project.py
{{cookiecutter.project_slug}}/buildout.cfg
{{cookiecutter.project_slug}}/etc/development.ini
{{cookiecutter.project_slug}}/etc/production.ini
{{cookiecutter.project_slug}}/setup.py
--- a/cookiecutter.json	Sun Jan 14 12:29:44 2018 +0100
+++ b/cookiecutter.json	Mon Jan 15 16:27:44 2018 +0100
@@ -15,9 +15,9 @@
   "db_host": "127.0.0.1",
   "db_port": "8100",
   "db_name": "{{ cookiecutter.project_slug }}",
-  "db_username": "zeouser",
+  "db_username": "",
   "db_password": "",
-  "zeo_realm": "{{ cookiecutter.project_slug }}",
+  "zeo_realm": "",
   "blobs_dir": "$((INSTALL)/var/db/blobs",
   "use_postgresql": true,
   "use_oracle": false,
--- a/hooks/post_gen_project.py	Sun Jan 14 12:29:44 2018 +0100
+++ b/hooks/post_gen_project.py	Mon Jan 15 16:27:44 2018 +0100
@@ -71,7 +71,7 @@
             print("WARNING: Can't set permissions for file {0}".format(target))
 
 
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
 
 #
 # Check Elasticsearch index
@@ -80,7 +80,7 @@
 curl = shutil.which('curl')
 have_curl = bool(curl)
 
-{%- if cookiecutter.create_elasticsearch_index %}
+{%- if cookiecutter.create_elasticsearch_index.lower() in ('true','on','yes','1') %}
 if have_curl:
     json_dir = os.path.join(TARGET, 'docs', 'elasticsearch')
     try:
@@ -96,7 +96,7 @@
     print("WARNING: You must install CURL to be able to initialize ElasticSearch index!")
 {%- endif %}
 
-{%- if cookiecutter.define_elasticsearch_mappings %}
+{%- if cookiecutter.define_elasticsearch_mappings.lower() in ('true','on','yes','1') %}
 if have_curl:
     mappings_dir = os.path.join(TARGET, 'docs', 'elasticsearch', 'mappings')
     try:
@@ -119,10 +119,10 @@
 print("To finalize it's creation, just type:")
 print("- cd {{ cookiecutter.project_slug }}")
 print("- python3.5 bootstrap.py")
-{%- if cookiecutter.use_oracle %}
+{%- if cookiecutter.use_oracle.lower() in ('true','on','yes','1') %}
 print("- export ORACLE_HOME=/path/to/your/oracle/client")
 {%- endif %}
-{%- if cookiecutter.need_pyams_gis %}
+{%- if cookiecutter.need_pyams_gis.lower() in ('true','on','yes','1') %}
 print("- apt-get install libgdal-dev")
 print("- export CPLUS_INCLUDE_PATH=/usr/include/gdal")
 print("- export C_INCLUDE_PATH=/usr/include/gdal")
--- a/{{cookiecutter.project_slug}}/buildout.cfg	Sun Jan 14 12:29:44 2018 +0100
+++ b/{{cookiecutter.project_slug}}/buildout.cfg	Mon Jan 15 16:27:44 2018 +0100
@@ -34,24 +34,24 @@
 {%- if cookiecutter.beaker_backend == 'redis' %}
     beakeredis
 {%- endif %}
-{%- if cookiecutter.use_oracle %}
+{%- if cookiecutter.use_oracle.lower() in ('true','on','yes','1') %}
     cx_Oracle
 {%- endif %}
     fanstatic
     nose
-{%- if cookiecutter.use_postgresql %}
+{%- if cookiecutter.use_postgresql in ('true','on','yes','1') %}
     psycopg2
 {%- endif %}
     pyams_alchemy
     pyams_catalog
     pyams_content
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch in ('true','on','yes','1') %}
     pyams_content_es
 {%- endif %}
     pyams_file
     pyams_form
     pyams_i18n
-{%- if cookiecutter.use_ldap %}
+{%- if cookiecutter.use_ldap in ('true','on','yes','1') %}
     pyams_ldap
 {%- endif %}
     pyams_mail
@@ -78,7 +78,7 @@
     pyramid_beaker
     pyramid_chameleon
     pyramid_debugtoolbar
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch in ('true','on','yes','1') %}
     pyramid_es
 {%- endif %}
     pyramid_fanstatic
--- a/{{cookiecutter.project_slug}}/etc/development.ini	Sun Jan 14 12:29:44 2018 +0100
+++ b/{{cookiecutter.project_slug}}/etc/development.ini	Mon Jan 15 16:27:44 2018 +0100
@@ -17,7 +17,7 @@
     pyramid_zodbconn
     pyramid_tm
     pyramid_retry
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
     pyramid_es
 {%- endif %}
     pyramid_rpc.jsonrpc
@@ -34,7 +34,7 @@
     pyams_zodbbrowser
     pyams_catalog
     pyams_mail
-{%- if cookiecutter.use_ldap %}
+{%- if cookiecutter.use_ldap.lower() in ('true','on','yes','1') %}
     pyams_ldap
 {%- endif %}
     pyams_cache
@@ -47,11 +47,11 @@
     pyams_portal
     pyams_media
     pyams_notify
-{%- if cookiecutter.need_pyams_gis %}
+{%- if cookiecutter.need_pyams_gis.lower() in ('true','on','yes','1') %}
     pyams_gis
 {%- endif %}
     pyams_content
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
     pyams_content_es
 {%- endif %}
     pyams_default_theme
@@ -74,7 +74,7 @@
 fanstatic.bottom = true
 fanstatic.debug = true
 
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
 
 # ElasticSearch settings
 elastic.server = {{ cookiecutter.elasticsearch_server }}
--- a/{{cookiecutter.project_slug}}/etc/production.ini	Sun Jan 14 12:29:44 2018 +0100
+++ b/{{cookiecutter.project_slug}}/etc/production.ini	Mon Jan 15 16:27:44 2018 +0100
@@ -16,7 +16,7 @@
     pyramid_zodbconn
     pyramid_tm
     pyramid_retry
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
     pyramid_es
 {%- endif %}
     pyramid_rpc.jsonrpc
@@ -33,7 +33,7 @@
     pyams_zodbbrowser
     pyams_catalog
     pyams_mail
-{%- if cookiecutter.use_ldap %}
+{%- if cookiecutter.use_ldap.lower() in ('true','on','yes','1') %}
     pyams_ldap
 {%- endif %}
     pyams_cache
@@ -46,11 +46,11 @@
     pyams_portal
     pyams_media
     pyams_notify
-{%- if cookiecutter.need_pyams_gis %}
+{%- if cookiecutter.need_pyams_gis.lower() in ('true','on','yes','1') %}
     pyams_gis
 {%- endif %}
     pyams_content
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
     pyams_content_es
 {%- endif %}
     pyams_default_theme
@@ -69,7 +69,7 @@
 fanstatic.bottom = true
 fanstatic.debug = false
 
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
 
 # ElasticSearch settings
 elastic.server = {{ cookiecutter.elasticsearch_server }}
--- a/{{cookiecutter.project_slug}}/setup.py	Sun Jan 14 12:29:44 2018 +0100
+++ b/{{cookiecutter.project_slug}}/setup.py	Mon Jan 15 16:27:44 2018 +0100
@@ -13,7 +13,7 @@
 {%- if cookiecutter.beaker_backend == 'redis' %}
     'beakeredis',
 {%- endif %}
-{%- if cookiecutter.use_oracle %}
+{%- if cookiecutter.use_oracle.lower() in ('true','on','yes','1') %}
     'cx_Oracle',
 {%- endif %}
     'fanstatic',
@@ -21,23 +21,23 @@
     'newt.db',
 {%- endif %}
     'nose',
-{%- if cookiecutter.use_postgresql %}
+{%- if cookiecutter.use_postgresql.lower() in ('true','on','yes','1') %}
     'psycopg2',
 {%- endif %}
     'pyams_alchemy',
     'pyams_catalog',
     'pyams_content',
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
     'pyams_content_es',
 {%- endif %}
     'pyams_default_theme',
     'pyams_file',
     'pyams_form',
-{%- if cookiecutter.need_pyams_gis %}
+{%- if cookiecutter.need_pyams_gis.lower() in ('true','on','yes','1') %}
     'pyams_gis',
 {%- endif %}
     'pyams_i18n',
-{%- if cookiecutter.use_ldap %}
+{%- if cookiecutter.use_ldap.lower() in ('true','on','yes','1') %}
     'pyams_ldap',
 {%- endif %}
     'pyams_notify',
@@ -62,7 +62,7 @@
     'pyramid_beaker',
     'pyramid_chameleon',
     'pyramid_debugtoolbar',
-{%- if cookiecutter.use_elasticsearch %}
+{%- if cookiecutter.use_elasticsearch.lower() in ('true','on','yes','1') %}
     'pyramid_es',
 {%- endif %}
     'pyramid_fanstatic',