initial commit of the Python utility menu
This commit is contained in:
61
template.py
Normal file
61
template.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# template.py
|
||||
|
||||
# used for the examples. these imports can be removed later
|
||||
import os
|
||||
import time
|
||||
|
||||
class TEMPLATE:
|
||||
def __init__(self, initial_temp_c=25.0):
|
||||
# add self.[parameters] here and update method details
|
||||
self.title = "Template Utility"
|
||||
self.usage = """This template can be used to define the CLASS
|
||||
that menu.py will use to generate the utility UI"""
|
||||
|
||||
self.methods = [
|
||||
{
|
||||
"name": "os_info",
|
||||
"title": "Print OS information",
|
||||
"description": "Print basic information from the OS"
|
||||
},
|
||||
{
|
||||
"name": "add_one",
|
||||
"title": "Number incrementer with error checking",
|
||||
"description": "Add 1 to a number"
|
||||
},
|
||||
{
|
||||
"name": "divide_by_zero",
|
||||
"title": "Divide anything by 0",
|
||||
"description": "Returns the input divded by 0"
|
||||
}
|
||||
]
|
||||
|
||||
def os_info(self, unused_input=""):
|
||||
"""Print OS information"""
|
||||
return [
|
||||
["OS:", "Environment Variables:", "Local Time"], # Header row
|
||||
[f"{os.name}", f"{os.getenv('PATH')}", f"{time.localtime()}"]
|
||||
]
|
||||
|
||||
def add_one(self, input):
|
||||
"""Number incrementer with error checking!"""
|
||||
try:
|
||||
input_plus_one = float(input) + 1
|
||||
except:
|
||||
input_plus_one = "[red][bold]NAN[/bold][/red]"
|
||||
return [
|
||||
[f"{input} + 1"], # Header row
|
||||
[f"{input_plus_one}"]
|
||||
]
|
||||
|
||||
def divide_by_zero(self, input):
|
||||
"""Divide anything by 0"""
|
||||
return [
|
||||
[f"{input} / 0"], # Header row
|
||||
["more than 255"]
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
obj = TEMPLATE()
|
||||
# when not using menu.py, direct CLI calls can be handled here
|
||||
obj.os_info()
|
||||
|
||||
Reference in New Issue
Block a user