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:
ronny abraham 2023-07-20 13:10:28 +03:00
parent fe2090d8e9
commit 66c85782e8
2 changed files with 56 additions and 7 deletions

View file

@ -15,6 +15,7 @@ try:
as utils_upload_template
from customfabric.modules.utils import loggify, print_console, booleanize
from customfabric.modules.utils import printerr
except ImportError:
raise
@ -33,6 +34,9 @@ NOTE = """
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):
configuration = env.config
@ -145,19 +149,51 @@ def execute_sql(script_name, add_dbname=True, is_admin=False):
@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')
generate_sql('re_init')
generate_sql('drop_db')
generate_sql('drop_all')
options = ['init', 're_init', 'drop_db', 'drop_all']
if scriptparam == '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
def clear_scripts():
"""
does nothing, there is no code here yet
"""
print("this does nothing, the code isn't here")

View file

@ -89,7 +89,8 @@ def loggify(module, func, prefix=""):
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
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
: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)
@ -123,6 +132,10 @@ def print_console(string, prepend="\n\n", append="\n\n", sep="-", numsep=44):
print(append)
if exit_program:
import sys
sys.exit(exit_code)
def print_debug(debugstr, module, function):
"""