From 9de38014be07d8eac28a45de021ce60288a77ea9 Mon Sep 17 00:00:00 2001 From: Kevin Puertas Ruiz Date: Thu, 31 Oct 2019 11:35:16 +0100 Subject: [PATCH] Changes to doc and to API, a bit more stable --- api.py | 21 +++++++++------ client/client.ps1 | 18 +++++++++++-- client/control.pyw | 36 ++++++++++++++++--------- client/translation.py | 6 ++++- doc/example_cooks/install_paintnet.yaml | 10 +++++++ doc/howto_writecook.md | 3 +++ 6 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 doc/example_cooks/install_paintnet.yaml diff --git a/api.py b/api.py index a33b95d..fa306b1 100644 --- a/api.py +++ b/api.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -BUILD = 20 +BUILD = 21 API_VER = 1 ##It can be run directly with "waitress-serve --port=3333 api:api" import falcon @@ -91,22 +91,27 @@ class getGroups(object): #Get local groups of a Computer else: data = sql.select("SELECT * FROM GROUPS WHERE ID_G IN (SELECT ID_G FROM COMPUTER_GROUP WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC") response.media = data - + +## +# getComputers: List all computers with data +# /get/computers? +# @param ComputerID/ComputerName -> To see all data only for one computer +## class getComputers(object): def on_get(self,request, response): logit(request) ComputerID=None for key, value in request.params.items(): if key == "ComputerName": - ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"'")[0]['ID_C']) + ComputerID = str(sql.select("SELECT ID_C FROM COMPUTERS WHERE Name='"+value+"' LIMIT 1")[0]['ID_C']) if key == "ComputerID": ComputerID = value - if ComputerID is None: - data = sql.select("SELECT * FROM COMPUTERS ORDER BY Name ASC") + if ComputerID is not None: # One computer + data = sql.select("SELECT * FROM COMPUTERS WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC LIMIT 1") response.media = data - else: - data = sql.select("SELECT * FROM COMPUTERS WHERE ID_C = '"+ComputerID+"') ORDER BY Name ASC") + else: # All computers + data = sql.select("SELECT * FROM COMPUTERS ORDER BY Name ASC") response.media = data @@ -794,7 +799,7 @@ api.add_route('/del/groupscook', delGroupsCook()) #Delete all groups of a cook api.add_route('/del/cleancook', delCleanCook()) #Delete status of a cook for all computers (Restart cook). No delete groups api.add_route('/get/computerexists', getComputerExists()) #Returns 0 or 1 (name status) -api.add_route('/get/computers', getComputers()) #Get list of computer +api.add_route('/get/computers', getComputers()) #Get list of computer and all data in array api.add_route('/get/cookall', getCookAll()) #Get all cooks implemented in one group at least api.add_route('/get/cookgrp', getCookGrp()) # See cooks that have a determinated group api.add_route('/get/cookpend', getCookPend()) #Get cooks pending to implement to a computer diff --git a/client/client.ps1 b/client/client.ps1 index 45d10d0..4431bbb 100644 --- a/client/client.ps1 +++ b/client/client.ps1 @@ -1,10 +1,10 @@ -# Build 8 +# Build 9 param([Int32]$startup=0) Write-Host $startup $root = $PSCommandPath | Split-Path -Parent $server = (Get-Content "$root\configpcm.ini" | select -Skip 1 | ConvertFrom-StringData).server $resources = (Get-Content "$root\configpcm.ini" | select -Skip 1 | ConvertFrom-StringData).resources - +$64bit = [Environment]::Is64BitOperatingSystem $computerName = [System.Net.Dns]::GetHostName() $UUID=(get-wmiobject Win32_ComputerSystemProduct).UUID @@ -51,6 +51,14 @@ foreach ($CookName in $cooks){ Write-Host "Se salta ya que no esta arrancando/apagandose el equipo..." continue # Go for next } + if ($cook.only64bit -eq 1 -and $64bit -eq $false) { # If script is only for 64 bit and system is 32 bit.. + Write-Host "Se salta ya que es esta receta es solo para 64 bits..." + continue # Go for next + } + if ($cook.only32bit -eq 1 -and $64bit -eq $true) { # If script is only for 32 bit and system is 64 bit.. + Write-Host "Se salta ya que es esta receta es solo para 32 bits..." + continue # Go for next + } $err = 0 $exit = 0 $inif = $false @@ -182,6 +190,12 @@ foreach ($CookName in $cooks){ Invoke-Expression $param #Executes powershell command $if=$? # True -> Exists ; False -> Not exists } + "IF64BIT" { # If 64 bit computer + $if = $64bit # Its true if 64 bit computer + } + "IF32BIT" { # If 32 bit computer + $if = !$64bit # Its true if 32 bit computer, flipped boolean + } "ELSE" { # Turn bool $if $if = !$if } diff --git a/client/control.pyw b/client/control.pyw index de57c86..de51d92 100644 --- a/client/control.pyw +++ b/client/control.pyw @@ -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') diff --git a/client/translation.py b/client/translation.py index 632ce9d..d1e4317 100644 --- a/client/translation.py +++ b/client/translation.py @@ -38,7 +38,9 @@ def T_es(textid): 'Select a computer': 'Selecciona un equipo', 'Computer status': 'Estado de un equipo', 'Add computer to group':'Añadir equipo a un grupo', + 'Add cook to a group':'Añadir receta a un grupo', 'Remove computer of a group':'Quitar equipo de un grupo', + 'Remove cook from a group':'Quitar receta de un grupo', 'Name of the cook':'Nombre de la receta', 'Select a group': 'Seleccione un grupo', 'Cooks of computer': 'Recetas del equipo', @@ -63,7 +65,9 @@ def T_es(textid): 'Enter password to start': 'Introduzca la contraseña para empezar', 'Clean cook status': 'Borrar estado de una receta', 'With errors': 'Con errores', - 'Error talking with API': 'Error en la comunicación con la API' + 'Error talking with API': 'Error en la comunicación con la API', + 'Cook details':'Detalles de una receta', + 'Cook groups':'Grupos de una receta' } return dict[textid] diff --git a/doc/example_cooks/install_paintnet.yaml b/doc/example_cooks/install_paintnet.yaml new file mode 100644 index 0000000..01755ed --- /dev/null +++ b/doc/example_cooks/install_paintnet.yaml @@ -0,0 +1,10 @@ +name: Install Paint.Net depending of Platform +revision: 1 +steps: + - IF64BIT| + - REPOTOLOCAL|PaintDotNetMsi/PaintDotNet_424_x64.msi + - INSTALLMSI|PaintDotNet_424_x64.msi + - ELSE|32 Bit + - REPOTOLOCAL|PaintDotNetMsi/PaintDotNet_424_x86.msi + - INSTALLMSI|PaintDotNet_424_x86.msi + - ENDIF| \ No newline at end of file diff --git a/doc/howto_writecook.md b/doc/howto_writecook.md index 3a67f85..2fdb0db 100644 --- a/doc/howto_writecook.md +++ b/doc/howto_writecook.md @@ -12,6 +12,7 @@ If the cook has to run everytime client is called (And not only one time per new If the cook has to run when no user is logued in, add: "atstartup: 1" Be aware that for be able to use this, in task scheduler (Or your favourite method) you have to run client.ps1 with argument "-startup 1" when no users are logued +"only64bit: 1"/"only32bit: 1" only for 64 or 32 bit systems (Maybe for some updates can be used) And then, steps. First a "steps:" line, and then line by line the steps of the cook "steps: @@ -49,6 +50,8 @@ Inside a cook, you can use IF/ELSE/ENDIF scheme. - IFSOFTWAREVER: Runs the if, if a program is installed and has X version. (Run with two param: "Name;Version") - IFPATHEXISTS: Runs if file exists - IFPWCMD: If powershell command returns $true (Executed succesfully), if is run +- IF64BIT: If you are in a 64 Bit operating system +- IF32BIT: If you are in a 32 Bit operating system - ELSE: Else.. - ENDIF