Fixed bugs, new options for cooks

This commit is contained in:
2019-09-05 08:38:06 +02:00
parent ada3b9a6d2
commit 90683c44b0
7 changed files with 89 additions and 55 deletions

34
api.py
View File

@@ -1,5 +1,5 @@
#!/usr/bin/python3
BUILD = 16
BUILD = 18
API_VER = 1
##It can be run directly with "waitress-serve --port=3333 api:api"
import falcon
@@ -111,7 +111,7 @@ class getComputers(object):
##
# getComputersGrp: Know all computers that have a group
# getComputersGrp: Know all computers that have this group
# /get/computersgrp?
# @param GroupName/GroupID -> Group to see computers
##
@@ -537,6 +537,12 @@ class delGrpComputer(object): #Del computer from a group
response.media = result
##
# delComputer: Delete computer and data of it
# /del/computer?
# @param ComputerName/ComputerID -> Computer ID or Name
# @param Password -> Password validated command
##
class delComputer(object): #Delete computer
def on_get(self, request, response):
logit(request)
@@ -546,8 +552,11 @@ class delComputer(object): #Delete computer
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C'])
if key == "ComputerID":
ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE ID_C='"+value+"'")[0]['ID_C'])
if ComputerID is None:
if key == "Password" and value == retPassword():
Password=value
if Password is None:
response.media = {'TEXT': 'Invalid password','RESULT':'ERROR'}
elif ComputerID is None:
response.media = {'TEXT': 'Error, you need a Name/ComputerID to update data','RESULT':'ERROR'}
elif ComputerID=='':
response.media = {'TEXT': 'Error, this Name/ID is not valid','RESULT':'ERROR'}
@@ -575,7 +584,8 @@ class updComputer(object):
UUID = value
if key == "Password" and value == retPassword():
Password=value
if Password is None:
response.media = {'TEXT': 'Invalid password','RESULT':'ERROR'}
if ComputerID is None and response.media is None:
response.media = {'TEXT': 'Error, you need a ComputerName/ComputerID to update data','RESULT':'ERROR'}
elif response.media is None and ComputerID is not None and UUID is not None:
@@ -609,27 +619,27 @@ class updComputer(object):
class updCookName(object):
def on_get(self, request, response):
logit(request)
CookName, CookNewName= None, None #Initialize
CookName, CookNewName,Password= None, None,None #Initialize
for key, value in request.params.items():
if key == "CookName":
if os.path.isfile('cooks/'+value+'.yaml'):
CookName= value
else:
response.media = {'TEXT': 'Error: Cook not exists in folder','RESULT':'ERROR'}
break
if key == "CookNewName":
if os.path.isfile('cooks/'+value+'.yaml'):
response.media = {'TEXT': 'Error: There is a cook with the new name in folder!','RESULT':'ERROR'}
break
else:
CookNewName= value
if key == "Password" and value == retPassword():
Password=value
if CookName is None or CookNewName is None:
response.media = {'TEXT': 'Error, you need the old and new Cook Name to update data','RESULT':'ERROR'}
elif Password is None: # Validate password
if Password is None:
response.media = {'TEXT': 'Invalid password','RESULT':'ERROR'}
elif response.media is None: #Like else
if response.media is not None:
pass
elif CookName is None or CookNewName is None:
response.media = {'TEXT': 'Error, you need the old and new Cook Name to update data','RESULT':'ERROR'}
else: #Do it.
old_file = os.path.join("cooks", CookName+'.yaml')
new_file = os.path.join("cooks", CookNewName+'.yaml')
os.rename(old_file, new_file)