playbook working, tidying up task order

This commit is contained in:
2025-11-02 23:33:13 -08:00
parent 378b740d93
commit c6d51f2a49
14 changed files with 220 additions and 375 deletions

View File

@ -24,36 +24,34 @@ def init_db():
# this code deletes the db file if 0 bytes
if os.path.exists(db_path) and os.path.getsize(db_path) == 0:
try:
os.remove(db_path)
print("Database is 0 bytes, deleting.")
os.remove(db_path)
except Exception as e:
print(f"error during file deletion - 405: {e}")
return jsonify({'error during file deletion': e}), 405
try:
result = bool(query_db(db_check))
print(result)
# Check if any tables were found
if result:
print(result)
print("drive_records exists - 205")
#return jsonify({'drive_records exists - 205': result}), 205
else:
print("drive_records does not exist, creating")
try:
result_init = query_db(create_table_command)
print("Database created - 201")
#return jsonify({'Database created': True, 'Result': result_init}), 201
print(result_init)
print("Database created - 201")
except sqlite3.Error as e:
print(f"error during table initialization: {e}")
return jsonify({'error during table initialization - 401': e}), 401
#return len(result) > 0
return jsonify({'error during table initialization - 401': e}), 401
except sqlite3.Error as e:
print(f"error during table check: {e}")
return jsonify({'error during table check - 400': e}), 400
# sqlite query function
# sqlite query function with lots of protection
def query_db(sql_query):
try:
# Establish a connection to the SQLite database using a context manager
with sqlite3.connect(db_path) as conn:
cursor = conn.cursor()
print("Executing SQL query:", sql_query)
@ -61,15 +59,8 @@ def query_db(sql_query):
rows = cursor.fetchall()
return rows
except sqlite3.Error as e:
# Handle any potential errors that might occur during database operations
print("An error occurred:", e)
return []
#conn = sqlite3.connect(db_path)
#cursor = conn.cursor()
#cursor.execute(sql_query)
#rows = cursor.fetchall()
#conn.close()
#return rows
# Function to return all drive records in database
def get_all_drive_records():
@ -149,6 +140,6 @@ def test():
if __name__ == '__main__':
result=init_db()
print(result)
app.run(debug=True, host='0.0.0.0', port=5000)
app.run(debug=True, host='172.17.0.1', port=5000)