From 89643d34972a2f263c556ffd5a2b5dcc867f3377 Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Mon, 19 Sep 2016 15:23:13 +0300 Subject: [PATCH 1/8] updated paths to meta/project modified: deploy_meta.py modified: test.py --- bin/deploy_meta.py | 2 +- bin/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/deploy_meta.py b/bin/deploy_meta.py index d6802ee..f832b4b 100644 --- a/bin/deploy_meta.py +++ b/bin/deploy_meta.py @@ -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 diff --git a/bin/test.py b/bin/test.py index a118caa..efb3043 100644 --- a/bin/test.py +++ b/bin/test.py @@ -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() From 595f1ba09dc1d8de5aca56fde7173fe3fc2d8406 Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Tue, 20 Sep 2016 18:41:18 +0300 Subject: [PATCH 2/8] changed name of commandline method modified: modules/django.py --- modules/django.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/django.py b/modules/django.py index 6e37104..1bcc34c 100644 --- a/modules/django.py +++ b/modules/django.py @@ -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 """ From 7653bc692ac580980c16588d84f11127d1096db2 Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Wed, 21 Sep 2016 01:18:02 +0300 Subject: [PATCH 3/8] added service name to top of jinja file when I saw I was getting recraete conflicts Changes to be committed: modified: share/templates/conf/docker/files/database.jinja2 --- share/templates/conf/docker/files/database.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/templates/conf/docker/files/database.jinja2 b/share/templates/conf/docker/files/database.jinja2 index 3a70008..0f9293c 100644 --- a/share/templates/conf/docker/files/database.jinja2 +++ b/share/templates/conf/docker/files/database.jinja2 @@ -1,4 +1,4 @@ -db: +{{ docker_service_name }}: image: {{ docker_database_image }} ports: From bc289e78ea015209528421c9286349593e44a20b Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Wed, 21 Sep 2016 01:44:43 +0300 Subject: [PATCH 4/8] fixed nginx port error for default dev value Changes to be committed: modified: bin/deploy_meta.py --- bin/deploy_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/deploy_meta.py b/bin/deploy_meta.py index f832b4b..4f8451e 100644 --- a/bin/deploy_meta.py +++ b/bin/deploy_meta.py @@ -229,7 +229,7 @@ class DeployMeta(QtGui.QMainWindow): 'title': 'Nginx Port', 'location': 'nginx.port', 'default': { - 'development': "8050", + 'development': "8080", 'staging': "80", 'production': "80", }, From 408a36d5a5fa762b2a2df657266bdaab0c5b9a71 Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Wed, 21 Sep 2016 15:23:28 +0300 Subject: [PATCH 5/8] created new method printerr modified: modules/utils.py --- modules/utils.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/utils.py b/modules/utils.py index a27eb0c..d34d51c 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -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) From f411c576cf2e8382e7ecde58501c65c89ced6a3a Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Wed, 21 Sep 2016 15:24:01 +0300 Subject: [PATCH 6/8] changed virtualenv.requirments variable to a dict that holds local, remote, filename and full ppath filepath for each requirements file modified: modules/initialize.py --- modules/initialize.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/initialize.py b/modules/initialize.py index a332b51..7dbd6dd 100644 --- a/modules/initialize.py +++ b/modules/initialize.py @@ -488,10 +488,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" From e4f80bf0ae45d8428aefdb334ba1c4aca1eede7f Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Wed, 21 Sep 2016 15:24:49 +0300 Subject: [PATCH 7/8] addying copy method to copy over pip requirements files from one branch to another modified: modules/pip.py --- modules/pip.py | 108 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 13 deletions(-) diff --git a/modules/pip.py b/modules/pip.py index 0aaa1b7..057302b 100644 --- a/modules/pip.py +++ b/modules/pip.py @@ -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=False): + """ + True - update package list and freeze output + """ configuration = env.config msg_help = """ @@ -111,7 +116,6 @@ def freeze(param=False): """ from utils import booleanize, handle_help - import sys if handle_help(param, msg_help, 'help'): sys.exit() @@ -119,16 +123,94 @@ def freeze(param=False): 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 copy(branch): + """ + copy requirements from the specified branch to the current 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 + """ + + 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 configuration.project.branch == 'development': + + printerr( + "This method copies to current branch which is you set to " + "development. That is not allowed for sanity reasons.", + 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) + + print "current: %s" % configuration.virtualenv.requirements.filepath + + from initialize import get_config + + branch_config = get_config(branch) + + print "current filepath: %s" % \ + configuration.virtualenv.requirements.filepath + print "current filename: %s" % \ + configuration.virtualenv.requirements.filename + + print + + print "branch filepath: %s" % \ + branch_config.virtualenv.requirements.filepath + print "branch filename: %s" % \ + branch_config.virtualenv.requirements.filename + + 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 : %s" % current_local_path + print "branch_local : %s" % branch_local_path + + print + print + print + + message = "Copying file from branch {branch_src} to " \ + "branch {branch_dst}. Continue? Y/n ".format( + branch_src=branch, branch_dst=configuration.project.branch) + + from utils import prompt_continue + prompt_continue(message=message) From 8a3a66a9fd3f05134b3388e0989d388519dfae0e Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Wed, 21 Sep 2016 15:44:46 +0300 Subject: [PATCH 8/8] created copyto method modified: modules/pip.py --- modules/pip.py | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/modules/pip.py b/modules/pip.py index 057302b..407ca8b 100644 --- a/modules/pip.py +++ b/modules/pip.py @@ -141,13 +141,16 @@ def freeze(param=False): @task -def copy(branch): +def copyto(branch): """ - copy requirements from the specified branch to the current 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 @@ -161,11 +164,10 @@ def copy(branch): "values.".format(branch=branch, branchlist=branch_list), ERROR_BAD_BRANCH_PARAM) - elif configuration.project.branch == 'development': + elif branch == 'development': printerr( - "This method copies to current branch which is you set to " - "development. That is not allowed for sanity reasons.", + "This method does not allow copying to development branch", ERROR_BAD_BRANCH_PARAM) elif configuration.project.branch == branch: @@ -175,24 +177,10 @@ def copy(branch): "This will simply copy over \n\tthe requirements file for " "this branch with itself", ERROR_BAD_BRANCH_PARAM) - print "current: %s" % configuration.virtualenv.requirements.filepath - from initialize import get_config branch_config = get_config(branch) - print "current filepath: %s" % \ - configuration.virtualenv.requirements.filepath - print "current filename: %s" % \ - configuration.virtualenv.requirements.filename - - print - - print "branch filepath: %s" % \ - branch_config.virtualenv.requirements.filepath - print "branch filename: %s" % \ - branch_config.virtualenv.requirements.filename - current_local_path = os.path.join( configuration.virtualenv.requirements.local, configuration.virtualenv.requirements.filename) @@ -201,16 +189,22 @@ def copy(branch): configuration.virtualenv.requirements.local, branch_config.virtualenv.requirements.filename) - print "current_local : %s" % current_local_path - print "branch_local : %s" % branch_local_path + print "current_local_path: %s" % current_local_path + print "branch_local_path: %s" % branch_local_path - print - print - print - - message = "Copying file from branch {branch_src} to " \ - "branch {branch_dst}. Continue? Y/n ".format( - branch_src=branch, branch_dst=configuration.project.branch) + 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)