Source code for menusys.menusys
#!/usr/bin/env python3
"""
##########################################################
# Script Name: menusys.py #
# Script Type: Python #
# Updated By: Benjamin P. Trachtenberg #
# Date Written 1/11/2015 #
# #
# Description: #
# Menu system tools #
# #
##########################################################
"""
import logging
import os as __os
import sys as __sys
import platform as __platform
import textwrap as __textwrap
LOGGER = logging.getLogger(__name__)
yes_no_dict = {
1: {"MENU": "Yes"},
2: {"MENU": "No"}}
prim_sec_dict = {
1: {"MENU": "Primary"},
2: {"MENU": "Secondary"}}
[docs]def word_wrap_string_and_print(string_to_wrap):
"""
Function to word wrap a string depending on the console
and print it
:type string_to_wrap: String
:param string_to_wrap: The string you want to wrap
:rtype: None
:return: None but it does call the print function
"""
try:
term_width, term_height = __os.get_terminal_size()
except OSError:
LOGGER.critical('Function word_wrap_string_and_print OSError')
term_width = 80
print(__textwrap.fill(string_to_wrap, term_width - 10))
[docs]def word_wrap_string(string_to_wrap):
"""
Function to word wrap a string depending on the console
:type string_to_wrap: String
:param string_to_wrap: The string you want to wrap
:rtype: String
:return: A word wrapped string
"""
try:
term_width, term_height = __os.get_terminal_size()
except OSError:
LOGGER.critical('Function word_wrap_string OSError')
term_width = 80
return __textwrap.fill(string_to_wrap, term_width - 10)
[docs]def chunk_up_string(string_to_chunk, size_of_chunk=100):
"""
Function to chunk up a string, and make a list of chunks
:type string_to_chunk: String
:param string_to_chunk: The string you want to chunk up
:type size_of_chunk: Integer
:param size_of_chunk: The size of the chunks in characters
:rtype: List
:return: A list containing the chunks.
"""
temp_list = list()
for chunk in range(0, len(string_to_chunk), size_of_chunk):
temp_list.append(string_to_chunk[chunk:chunk + size_of_chunk])
return temp_list
[docs]def clear_screen():
"""
Function to do a clear screen in Linux or Windows
:rtype: None
:return: None it clears the screen
"""
if __platform.system() == "Windows":
__os.system("cls")
elif __platform.system() == "Linux":
__os.system("clear")
else:
print("Your OS doesn't seem to be supported!")
if __name__ == "__main__":
help(__name__)