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): class DeployMeta(QtGui.QMainWindow):
PATH_META = "../../../meta/configuration" PATH_META = "../../../meta/project"
PATH_TEMPLATES = "../share/templates/meta" PATH_TEMPLATES = "../share/templates/meta"
path_meta = None path_meta = None
@ -229,7 +229,7 @@ class DeployMeta(QtGui.QMainWindow):
'title': 'Nginx Port', 'title': 'Nginx Port',
'location': 'nginx.port', 'location': 'nginx.port',
'default': { 'default': {
'development': "8050", 'development': "8080",
'staging': "80", 'staging': "80",
'production': "80", 'production': "80",
}, },

View file

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

View file

@ -36,7 +36,7 @@ def test(args=None):
@task @task
def manage_commandline(args=""): def commandline(args=""):
""" """
prints out what you need to run on the command line to invoke manage.py 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( virtualenv_requirements = "{branch}.txt".format(
branch=configuration.project.branch) 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, configuration.paths.project.root,
layout['virtualenv']['requirements'], layout['virtualenv']['requirements'])
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" # determine the virtualenv name, if it is set as "Null"

View file

@ -1,10 +1,15 @@
from fabric.api import env, task from fabric.api import env, task
from fabric.operations import run from fabric.operations import run
import sys
import os
import logging import logging
from utils import virtualenv_source, virtualenv 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 @task
@ -61,7 +66,7 @@ def setup():
level=logging.DEBUG) level=logging.DEBUG)
pipinstall_cmd = "pip install -r {requirements}".format( pipinstall_cmd = "pip install -r {requirements}".format(
requirements=configuration.virtualenv.requirements) requirements=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\")" %
@ -78,15 +83,12 @@ def install(package=None):
""" """
configuration = env.config configuration = env.config
import sys
if not package: if not package:
print_console("you must specify a package to be installed") printerr("You must specify a package to be installed", ERROR_BAD_PARAM)
sys.exit()
if package == "--all": if package == "--all":
pipinstall_cmd = "pip install -r {requirements_file}".format( pipinstall_cmd = "pip install -r {requirements_file}".format(
requirements_file=configuration.virtualenv.requirements) requirements_file=configuration.virtualenv.requirements.filepath)
else: else:
pipinstall_cmd = "pip install {package}".format( pipinstall_cmd = "pip install {package}".format(
package=package) package=package)
@ -101,6 +103,9 @@ def install(package=None):
@task @task
def freeze(param='help'): def freeze(param='help'):
"""
True - update package list and freeze output
"""
configuration = env.config configuration = env.config
msg_help = """ msg_help = """
@ -111,7 +116,6 @@ def freeze(param='help'):
""" """
from utils import booleanize, handle_help from utils import booleanize, handle_help
import sys
if handle_help(param, msg_help, 'help'): if handle_help(param, msg_help, 'help'):
sys.exit() sys.exit()
@ -119,16 +123,88 @@ def freeze(param='help'):
try: try:
param = booleanize(param) param = booleanize(param)
except TypeError: except TypeError:
print "the parameter value you gave, \"%s\" , is not" \ printerr(
" a valid parameter." % param "the parameter value you gave, '{param}' , is not a "
print msg_help "valid parameter\n{msg_help}".format(
sys.exit() param=param, msg_help=msg_help),
ERROR_BAD_PARAM
)
if param: if param:
cmd_pipfreeze = "pip freeze > {requirements}".format( cmd_pipfreeze = "pip freeze > {requirements}".format(
requirements=configuration.virtualenv.requirements) requirements=configuration.virtualenv.requirements.filepath)
else: else:
cmd_pipfreeze = "pip freeze" cmd_pipfreeze = "pip freeze"
with virtualenv(): with virtualenv():
run(cmd_pipfreeze) 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 os
import sys
import errno import errno
import logging import logging
@ -12,10 +13,27 @@ from fabric.operations import run, sudo
def printvar(name, value, exit=False): def printvar(name, value, exit=False):
print "%s : %s" % (name, value) print "%s : %s" % (name, value)
if exit: if exit:
import sys
sys.exit() 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=""): def loggify(module, func, prefix=""):
""" """
I'm tired of rewriting this logging code in every single function, so I 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: else:
msg_error = "something exists at dst - '%s' " \ msg_error = "something exists at dst - '%s' " \
"- and it's not a link\n kicking out".format(path_dst) "- and it's not a link\n kicking out".format(path_dst)
import sys
sys.exit(msg_error) sys.exit(msg_error)
if debug: if debug:
@ -371,7 +389,6 @@ def prompt_continue(message="Do you want to continue? Y/n", default="Y"):
""" """
from fabric.operations import prompt from fabric.operations import prompt
import sys
prompt_val = prompt(message) prompt_val = prompt(message)

View file

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