Source code for helper_functions

#!/usr/bin/env python

import os
import datetime
import subprocess

[docs]def cls(): """cls() will clear the screen. Works in linux or windows""" os.system('cls' if os.name=='nt' else 'clear')
[docs]def underline(text): """Underlines text (with equals signs). :param text: The text to be underlined :type text: str :return: Single string made up of the supplied text, a carriage return and the appropriate number of equals signs. :rtype: str""" __underline = "" __counter = 0 while __counter < len(text): __underline = __underline + "=" __counter += 1 text = text + "\n" + __underline return text
[docs]def datetag(): x = datetime.datetime.now() y = str(x.strftime("%Y")) m = str(x.strftime("%m")) d = str(x.strftime("%d")) tag = y + m + d return tag
[docs]def mysql_backup(sdb, shost, username, password): tag = datetag() output_file = "../../34-MySQL_Databases/00-SQL_backups/{}-backup_{}.sql".format(sdb, tag) try: subprocess.check_call( "mysqldump -u %s -p%s -h %s -e --opt --max_allowed_packet=512M -c %s > %s" % (username, password, shost, sdb, output_file), shell=True) except subprocess.CalledProcessError as e: print("Error: mysqldump ended with status %s, check DB credentials" % e.returncode) exit(1)
[docs]def mainloop(): """Just a test routine that will present the user with a list of the days of the week for selection IF the module is run in its own right rather than being called from another module.""" cls() example_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Quit"] state = "Confused" while state != "Quit": state = menu(example_list) print("\nYou chose " + state + "\n")
if __name__ == "__main__": mainloop()