Introduce keep_local_envs_in_vcs option

This commit is contained in:
Nikita P. Shupeyko 2018-03-06 16:49:26 +03:00
parent aba1b3aca9
commit 50c8762dd0
4 changed files with 20 additions and 12 deletions

View File

@ -192,6 +192,7 @@ Answer the prompts with your own desired options_. For example::
4 - Apache Software License 2.0
5 - Not open source
Choose from 1, 2, 3, 4, 5 [1]: 1
keep_local_envs_in_vcs [y]: y
Enter the project and take a look around::

View File

@ -39,5 +39,6 @@
"use_opbeat": "n",
"use_whitenoise": "y",
"use_heroku": "n",
"use_travisci": "n"
"use_travisci": "n",
"keep_local_envs_in_vcs": "y"
}

View File

@ -94,6 +94,11 @@ use_heroku [n]
use_travisci [n]
Indicates whether the project should be configured to use `Travis CI`_.
keep_local_envs_in_vcs [y]
Indicates whether the project's `.envs/.local/` should be kept in VCS
(comes in handy when working in teams where local environment reproducibility
is strongly encouraged).
.. _MIT: https://opensource.org/licenses/MIT
.. _BSD: https://opensource.org/licenses/BSD-3-Clause

View File

@ -216,39 +216,37 @@ def set_postgres_password(file_path):
return postgres_password
def append_to_gitignore_file(s) -> None:
def append_to_gitignore_file(s):
with open(os.path.join(PROJECT_DIR_PATH, '.gitignore'), 'a') as gitignore_file:
gitignore_file.write(s)
gitignore_file.write(os.linesep)
def initialize_envs(postgres_user):
envs_dir_path = '.envs'
def set_flags_in_envs(postgres_user):
append_to_gitignore_file('.envs' + '/**/*')
append_to_gitignore_file(envs_dir_path + '/**/*')
local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.local', '.postgres')
local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.local', '.postgres')
set_postgres_user(local_postgres_envs_path, value=postgres_user)
set_postgres_password(local_postgres_envs_path)
production_django_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.production', '.django')
production_django_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.production', '.django')
set_django_secret_key(production_django_envs_path)
set_django_admin_url(production_django_envs_path)
production_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.production', '.postgres')
production_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.production', '.postgres')
set_postgres_user(production_postgres_envs_path, value=postgres_user)
set_postgres_password(production_postgres_envs_path)
def initialize_settings_files():
def set_flags_in_settings_files():
set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'local.py'))
set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'test.py'))
def main():
postgres_user = generate_postgres_user()
initialize_envs(postgres_user)
initialize_settings_files()
set_flags_in_envs(postgres_user)
set_flags_in_settings_files()
if '{{ cookiecutter.open_source_license }}' == 'Not open source':
remove_open_source_project_only_files()
@ -293,6 +291,9 @@ def main():
if '{{ cookiecutter.use_travisci }}'.lower() == 'n':
remove_dottravisyml_file()
if '{{ cookiecutter.keep_local_envs_in_vcs }}'.lower() == 'y':
append_to_gitignore_file('!.envs/.local/')
if __name__ == '__main__':
main()