modified utils.print_console so that it can have an exit option and give an exit code, also modified database.generate so that it can selectively generate one of the scripts if chosen, has better docutils and also prints a help message when asked
This commit is contained in:
parent
fe2090d8e9
commit
66c85782e8
2 changed files with 56 additions and 7 deletions
|
|
@ -15,6 +15,7 @@ try:
|
||||||
as utils_upload_template
|
as utils_upload_template
|
||||||
|
|
||||||
from customfabric.modules.utils import loggify, print_console, booleanize
|
from customfabric.modules.utils import loggify, print_console, booleanize
|
||||||
|
from customfabric.modules.utils import printerr
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise
|
raise
|
||||||
|
|
@ -33,6 +34,9 @@ NOTE = """
|
||||||
you will NOT BE ABLE TO SYNC. SO TURN THE FUCKING THING OFF\n\n\n"""
|
you will NOT BE ABLE TO SYNC. SO TURN THE FUCKING THING OFF\n\n\n"""
|
||||||
|
|
||||||
|
|
||||||
|
DATABASE_ERROR_CODE_BAD_SCRIPT_PARAM = -3
|
||||||
|
|
||||||
|
|
||||||
def generate_sql(script_name):
|
def generate_sql(script_name):
|
||||||
configuration = env.config
|
configuration = env.config
|
||||||
|
|
||||||
|
|
@ -145,19 +149,51 @@ def execute_sql(script_name, add_dbname=True, is_admin=False):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def generate():
|
def generate(scriptparam='all'):
|
||||||
"""
|
"""
|
||||||
helper function to upload all the scripts
|
helper function to generate and upload the scripts
|
||||||
|
|
||||||
|
:parameter scriptparam: the name of the script we want to generate
|
||||||
|
defaults to all, in which case, all scripts are generated
|
||||||
|
:type scriptparam: str
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
generate_sql('init')
|
options = ['init', 're_init', 'drop_db', 'drop_all']
|
||||||
generate_sql('re_init')
|
|
||||||
generate_sql('drop_db')
|
if scriptparam == 'all':
|
||||||
generate_sql('drop_all')
|
for scriptname in options:
|
||||||
|
generate_sql(scriptname)
|
||||||
|
elif scriptparam == 'help':
|
||||||
|
message = "usage: fab database.generate:scriptparam='all'"\
|
||||||
|
" or some value of {options} \n leave the parameter "\
|
||||||
|
"blank to generate all scripts. Exiting.".format(options=options)
|
||||||
|
|
||||||
|
print_console(message, exit_program=True)
|
||||||
|
|
||||||
|
elif scriptparam in options:
|
||||||
|
generate_sql(scriptparam)
|
||||||
|
|
||||||
|
else:
|
||||||
|
msg = "error - script parameters: " \
|
||||||
|
"{scriptparam} is not one of {options}".format(
|
||||||
|
scriptparam=scriptparam, options=options)
|
||||||
|
|
||||||
|
printerr(message=msg,
|
||||||
|
errcode=DATABASE_ERROR_CODE_BAD_SCRIPT_PARAM,
|
||||||
|
exit=True)
|
||||||
|
|
||||||
|
# generate_sql('init')
|
||||||
|
# generate_sql('re_init')
|
||||||
|
# generate_sql('drop_db')
|
||||||
|
# generate_sql('drop_all')
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def clear_scripts():
|
def clear_scripts():
|
||||||
|
"""
|
||||||
|
does nothing, there is no code here yet
|
||||||
|
"""
|
||||||
print("this does nothing, the code isn't here")
|
print("this does nothing, the code isn't here")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,8 @@ def loggify(module, func, prefix=""):
|
||||||
return logging.getLogger(loggername)
|
return logging.getLogger(loggername)
|
||||||
|
|
||||||
|
|
||||||
def print_console(string, prepend="\n\n", append="\n\n", sep="-", numsep=44):
|
def print_console(string, prepend="\n\n", append="\n\n", sep="-", numsep=44,
|
||||||
|
exit_program=False, exit_code=0):
|
||||||
"""
|
"""
|
||||||
helper function to take a string, and format it so it prints to the console
|
helper function to take a string, and format it so it prints to the console
|
||||||
in a way that is pleasing to the eye.
|
in a way that is pleasing to the eye.
|
||||||
|
|
@ -109,6 +110,14 @@ def print_console(string, prepend="\n\n", append="\n\n", sep="-", numsep=44):
|
||||||
|
|
||||||
:parameter numsep: number of times the separator is printed out on a line
|
:parameter numsep: number of times the separator is printed out on a line
|
||||||
:type numsep: int
|
:type numsep: int
|
||||||
|
|
||||||
|
:parameter exit_program: whether to exit the program after printing the
|
||||||
|
message. defaults to False
|
||||||
|
:type exit_program: bool
|
||||||
|
|
||||||
|
:parameter exit_code: what exit code to use if we exit the program after
|
||||||
|
printing the message. defaults to 0
|
||||||
|
:type exit_code: int
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print(prepend)
|
print(prepend)
|
||||||
|
|
@ -123,6 +132,10 @@ def print_console(string, prepend="\n\n", append="\n\n", sep="-", numsep=44):
|
||||||
|
|
||||||
print(append)
|
print(append)
|
||||||
|
|
||||||
|
if exit_program:
|
||||||
|
import sys
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
||||||
|
|
||||||
def print_debug(debugstr, module, function):
|
def print_debug(debugstr, module, function):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue