0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-19 09:51:19 +02:00
howdy/cli/clear.py

34 lines
898 B
Python
Raw Normal View History

2018-02-13 23:22:13 +01:00
# Clear all models by deleting the whole file
# Import required modules
2018-02-13 22:03:03 +01:00
import os
import sys
# Get the full path to this file
path = os.path.dirname(os.path.abspath(__file__))
# Get the passed user
user = sys.argv[1]
2018-02-13 23:22:13 +01:00
# Check if the models folder is there
2018-02-13 22:03:03 +01:00
if not os.path.exists(path + "/../models"):
print("No models created yet, can't clear them if they don't exist")
sys.exit()
2018-02-13 23:22:13 +01:00
# Check if the user has a models file to delete
2018-02-13 22:03:03 +01:00
if not os.path.isfile(path + "/../models/" + user + ".dat"):
print(user + " has no models or they have been cleared already")
sys.exit()
2018-02-13 23:22:13 +01:00
# Double check with the user
2018-02-13 22:03:03 +01:00
print("This will clear all models for " + user)
ans = input("Do you want to continue [y/N]: ")
2018-02-13 23:22:13 +01:00
# Abort if they don't answer y or Y
2018-02-13 22:03:03 +01:00
if (ans.lower() != "y"):
print('\nInerpeting as a "NO"')
sys.exit()
2018-02-13 23:22:13 +01:00
# Delete otherwise
2018-02-13 22:03:03 +01:00
os.remove(path + "/../models/" + user + ".dat")
print("\nModels cleared")