forked from platypush/platypush
[WIP]
This commit is contained in:
parent
d155094729
commit
af21ff13ff
5 changed files with 52 additions and 2 deletions
|
@ -422,6 +422,7 @@ class Config:
|
||||||
|
|
||||||
self.procedures[procedure_name] = {
|
self.procedures[procedure_name] = {
|
||||||
'_async': _async,
|
'_async': _async,
|
||||||
|
'type': 'config',
|
||||||
'actions': component,
|
'actions': component,
|
||||||
'args': args,
|
'args': args,
|
||||||
}
|
}
|
||||||
|
|
7
platypush/entities/_engine/_procedure.py
Normal file
7
platypush/entities/_engine/_procedure.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class ProceduresManager:
|
||||||
|
"""
|
||||||
|
This class is responsible for managing the procedures as native entities.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.procedures = {}
|
38
platypush/entities/procedures.py
Normal file
38
platypush/entities/procedures.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from sqlalchemy import (
|
||||||
|
Column,
|
||||||
|
Enum,
|
||||||
|
ForeignKey,
|
||||||
|
Integer,
|
||||||
|
JSON,
|
||||||
|
String,
|
||||||
|
)
|
||||||
|
|
||||||
|
from platypush.common.db import is_defined
|
||||||
|
|
||||||
|
from . import Entity
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
if not is_defined('procedure'):
|
||||||
|
|
||||||
|
class Procedure(Entity):
|
||||||
|
"""
|
||||||
|
Models a procedure entity.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__tablename__ = 'procedure'
|
||||||
|
|
||||||
|
id = Column(
|
||||||
|
Integer, ForeignKey('entity.id', ondelete='CASCADE'), primary_key=True
|
||||||
|
)
|
||||||
|
name = Column(String, unique=True, nullable=False)
|
||||||
|
args = Column(JSON, nullable=False, default=[])
|
||||||
|
type = Column(Enum('python', 'config', name='procedure_type'), nullable=False)
|
||||||
|
|
||||||
|
__table_args__ = {'keep_existing': True}
|
||||||
|
__mapper_args__ = {
|
||||||
|
'polymorphic_identity': __tablename__,
|
||||||
|
}
|
|
@ -10,9 +10,10 @@ class ProcedureEncoder(json.JSONEncoder):
|
||||||
def default(self, o):
|
def default(self, o):
|
||||||
if callable(o):
|
if callable(o):
|
||||||
return {
|
return {
|
||||||
'type': 'native_function',
|
'type': 'python',
|
||||||
'module': o.__module__,
|
'module': o.__module__,
|
||||||
'source': inspect.getsourcefile(o),
|
'source': getattr(o, "_source", inspect.getsourcefile(o)),
|
||||||
|
'line': getattr(o, "_line", inspect.getsourcelines(o)[1]),
|
||||||
'args': [
|
'args': [
|
||||||
name
|
name
|
||||||
for name, arg in inspect.signature(o).parameters.items()
|
for name, arg in inspect.signature(o).parameters.items()
|
||||||
|
|
|
@ -565,9 +565,12 @@ def procedure(name_or_func: Optional[str] = None, *upper_args, **upper_kwargs):
|
||||||
"""
|
"""
|
||||||
Public decorator to mark a function as a procedure.
|
Public decorator to mark a function as a procedure.
|
||||||
"""
|
"""
|
||||||
|
import inspect
|
||||||
|
|
||||||
f.procedure = True
|
f.procedure = True
|
||||||
f.procedure_name = name
|
f.procedure_name = name
|
||||||
|
f._source = inspect.getsourcefile(f) # pylint: disable=protected-access
|
||||||
|
f._line = inspect.getsourcelines(f)[1] # pylint: disable=protected-access
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def _execute_procedure(*args, **kwargs):
|
def _execute_procedure(*args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue