Ejemplo n.º 1
0
    def update_waiting(self):
        """
        Update function, runs if state is WAITING.

        Log warning if function runs (logger will raise exception).
        """
        logger.log_warning(f"node 'warning' raised exception '{self.desc_value}'")
        self.state = ACTIVE
Ejemplo n.º 2
0
def add_module(module_file):
    if not os.path.exists(module_file):
        logger.log_warning(f"module \"{module_file}\" not found")
    else:
        spec = importlib.util.spec_from_file_location(".".join(module_file.split(".py")[0].split("/")), module_file)
        loaded_module = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(loaded_module)
        m = inspect.getmembers(loaded_module, inspect.isclass)
        for node_class_name, node_class in m:
            if base.Node in node_class.__bases__:
                for alias in node_class.aliases:
                    node_aliases[alias] = node_class
Ejemplo n.º 3
0
    def __new__(cls, data):
        """
        Function runs before the constructor and selects suitable class.
        If node is function (function input or output) method
        will run special nodes class constructor.

        :param dict data: node information
        """
        node_name = data["node_name"]
        if str(node_name).startswith("function"):
            return func.NodeFunction(data)

        if node_name in loader.node_aliases:
            return loader.node_aliases[node_name](data)

        logger.log_warning(f"no function node found with name '{node_name}'")
        return base.Node(data)
Ejemplo n.º 4
0
    def __init__(self, data):
        """
        Wire constructor. Attribute takes dictionary with
        several descriptive parameters:
            source - identifier of the first connected object in scheme;
            target - identifier of the second connected object in scheme;
            exitX/exitY - connection (exit) point in source object;
            entryX/entryY - connection (entry) point in target object;
        It checks validity of connected objects and
        calculates entry and exit connector indexes

        :param dict data: information about wire
        """
        self.wires.append(self)
        self.raw_data = data

        self.source = Node.nodes.get(data["source"], None)
        self.target = Node.nodes.get(data["target"], None)

        if self.source is None and self.target is None:
            logger.log_warning("no source and target nodes found")
        elif self.source is None:
            logger.log_error(
                f"no source node found for wire with target '{self.target.name}/{self.target.id}'"
            )
        elif self.target is None:
            logger.log_error(
                f"no target node found for wire with source '{self.source.name}/{self.source.id}'"
            )

        self.exit = data["exitX"], data["exitY"]
        self.entry = data["entryX"], data["entryY"]

        if self.exit[0] == self.entry[0]:
            logger.log_error(
                f"wrong wire connection from node '{self.source.name}/{self.source.id}' "
                f"to node '{self.target.name}/{self.target.id}'")

        if self.exit[0] == 0:
            self.exit, self.entry = self.entry, self.exit
            self.target, self.source = self.source, self.target

        self.entry_connector = self.target.input_connectors.index(
            self.entry[1])
        self.exit_connector = self.source.output_connectors.index(self.exit[1])
Ejemplo n.º 5
0
import json
import os
import inspect
import importlib.util
from scripts.utils import logger
from scripts.nodes import base
from scripts.config import config

node_aliases = {}
module_files = []
module_folders = []
try:
    module_files = json.loads(config.get("Sync Modules", "files"))
except json.decoder.JSONDecodeError as e:
    logger.log_warning("wrong 'files' setting syntax in 'settings.ini'")
try:
    module_folders = json.loads(config.get("Sync Modules", "folders"))
except json.decoder.JSONDecodeError as e:
    logger.log_warning("wrong 'folders' setting syntax in 'settings.ini'")


def add_module(module_file):
    if not os.path.exists(module_file):
        logger.log_warning(f"module \"{module_file}\" not found")
    else:
        spec = importlib.util.spec_from_file_location(".".join(module_file.split(".py")[0].split("/")), module_file)
        loaded_module = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(loaded_module)
        m = inspect.getmembers(loaded_module, inspect.isclass)
        for node_class_name, node_class in m:
            if base.Node in node_class.__bases__: