fixed the startapp and manage so that startapp does not create a directory (leads to an error) and instead added arg to manage to specify working directory where the manage command would be run in

This commit is contained in:
Ronny Abraham 2018-11-09 11:27:28 +02:00
parent e270402ac9
commit 2dffeaa1b9

View file

@ -37,12 +37,20 @@ def test(args=None):
@task @task
def commandline(args=""): def commandline(args="", workingdir=None):
""" """
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
""" """
configuration = env.config configuration = env.config
if workingdir:
commandline = "{djangoroot}/manage.py {args} " \
"--pythonpath='{djangoroot}' " \
"--settings={djangosettings}".format(
djangoroot=configuration.paths.django.root,
args=args,
djangosettings=configuration.imports.settings,)
else:
commandline = "{djangoroot}/manage.py {args} --pythonpath='{djangoroot}'" \ commandline = "{djangoroot}/manage.py {args} --pythonpath='{djangoroot}'" \
" --settings={djangosettings}".format( " --settings={djangosettings}".format(
djangoroot=configuration.paths.django.root, djangoroot=configuration.paths.django.root,
@ -53,13 +61,32 @@ def commandline(args=""):
@task @task
def manage(args=""): def manage(args="", workingdir=None):
configuration = env.config configuration = env.config
# changes the working directory to the djangoroot # changes the working directory to the djangoroot
from fabric.context_managers import cd from fabric.context_managers import cd
with virtualenv(): with virtualenv():
if workingdir:
with cd(workingdir):
fabcommand = "{djangoroot}/manage.py {args} " \
"--pythonpath='{djangoroot}' " \
"--settings={djangosettings}".format(
djangoroot=configuration.paths.django.root,
args=args,
djangosettings=configuration.imports.settings,
)
if env.debug:
print("fabcommand: %s" % fabcommand)
print("workingdir: %s" % workingdir)
else:
output = fabric_ops.run(
fabcommand,
# MAKE SURE THIS IS ALWAYS HERE!
shell='/bin/bash')
with cd(configuration.paths.django.root): with cd(configuration.paths.django.root):
output = fabric_ops.run( output = fabric_ops.run(
"{djangoroot}/manage.py {args} --pythonpath='{djangoroot}' " "{djangoroot}/manage.py {args} --pythonpath='{djangoroot}' "
@ -151,18 +178,11 @@ def startapp(appname='help'):
if handle_help(appname, msg_help, 'help'): if handle_help(appname, msg_help, 'help'):
sys.exit() sys.exit()
destination = os.path.join(configuration.paths.django.apps, appname) command = "startapp {appname}".format(
appname=appname)
cmd_mkdir = "mkdir {destination}".format( manage(command, workingdir=configuration.paths.django.apps)
destination=destination)
command = "startapp {appname} {destination}".format(
appname=appname,
destination=destination)
fabric_ops.run(cmd_mkdir)
manage(command)
# with lcd(configuration.paths.django.apps): # with lcd(configuration.paths.django.apps):
# manage(command) # manage(command)