Changes to doc and to API, a bit more stable

This commit is contained in:
2019-10-31 11:35:16 +01:00
parent ea9f7b6436
commit 9de38014be
6 changed files with 71 additions and 23 deletions

View File

@@ -1,11 +1,12 @@
#!/usr/bin/python3
# Version 0.72
# Version 0.8
import easygui
import configparser
import json
import requests
import subprocess, platform
import hashlib #SHA256
import os
from translation import T
@@ -30,9 +31,11 @@ def sendmenudot(text,title,choices):
else:
return menu
## showchoicesapi, suburl has to have params (NOT inlcuding server part)
def showchoicesapi(text,title,suburl,field='Name'):
def showchoicesapi(text,title,suburl,field=['Name']):
global c_server
global passha256
if isinstance(field,str):
field=[field] # Convert to list
if 'Password=' in suburl:
twopart = ""
elif '?' in suburl:
@@ -42,8 +45,12 @@ def showchoicesapi(text,title,suburl,field='Name'):
try:
jsonobj = json.loads(requests.get(c_server+suburl+twopart).text)
listitems = []
for ite in jsonobj:
listitems.append(ite[field])
for ite in jsonobj: # Run in array from json
to = ""
for i in field: # Converting list of fields to large string for return. Not change API
to = str(to) + str(ite[i]) + "|"
to = to.rstrip('|')
listitems.append(to)
return easygui.choicebox(text,title,listitems)
except:
easygui.msgbox(msg=T('Error talking with API'), title=title, ok_button='OK')
@@ -127,7 +134,7 @@ def mcomputers():
elif menu == '3':
m_addcomputergroup()
elif menu == '4':
showchoicesapi(T('Computers list'),T('Computers list'),"/get/computers")
showchoicesapi(T('Computers list'),T('Computers list'),"/get/computers",['Name','RAM','CPUName','SOVersion'])
elif menu == '5':
computer = showchoicesapi(T('Select a computer'),T('Computer status'),"/get/computers")
showchoicesapi(T('Cooks of computer')+' '+computer,T('Computer status'),"/get/cookpend?ComputerName="+computer+"&SeeAll=1",'CookName')
@@ -165,7 +172,7 @@ def mgroups():
def mcooks():
global c_server
global c_resources
menu = sendmenudot(T('Cooks menu'),T('Select option'),['1.Detalles de una receta','2.'+T('Rename cook'),'3.Añadir receta a un grupo','4.Eliminar receta de un grupo','5.Grupos de una receta','6.'+T('Clean cook status')])
menu = sendmenudot(T('Cooks menu'),T('Select option'),['1.'+T('Cook details'),'2.'+T('Rename cook'),'3.Añadir receta a un grupo','4.Eliminar receta de un grupo','5.'+T('Cook groups'),'6.'+T('Clean cook status')])
if menu == '1':
cook = showchoicesapi("Lista de recetas implementadas en algún grupo. Selecciona una para ver sus datos","Detalles de una receta","/get/cookall",'CookName')
if cook is not None:
@@ -192,15 +199,20 @@ def mcooks():
if newname is not None and easygui.ynbox("Cambiar nombre de la receta '"+cook+"' por '"+newname+"'. ¿Seguro?",T('Rename cook')):
sendsettoapi("/upd/cookname?CookName="+cook+"&CookNewName="+newname,"Receta cambiada de nombre")
elif menu == '3':
cook = easygui.enterbox(T('Name of the cook'),"Añadir receta a un grupo")
group = showchoicesapi("Lista de grupos existentes","Listado de grupos","/get/groups")
if easygui.ynbox("Añadir la receta "+cook+" al grupo '"+group+"'. ¿Seguro?","Añadir receta a un grupo"):
sendsettoapi("/add/cookgrp?CookName="+cook+"&GroupName="+group,"Receta añadida al grupo")
files = os.listdir(os.path.dirname(os.path.realpath(__file__))+'/../cooks')
files_txt = [i for i in files if i.endswith('.yaml')]
cook = easygui.choicebox(T('Name of the cook'),T('Add cook to a group'),sorted(files_txt))
if cook is not None:
cook = cook.replace('.yaml','')
group = showchoicesapi("Lista de grupos existentes",T('Groups list'),"/get/groups")
if group is not None:
if easygui.ynbox("Añadir la receta "+cook+" al grupo '"+group+"'. ¿Seguro?",T('Add cook to a group')):
sendsettoapi("/add/cookgrp?CookName="+cook+"&GroupName="+group,"Receta añadida al grupo")
elif menu == '4':
cook = showchoicesapi("Lista de recetas implementadas en algún grupo. Selecciona una para elegir un grupo de esa receta para borrar. Si la receta no está en ningún grupo, no saldrá.","Eliminar receta de un grupo","/get/cookall",'CookName')
if cook is not None:
group = showchoicesapi("Lista de grupos que tienen esa receta ("+cook+"). Selecciona el grupo a quitar","Eliminar receta de un grupo","/get/grpcook?CookName="+cook,'Name')
if group is not None and easygui.ynbox("Se va a quitar la receta "+cook+" del grupo "+group+". ¿Seguro?","Eliminar receta de un grupo"):
group = showchoicesapi("Lista de grupos que tienen esa receta ("+cook+"). Selecciona el grupo a quitar",T('Remove cook from a group'),"/get/grpcook?CookName="+cook,'Name')
if group is not None and easygui.ynbox("Se va a quitar la receta "+cook+" del grupo "+group+". ¿Seguro?",T('Remove cook from a group')):
sendsettoapi("/del/cookgrp?CookName="+cook+"&GroupName="+group,"Receta quitada del grupo")
elif menu == '5':
cook = showchoicesapi("Lista de recetas implementadas en algún grupo. Selecciona una para ver los grupos de la receta. Si la receta no está en ningún grupo, no saldrá.","Grupos de una receta","/get/cookall",'CookName')