Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executor Plugin: Improvements and fixes #776

Merged
merged 16 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions executor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Executor(SmartPlugin):
the update functions for the items
"""

PLUGIN_VERSION = '1.1.1'
PLUGIN_VERSION = '1.2.0'

def __init__(self, sh):
"""
Expand Down Expand Up @@ -142,4 +142,3 @@ def init_webinterface(self):
description='')

return True

4 changes: 2 additions & 2 deletions executor/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ plugin:
de: 'Ausführen von Python Statements im Kontext von SmartHomeNG v1.5 und höher'
en: 'Execute Python statements in the context of SmartHomeNG v1.5 and up'
maintainer: bmxp
tester: nobody # Who tests this plugin?
tester: onkelandy
state: ready # change to ready when done with development
keywords: Python eval exec code test
documentation: https://www.smarthomeng.de/user/plugins/executor/user_doc.html
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1425152-support-thread-plugin-executor

version: 1.1.1 # Plugin version
version: 1.2.0 # Plugin version
sh_minversion: 1.9 # minimum shNG version to use this plugin
#sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
py_minversion: 3.8 # minimum Python version to use for this plugin, use f-strings for debug
Expand Down
29 changes: 24 additions & 5 deletions executor/user_doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ executor
Einführung
~~~~~~~~~~

Das executor plugin kann genutzt werden, um **Python Code** (z.B. für **Logiken**) und **eval Ausdrücke** zu testen.
Das executor Plugin kann genutzt werden, um **Python Code** (z.B. für **Logiken**) und **eval Ausdrücke** zu testen.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das mit den eval Ausdrücken kann raus, die sind ja im Admin Interface bereits implementiert.


.. important::

Expand All @@ -35,8 +35,8 @@ Damit wird dem Plugin eine relative Pfadangabe unterhalb *var* angegeben wo Skri
Webinterface
============

Im Webinterface findet sich eine Listbox mit den auf dem Rechner gespeicherten Skripten.
Um das Skript in den Editor zu laden entweder ein Skript in der Liste einfach anklicken und auf *aus Datei laden* klicken oder
Im Webinterface findet sich eine Listbox mit den auf dem Rechner gespeicherten Skripten.
Um das Skript in den Editor zu laden, entweder ein Skript in der Liste einfach anklicken und auf *aus Datei laden* klicken oder
direkt in der Liste einen Doppelklick auf die gewünschte Datei ausführen.

Der Dateiname wird entsprechend der gewählten Datei gesetzt. Mit Klick auf *aktuellen Code speichern* wird der Code im konfigurierten
Expand All @@ -46,7 +46,7 @@ Mit einem Klick auf *Code ausführen!* oder der Kombination Ctrl+Return wird der
Das kann gerade bei Datenbank Abfragen recht lange dauern. Es kann keine Rückmeldung von SmartHomeNG abgefragt werden wie weit der Code derzeit ist.
Das Ergebnis wird unten angezeigt. Solange kein Ergebnis vorliegt, steht im Ergebniskasten **... processing ...**

Mit einem Klick auf Datei löschen wird versucht die unter Dateiname angezeigte Datei ohne Rückfrage zu löschen.
Mit einem Klick auf *Datei löschen* wird versucht, die unter Dateiname angezeigte Datei ohne Rückfrage zu löschen.
Anschliessend wird die Liste der Skripte aktualisiert.

Beispiel Python Code
Expand All @@ -55,7 +55,9 @@ Beispiel Python Code
Sowohl ``logger`` als auch ``print`` funktionieren für die Ausgabe von Ergebnissen.
Die Idee ist, dass Logiken mehr oder weniger 1:1 kopiert und getestet werden können.


Loggertest
----------

.. code-block:: python

Expand All @@ -66,6 +68,7 @@ Loggertest


Datenserien für ein Item ausgeben
---------------------------------

Abfragen von Daten aus dem database plugin für ein spezifisches Item:

Expand Down Expand Up @@ -111,4 +114,20 @@ würde in folgendem Ergebnis münden:
]
}

Damit die Nutzung

Zählen der Datensätze in der Datenbank
--------------------------------------

Das folgende Snippet zeigt alle Datenbank-Items an und zählt die Einträge in der Datenbank. Vorsicht: Dies kann sehr lange dauern, wenn Sie eine große Anzahl von Einträgen mit Datenbankattributen haben.

.. code-block:: python

from lib.item import Items
items = Items.get_instance()
myfiller = " "
allItems = items.return_items()
for myItem in allItems:
if not hasattr(myItem,'db'):
continue
mycount = myItem.db('countall', 0)
print (myItem.property.name + myfiller[0:len(myfiller)-len(myItem.property.name)]+ ' - Anzahl Datensätze :'+str(mycount))
14 changes: 7 additions & 7 deletions executor/webif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import csv
from jinja2 import Environment, FileSystemLoader

import sys
import sys

class PrintCapture:
"""this class overwrites stdout and stderr temporarily to capture output"""
Expand Down Expand Up @@ -197,7 +197,7 @@ def eval_statement(self, eline, path, reload=None):
def exec_code(self, eline, reload=None):
"""
evaluate a whole python block in eline

:return: result of the evaluation
"""
result = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

der stub_logger müsste noch um neuere methoden wie notice etc. erweitert werden...

Expand Down Expand Up @@ -284,7 +284,7 @@ def delete_file(self, filename=''):
@cherrypy.expose
def get_filelist(self):
"""returns all filenames from the defined script path with suffix ``.py``"""

if self.plugin.executor_scripts is not None:
subdir = self.plugin.executor_scripts
self.logger.debug(f"list files in {subdir}")
Expand All @@ -296,7 +296,7 @@ def get_filelist(self):
return files

return ''

@cherrypy.expose
def get_autocomplete(self):
_sh = self.plugin.get_sh()
Expand All @@ -310,11 +310,11 @@ def get_autocomplete(self):
if api is not None:
for function in api:
plugin_list.append("sh."+plugin_config_name + "." + function)


myItems = _sh.return_items()
itemList = []
for item in myItems:
itemList.append("sh."+str(item)+"()")
itemList.append("sh."+str(item.property.path)+"()")
retValue = {'items':itemList,'plugins':plugin_list}
return (json.dumps(retValue))
return (json.dumps(retValue))
Loading