addying copy method to copy over pip requirements files from one branch to another
modified: modules/pip.py
This commit is contained in:
parent
f411c576cf
commit
e4f80bf0ae
1 changed files with 95 additions and 13 deletions
108
modules/pip.py
108
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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue