updated database files so that user and database names are put in quotes, also fixed some problems with pip
This commit is contained in:
parent
82b8699533
commit
5c75151f2b
6 changed files with 86 additions and 68 deletions
|
|
@ -95,7 +95,7 @@ def edit(remote_path, host_string=None):
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
editor = "mvim"
|
editor = "mvim"
|
||||||
else:
|
else:
|
||||||
editor = "nvim"
|
editor = "mvim"
|
||||||
|
|
||||||
# if env.key_filename:
|
# if env.key_filename:
|
||||||
# cmd_edit = "{editor} sftp://{user}@{host_string}/{remote_path}" \
|
# cmd_edit = "{editor} sftp://{user}@{host_string}/{remote_path}" \
|
||||||
|
|
|
||||||
122
modules/pip.py
122
modules/pip.py
|
|
@ -1,14 +1,20 @@
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
from fabric.api import env, task
|
from fabric.api import env, task
|
||||||
from fabric.operations import run
|
from fabric.operations import run
|
||||||
from fabric.context_managers import hide, settings
|
from fabric.context_managers import hide, settings
|
||||||
from fabric.utils import abort
|
from fabric.utils import abort
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from .utils import virtualenv_source, virtualenv
|
from .utils import virtualenv_source, virtualenv
|
||||||
from .utils import printerr
|
from .utils import printerr
|
||||||
|
from .utils import booleanize, handle_flag_message
|
||||||
|
from .utils import prompt_continue
|
||||||
|
from .utils import upload_template
|
||||||
|
|
||||||
|
from .initialize import get_config
|
||||||
|
|
||||||
|
|
||||||
ERROR_BAD_BRANCH_PARAM = -3
|
ERROR_BAD_BRANCH_PARAM = -3
|
||||||
ERROR_BAD_PARAM = -2
|
ERROR_BAD_PARAM = -2
|
||||||
|
|
@ -46,34 +52,32 @@ def setup_virtualenv(python3=True):
|
||||||
if python3:
|
if python3:
|
||||||
mkvirtualenv_cmd += "--python=python3 "
|
mkvirtualenv_cmd += "--python=python3 "
|
||||||
|
|
||||||
mkvirtualenv_cmd += "{virtualenv_name}".format(
|
mkvirtualenv_cmd += f"{configuration.virtualenv.name}"
|
||||||
virtualenv_name=configuration.virtualenv.name)
|
|
||||||
|
|
||||||
if env.debug:
|
if env.debug:
|
||||||
|
|
||||||
logging.debug("python3 install: %s" % python3)
|
logging.debug("python3 install: %s", python3)
|
||||||
|
|
||||||
logging.debug("virtualenv.workon : %s"
|
logging.debug("virtualenv.workon : %s",
|
||||||
% configuration.virtualenv.workon)
|
configuration.virtualenv.workon)
|
||||||
|
|
||||||
logging.debug("virtualenv.activate : %s"
|
logging.debug("virtualenv.activate : %s",
|
||||||
% configuration.virtualenv.activate)
|
configuration.virtualenv.activate)
|
||||||
|
|
||||||
logging.debug("virtualenv.name : %s"
|
logging.debug("virtualenv.name : %s",
|
||||||
% configuration.virtualenv.name)
|
configuration.virtualenv.name)
|
||||||
|
|
||||||
logging.debug("virtualenv.paths.bin : %s"
|
logging.debug("virtualenv.paths.bin : %s",
|
||||||
% configuration.virtualenv.paths.bin)
|
configuration.virtualenv.paths.bin)
|
||||||
|
|
||||||
logging.debug("virtualenv.paths.root : %s"
|
logging.debug("virtualenv.paths.root : %s",
|
||||||
% configuration.virtualenv.paths.root)
|
configuration.virtualenv.paths.root)
|
||||||
|
|
||||||
logging.debug("mkvirtualenv_cmd: %s" % mkvirtualenv_cmd)
|
logging.debug("mkvirtualenv_cmd: %s", mkvirtualenv_cmd)
|
||||||
|
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"with virtualenv_source(): "
|
"with virtualenv_source(): "
|
||||||
"run(\"\n\t{mkvirtualenv_cmd}\n\t\")".format(
|
"run(\"\n\t%s\n\t\")", mkvirtualenv_cmd)
|
||||||
mkvirtualenv_cmd=mkvirtualenv_cmd))
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# run("source virtualenvwrapper.sh; mkvirtualenv "
|
# run("source virtualenvwrapper.sh; mkvirtualenv "
|
||||||
|
|
@ -123,7 +127,7 @@ def update_pip():
|
||||||
pipinstall_cmd = "pip install --upgrade pip"
|
pipinstall_cmd = "pip install --upgrade pip"
|
||||||
|
|
||||||
if env.debug:
|
if env.debug:
|
||||||
logging.debug("with virtualenv(): run(\"\n\t%s\n\t\")" %
|
logging.debug("with virtualenv(): run(\"\n\t%s\n\t\")",
|
||||||
pipinstall_cmd)
|
pipinstall_cmd)
|
||||||
else:
|
else:
|
||||||
with virtualenv():
|
with virtualenv():
|
||||||
|
|
@ -150,11 +154,13 @@ def setup():
|
||||||
format='\n%(levelname)s: deploy.pip %(message)s',
|
format='\n%(levelname)s: deploy.pip %(message)s',
|
||||||
level=logging.DEBUG)
|
level=logging.DEBUG)
|
||||||
|
|
||||||
pipinstall_cmd = "pip install -r {requirements}".format(
|
pipinstall_cmd = (
|
||||||
requirements=configuration.virtualenv.requirements.filepath)
|
f"pip install -r "
|
||||||
|
f"{configuration.virtualenv.requirements.filepath}"
|
||||||
|
)
|
||||||
|
|
||||||
if env.debug:
|
if env.debug:
|
||||||
logging.debug("with virtualenv(): run(\"\n\t%s\n\t\")" %
|
logging.debug("with virtualenv(): run(\"\n\t%s\n\t\")",
|
||||||
pipinstall_cmd)
|
pipinstall_cmd)
|
||||||
else:
|
else:
|
||||||
with virtualenv():
|
with virtualenv():
|
||||||
|
|
@ -181,14 +187,17 @@ def install(package_name=None):
|
||||||
abort("You must specify a package name to be installed")
|
abort("You must specify a package name to be installed")
|
||||||
|
|
||||||
if package_name == "--all":
|
if package_name == "--all":
|
||||||
pipinstall_cmd = "pip install -r {requirements_file}".format(
|
pipinstall_cmd = (
|
||||||
requirements_file=configuration.virtualenv.requirements.filepath)
|
f"pip install -r "
|
||||||
|
f"{configuration.virtualenv.requirements.filepath}"
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pipinstall_cmd = "pip install {package}".format(
|
pipinstall_cmd = f"pip install {package_name}"
|
||||||
package=package_name)
|
|
||||||
|
|
||||||
if env.debug:
|
if env.debug:
|
||||||
print("pipinstall_cmd: %s" % pipinstall_cmd)
|
print(f"pipinstall_cmd: {pipinstall_cmd}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with virtualenv():
|
with virtualenv():
|
||||||
run(pipinstall_cmd)
|
run(pipinstall_cmd)
|
||||||
|
|
@ -231,8 +240,6 @@ def freeze(param='help'):
|
||||||
\tFalse (default) - print the freeze output to the console
|
\tFalse (default) - print the freeze output to the console
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .utils import booleanize, handle_flag_message
|
|
||||||
|
|
||||||
if handle_flag_message(param, msg_help, 'help'):
|
if handle_flag_message(param, msg_help, 'help'):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
|
|
@ -240,15 +247,17 @@ def freeze(param='help'):
|
||||||
param = booleanize(param)
|
param = booleanize(param)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
printerr(
|
printerr(
|
||||||
"the parameter value you gave, '{param}' , is not a "
|
f"the parameter value you gave, '{param}',"
|
||||||
"valid parameter\n{msg_help}".format(
|
f" is not a valid parameter\n{msg_help}",
|
||||||
param=param, msg_help=msg_help),
|
|
||||||
ERROR_BAD_PARAM
|
ERROR_BAD_PARAM
|
||||||
)
|
)
|
||||||
|
|
||||||
if param:
|
if param:
|
||||||
cmd_pipfreeze = "pip freeze > {requirements}".format(
|
cmd_pipfreeze = (
|
||||||
requirements=configuration.virtualenv.requirements.filepath)
|
f"pip freeze > "
|
||||||
|
f"{configuration.virtualenv.requirements.filepath}"
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cmd_pipfreeze = "pip freeze"
|
cmd_pipfreeze = "pip freeze"
|
||||||
|
|
||||||
|
|
@ -257,44 +266,48 @@ def freeze(param='help'):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def copyto(branch):
|
def copyto(branch=None):
|
||||||
"""
|
"""
|
||||||
copy requirements from the current branch to the specified branch
|
copy requirements from the current branch to the specified branch
|
||||||
|
|
||||||
this only changes the requirements on the local branches. It does not
|
this only changes the requirements on the local branches. It does not
|
||||||
upload remotely. This is because I want to use deploy.sync to do all
|
upload remotely. Use deploy.sync to perform remote updates.
|
||||||
remote updates
|
|
||||||
|
|
||||||
Keyword Arguments:
|
Keyword Arguments:
|
||||||
branch -- the branch to copy to
|
branch -- the branch to copy to
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
fab copyto --branch=staging
|
||||||
"""
|
"""
|
||||||
|
|
||||||
configuration = env.config
|
if branch is None:
|
||||||
|
printerr(
|
||||||
|
"Missing required parameter: 'branch'\n"
|
||||||
|
"Usage: fab pip.copyto:<branch>\n"
|
||||||
|
"Valid options: development, staging, production",
|
||||||
|
ERROR_BAD_BRANCH_PARAM
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
configuration = env.config
|
||||||
branch_list = ['staging', 'production', 'development']
|
branch_list = ['staging', 'production', 'development']
|
||||||
|
|
||||||
if branch not in branch_list:
|
if branch not in branch_list:
|
||||||
|
|
||||||
printerr(
|
printerr(
|
||||||
"Branch parameter '{branch}' must be one of {branchlist} "
|
f"Branch parameter '{branch}' must be one of {branch_list} "
|
||||||
"values.".format(branch=branch, branchlist=branch_list),
|
"values.", ERROR_BAD_BRANCH_PARAM)
|
||||||
ERROR_BAD_BRANCH_PARAM)
|
|
||||||
|
|
||||||
elif branch == 'development':
|
elif branch == 'development':
|
||||||
|
|
||||||
printerr(
|
printerr(
|
||||||
"This method does not allow copying to development branch",
|
"This method does not allow copying to development branch",
|
||||||
ERROR_BAD_BRANCH_PARAM)
|
ERROR_BAD_BRANCH_PARAM)
|
||||||
|
|
||||||
elif configuration.project.branch == branch:
|
elif configuration.project.branch == branch:
|
||||||
|
|
||||||
printerr(
|
printerr(
|
||||||
"You have set the source branch to the current branch."
|
"You have set the source branch to the current branch."
|
||||||
"This will simply copy over \n\tthe requirements file for "
|
"This will simply copy over \n\tthe requirements file for "
|
||||||
"this branch with itself", ERROR_BAD_BRANCH_PARAM)
|
"this branch with itself", ERROR_BAD_BRANCH_PARAM)
|
||||||
|
|
||||||
from .initialize import get_config
|
|
||||||
|
|
||||||
branch_config = get_config(branch)
|
branch_config = get_config(branch)
|
||||||
|
|
||||||
current_local_path = os.path.join(
|
current_local_path = os.path.join(
|
||||||
|
|
@ -305,17 +318,16 @@ def copyto(branch):
|
||||||
configuration.virtualenv.requirements.local,
|
configuration.virtualenv.requirements.local,
|
||||||
branch_config.virtualenv.requirements.filename)
|
branch_config.virtualenv.requirements.filename)
|
||||||
|
|
||||||
print("current_local_path: %s" % current_local_path)
|
print(f"current_local_path: {current_local_path}")
|
||||||
print("branch_local_path: %s" % branch_local_path)
|
print("branch_local_path: {branch_local_path}")
|
||||||
|
|
||||||
message = "Copying file from current branch '{branch_src}' to " \
|
message = (
|
||||||
"destination branch '{branch_dst}'. Continue? Y/n ".format(
|
f"Copying file from current branch '{configuration.project.branch}'"
|
||||||
branch_src=configuration.project.branch, branch_dst=branch)
|
f"to destination branch '{branch}'. Continue? Y/n "
|
||||||
|
)
|
||||||
|
|
||||||
from .utils import prompt_continue
|
|
||||||
prompt_continue(message=message)
|
prompt_continue(message=message)
|
||||||
|
|
||||||
from .utils import upload_template
|
|
||||||
upload_template(
|
upload_template(
|
||||||
filename=configuration.virtualenv.requirements.filename,
|
filename=configuration.virtualenv.requirements.filename,
|
||||||
destination=branch_local_path,
|
destination=branch_local_path,
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
DROP DATABASE {{db_name}};
|
DROP DATABASE '{{db_name}}';
|
||||||
DROP USER {{db_user}};
|
DROP USER '{{db_user}}';
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
DROP DATABASE {{db_name}};
|
DROP DATABASE '{{db_name}}';
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
CREATE USER {{db_user}} WITH PASSWORD '{{db_password}}';
|
CREATE USER '{{db_user}}' WITH PASSWORD '{{db_password}}';
|
||||||
ALTER USER {{db_user}} CREATEDB;
|
ALTER USER '{{db_user}}' CREATEDB;
|
||||||
CREATE DATABASE {{db_name}} WITH ENCODING='UTF8';
|
|
||||||
ALTER DATABASE {{db_name}} OWNER TO {{db_user}};
|
CREATE DATABASE '{{db_name}}' WITH ENCODING='UTF8';
|
||||||
GRANT ALL PRIVILEGES ON DATABASE {{db_name}} TO {{db_user}};
|
ALTER DATABASE '{{db_name}}' OWNER TO '{{db_user}}';
|
||||||
|
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE '{{db_name}}' TO '{{db_user}}';
|
||||||
|
GRANT ALL ON SCHEMA public TO '{{db_user}}';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
DROP DATABASE {{db_name}};
|
DROP DATABASE '{{db_name}}';
|
||||||
CREATE DATABASE {{db_name}} WITH ENCODING='UTF8';
|
|
||||||
ALTER DATABASE {{db_name}} OWNER TO {{db_user}};
|
CREATE DATABASE '{{db_name}}' WITH ENCODING='UTF8';
|
||||||
GRANT ALL PRIVILEGES ON DATABASE {{db_name}} TO {{db_user}};
|
ALTER DATABASE '{{db_name}}' OWNER TO '{{db_user}}';
|
||||||
|
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE '{{db_name}}' TO '{{db_user}}';
|
||||||
|
GRANT ALL ON SCHEMA public TO '{{db_user}}';
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue