Merge branch 'majorchange' of bitbucket.org:ronnyabraham/fabric into majorchange

This commit is contained in:
Ronny Abraham 2016-09-21 16:18:34 +03:00
commit 0ad9e5b772
7 changed files with 128 additions and 24 deletions

View file

@ -76,7 +76,7 @@ def nested_set(dic, keys, value):
class DeployMeta(QtGui.QMainWindow):
PATH_META = "../../../meta/configuration"
PATH_META = "../../../meta/project"
PATH_TEMPLATES = "../share/templates/meta"
path_meta = None
@ -229,7 +229,7 @@ class DeployMeta(QtGui.QMainWindow):
'title': 'Nginx Port',
'location': 'nginx.port',
'default': {
'development': "8050",
'development': "8080",
'staging': "80",
'production': "80",
},

View file

@ -74,7 +74,7 @@ def create_path(path_str, delimiter="/"):
def main():
path_meta = create_path("../../meta/configuration")
path_meta = create_path("../../../meta/project")
args = parser.parse_args()

View file

@ -36,7 +36,7 @@ def test(args=None):
@task
def manage_commandline(args=""):
def commandline(args=""):
"""
prints out what you need to run on the command line to invoke manage.py
"""

View file

@ -490,10 +490,21 @@ def _init_virtualenv(configuration, config, layout):
virtualenv_requirements = "{branch}.txt".format(
branch=configuration.project.branch)
configuration.virtualenv.requirements = os.path.join(
configuration.virtualenv.addbranch('requirements')
configuration.virtualenv.requirements.local = os.path.join(
configuration.paths.project.local,
layout['virtualenv']['requirements'])
configuration.virtualenv.requirements.remote = os.path.join(
configuration.paths.project.root,
layout['virtualenv']['requirements'],
virtualenv_requirements)
layout['virtualenv']['requirements'])
configuration.virtualenv.requirements.filename = virtualenv_requirements
configuration.virtualenv.requirements.filepath = os.path.join(
configuration.virtualenv.requirements.remote,
configuration.virtualenv.requirements.filename)
#
# determine the virtualenv name, if it is set as "Null"

View file

@ -1,10 +1,15 @@
from fabric.api import env, task
from fabric.operations import run
import sys
import os
import logging
from utils import virtualenv_source, virtualenv
from utils import print_console
from utils import print_console, printerr
ERROR_BAD_BRANCH_PARAM = -3
ERROR_BAD_PARAM = -2
@task
@ -61,7 +66,7 @@ def setup():
level=logging.DEBUG)
pipinstall_cmd = "pip install -r {requirements}".format(
requirements=configuration.virtualenv.requirements)
requirements=configuration.virtualenv.requirements.filepath)
if env.debug:
logging.debug("with virtualenv(): run(\"\n\t%s\n\t\")" %
@ -78,15 +83,12 @@ def install(package=None):
"""
configuration = env.config
import sys
if not package:
print_console("you must specify a package to be installed")
sys.exit()
printerr("You must specify a package to be installed", ERROR_BAD_PARAM)
if package == "--all":
pipinstall_cmd = "pip install -r {requirements_file}".format(
requirements_file=configuration.virtualenv.requirements)
requirements_file=configuration.virtualenv.requirements.filepath)
else:
pipinstall_cmd = "pip install {package}".format(
package=package)
@ -101,6 +103,9 @@ def install(package=None):
@task
def freeze(param='help'):
"""
True - update package list and freeze output
"""
configuration = env.config
msg_help = """
@ -111,7 +116,6 @@ def freeze(param='help'):
"""
from utils import booleanize, handle_help
import sys
if handle_help(param, msg_help, 'help'):
sys.exit()
@ -119,16 +123,88 @@ def freeze(param='help'):
try:
param = booleanize(param)
except TypeError:
print "the parameter value you gave, \"%s\" , is not" \
" a valid parameter." % param
print msg_help
sys.exit()
printerr(
"the parameter value you gave, '{param}' , is not a "
"valid parameter\n{msg_help}".format(
param=param, msg_help=msg_help),
ERROR_BAD_PARAM
)
if param:
cmd_pipfreeze = "pip freeze > {requirements}".format(
requirements=configuration.virtualenv.requirements)
requirements=configuration.virtualenv.requirements.filepath)
else:
cmd_pipfreeze = "pip freeze"
with virtualenv():
run(cmd_pipfreeze)
@task
def copyto(branch):
"""
copy requirements from the current branch to the specified branch
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
remote updates
Keyword Arguments:
branch -- the branch to copy to
"""
configuration = env.config
branch_list = ['staging', 'production', 'development']
if branch not in branch_list:
printerr(
"Branch parameter '{branch}' must be one of {branchlist} "
"values.".format(branch=branch, branchlist=branch_list),
ERROR_BAD_BRANCH_PARAM)
elif branch == 'development':
printerr(
"This method does not allow copying to development branch",
ERROR_BAD_BRANCH_PARAM)
elif configuration.project.branch == branch:
printerr(
"You have set the source branch to the current branch."
"This will simply copy over \n\tthe requirements file for "
"this branch with itself", ERROR_BAD_BRANCH_PARAM)
from initialize import get_config
branch_config = get_config(branch)
current_local_path = os.path.join(
configuration.virtualenv.requirements.local,
configuration.virtualenv.requirements.filename)
branch_local_path = os.path.join(
configuration.virtualenv.requirements.local,
branch_config.virtualenv.requirements.filename)
print "current_local_path: %s" % current_local_path
print "branch_local_path: %s" % branch_local_path
message = "Copying file from current branch '{branch_src}' to " \
"destination branch '{branch_dst}'. Continue? Y/n ".format(
branch_src=configuration.project.branch, branch_dst=branch)
from utils import prompt_continue
prompt_continue(message=message)
from utils import upload_template
upload_template(
filename=configuration.virtualenv.requirements.filename,
destination=branch_local_path,
context=None,
use_jinja=False,
use_sudo=False,
backup=True,
template_dir=configuration.virtualenv.requirements.local)

View file

@ -1,4 +1,5 @@
import os
import sys
import errno
import logging
@ -12,10 +13,27 @@ from fabric.operations import run, sudo
def printvar(name, value, exit=False):
print "%s : %s" % (name, value)
if exit:
import sys
sys.exit()
def printerr(message="", errcode=-2, exit=True):
""" prints error message and error code then exits
Keyword Arguments:
message -- error message
errcode -- the error code
exit -- if we do a sys.exit
"""
message = "Error\n\t{message}\n\tExiting with code: {errcode}\n".format(
message=message, errcode=errcode)
print
print message
print
sys.exit(errcode)
def loggify(module, func, prefix=""):
"""
I'm tired of rewriting this logging code in every single function, so I
@ -350,7 +368,7 @@ def link_create(path_src, path_dst, debug=False):
else:
msg_error = "something exists at dst - '%s' " \
"- and it's not a link\n kicking out".format(path_dst)
import sys
sys.exit(msg_error)
if debug:
@ -371,7 +389,6 @@ def prompt_continue(message="Do you want to continue? Y/n", default="Y"):
"""
from fabric.operations import prompt
import sys
prompt_val = prompt(message)

View file

@ -1,4 +1,4 @@
db:
{{ docker_service_name }}:
image: {{ docker_database_image }}
ports: