fabric/modules/configuration_setup.py
Ronny Abraham 2bef12902e new file: api.py
new file:   api.pyc
	new file:   conf/fabric.yml
	new file:   fabfile.py
	new file:   fabfile.pyc
	new file:   modules/__init__.py
	new file:   modules/__init__.pyc
	new file:   modules/conf_setup.py
	new file:   modules/conf_setup.pyc
	new file:   modules/configuration_setup.py
	new file:   modules/database.py
	new file:   modules/database.pyc
	new file:   modules/deploy.py
	new file:   modules/deploy.pyc
	new file:   modules/django.py
	new file:   modules/django.pyc
	new file:   modules/docker.py
	new file:   modules/docker.pyc
	new file:   modules/initialize.py
	new file:   modules/initialize.pyc
	new file:   modules/maintenance.py
	new file:   modules/maintenance.pyc
	new file:   modules/nginx.py
	new file:   modules/nginx.pyc
	new file:   modules/pip.py
	new file:   modules/pip.pyc
	new file:   modules/setup.pyc
	new file:   modules/supervisor.py
	new file:   modules/supervisor.pyc
	new file:   modules/testing/__init__.py
	new file:   modules/testing/__init__.pyc
	new file:   modules/testing/configuration_setup.py
	new file:   modules/testing/maintenance.pyc
	new file:   modules/utils.py
	new file:   modules/utils.pyc
	new file:   templates/conf/database/files/db.drop_all.sql.jinja2
	new file:   templates/conf/database/files/db.drop_db.sql.jinja2
	new file:   templates/conf/database/files/db.init.sql.jinja2
	new file:   templates/conf/database/files/db.re_init.sql.jinja2
	new file:   templates/conf/django/files/gunicorn.jinja2
	new file:   templates/conf/django/files/gunicorn.unixsocket.jinja2
	new file:   templates/conf/django/files/local.jinja2
	new file:   templates/conf/django/files/settings.jinja2
	new file:   templates/conf/django/files/settings18.jinja2
	new file:   templates/conf/django/files/wsgi.jinja2
	new file:   templates/conf/django/files/wsgi.py
	new file:   templates/conf/docker/files/database.jinja2
	new file:   templates/conf/gunicorn/files/gunicorn.jinja2
	new file:   templates/conf/gunicorn/files/gunicorn.unixsocket.jinja2
	new file:   templates/conf/gunicorn/files/local.jinja2
	new file:   templates/conf/gunicorn/files/settings.jinja2
	new file:   templates/conf/gunicorn/files/settings18.jinja2
	new file:   templates/conf/gunicorn/files/wsgi.jinja2
	new file:   templates/conf/gunicorn/files/wsgi.py
	new file:   templates/conf/nginx/files/default.conf.jinja2
	new file:   templates/conf/nginx/files/unixsocket.jinja2
	new file:   templates/conf/supervisor/files/conf_old
	new file:   templates/conf/supervisor/files/supervisor.jinja2
	new file:   templates/meta/development.yml
	new file:   templates/meta/layout.yml
	new file:   templates/meta/staging.yml
	new file:   templates/readmes/aws.md
	new file:   templates/readmes/gandi.md
	new file:   templates/readmes/reset_migrations.md
	new file:   templates/readmes/setup_gandi.md
	new file:   templates/readmes/translations.md
	new file:   templates/readmes/update_images.md
2016-09-06 14:43:49 +03:00

160 lines
4.5 KiB
Python

from fabric.contrib.files import exists as fab_exists
from fabric.operations import run
from fabric.api import env
import os
import sys
import utils
def check_version(section):
pass
def check_is_conf(section, handle_error=False):
"""confirms that the configuration section name passed is a legit one
Keyword Arguments:
section -- the configuration section we are looking at
handle_error -- if True, print out an error message and exit
"""
configuration = env.config
if section in configuration.templates.keys():
return True
else:
if handle_error:
print """
Error. maintenance.exists_dir_sub takes a 'section' parameter value.
'%s' is not a valid parameter value.
Valid options include:""" % section
for key in configuration.templates.keys():
print " %s" % key
print """
Please run the command again, but this time enter a valid section value.
"""
sys.exit()
return False
def exists_dir_top():
""" Check if the parent directory for all configuration files exists"""
from fabric.contrib.files import exists
configuration = env.config
# NOTE
# all template configuration files are built off the files that are
# contained LOCALLY. I don't bother building them off the remotely
# located files, since those files get rsync'd anyway.
if env.debug:
print "maintenance.exists_dir_top -- checking for " \
"directory:\n\t%s\n" % configuration.paths.conf.local
return exists(configuration.paths.conf.local)
def exists_dir_sub(section):
"""Check if the subdirectory for this configuration type exists in the
configuration directory
Keyword Arguments:
section -- the configuration section we are looking at
"""
configuration = env.config
# NOTE
# all template configuration files are built off the files that are
# contained LOCALLY. I don't bother building them off the remotely
# located files, since those files get rsync'd anyway.
check_is_conf(section)
_template = getattr(configuration.templates, section)
if env.debug:
utils.printvar('template.path.local', _template.path.local)
path_test = os.path.join(_template.path.local, 'blah')
utils.printvar('exists_path_test', fab_exists(path_test))
utils.printvar('exists_local', fab_exists(_template.path.local))
else:
return fab_exists(_template.path.local)
def exists_file(section):
"""Check if the template file for this configuration type exists in the
configuration directory
Keyword Arguments:
section -- the configuration type
"""
configuration = env.config
check_is_conf(section)
exists_dir_sub(section)
utils.print_console("\tNOTE: exists_file ONLY works when run on the"
" local branch!\n\tThis is because it is set up to "
" only check development template config files",
numsep=90)
_template = getattr(configuration.templates, section)
path_src = os.path.join(
_template.path.local,
'files',
_template.conf.src)
if env.debug:
utils.printvar('template.path.local', _template.path.local)
utils.printvar('template.src', _template.conf.src)
utils.printvar('template.dst', _template.conf.dst)
utils.printvar('path_src', path_src)
utils.printvar('path_exists', fab_exists(path_src))
return fab_exists(path_src)
# TODO
# DONE 1. make sure the configuration request is legit for this branch
# DONE 2. check to see if conf directory exists
# DONE 3. check to see if conf template file exists
# 4a. (optional) add switch to check if conf file was built from template
# 4b. (optional) check to see if version is up to date
def create_dir():
# TODO
# 1. make sure the configuration request is legit for this branch
# 2. check to see if conf dir already exists
# 3. if not create it
pass
def create_dir_top():
"""Creates the top level conf directory if it does not exist"""
import utils
configuration = env.config
if not exists_dir_top():
cmd_mkdir = "mkdir %s" % configuration.paths.conf.remote
run(cmd_mkdir)
else:
msg = "configuration directory already exists, aborting create." \
"Continue? Y/n"
utils.prompt_continue(message=msg)
def create_file():
pass