Cleaner structure
This commit is contained in:
parent
033a021db7
commit
73a1d877a5
9 changed files with 11 additions and 5 deletions
47
utils/utility.py
Normal file
47
utils/utility.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import yaml
|
||||
|
||||
class Utilities:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def read_yaml(self, yaml_file):
|
||||
try:
|
||||
with open(yaml_file, "r") as file:
|
||||
data = yaml.safe_load(file)
|
||||
return data
|
||||
except (FileNotFoundError, PermissionError) as e:
|
||||
print(f"Error loading settings file: {e}")
|
||||
return
|
||||
|
||||
def write_yaml(self, yaml_file, data):
|
||||
try:
|
||||
with open(yaml_file, "w") as file:
|
||||
yaml.dump(data, file)
|
||||
except PermissionError as e:
|
||||
print(f"Error saving setings: {e}")
|
||||
|
||||
def yes_no(self, str):
|
||||
"""Ask user y/n question"""
|
||||
while True:
|
||||
choice = input(f"{str} (y/n): ")
|
||||
if choice == "y":
|
||||
return True
|
||||
elif choice == "n":
|
||||
return False
|
||||
else:
|
||||
print("Not a valid option, try again.")
|
||||
|
||||
def progress_bar(self, current, total, barsize = 50):
|
||||
if current > total:
|
||||
print("\033[91mThis bar has exceeded its limits!\033[0m Maybe the current value needs some restraint?")
|
||||
print(f"{(current - total) * '\033[92mHonk, Honk!\033[0m '}")
|
||||
return
|
||||
progress = int((barsize / total) * current)
|
||||
rest = barsize - progress
|
||||
if rest <= 2: rest = 0
|
||||
# Determine the number of digits in total
|
||||
total_digits = len(str(total))
|
||||
# Format current with leading zeros
|
||||
current_formatted = f"{current:0{total_digits}}"
|
||||
print(f"{current_formatted}|{progress * '-'}>{rest * ' '}|{total}", end="\r")
|
||||
if current == total: print("")
|
Loading…
Add table
Add a link
Reference in a new issue