import os from collections import defaultdict from typing import Any, DefaultDict, Dict, List, Optional, Set from websockets.server import WebSocketServerProtocol as WsClient from arcor2.cached import UpdateableCachedProject, UpdateableCachedScene from arcor2.data import events from arcor2.logging import get_aiologger from arcor2.object_types.abstract import Generic from arcor2_arserver.object_types.data import ObjectTypeDict from arcor2_arserver_data.events.common import ShowMainScreen logger = get_aiologger("ARServer") VERBOSE: bool = False PORT: int = int(os.getenv("ARCOR2_SERVER_PORT", 6789)) SCENE: Optional[UpdateableCachedScene] = None PROJECT: Optional[UpdateableCachedProject] = None MAIN_SCREEN: Optional[ShowMainScreen.Data] = ShowMainScreen.Data( ShowMainScreen.Data.WhatEnum.ScenesList) INTERFACES: Set[WsClient] = set() OBJECT_TYPES: ObjectTypeDict = {} SCENE_OBJECT_INSTANCES: Dict[str, Generic] = {} RUNNING_ACTION: Optional[
import sys import websockets from aiologger.levels import LogLevel from aiorun import run from arcor2_logger import version from arcor2_logger.object_types.logging_mixin import Level, LogMessage, Register from dataclasses_jsonschema import ValidationError from websockets.server import WebSocketServerProtocol as WsClient from arcor2 import env from arcor2.exceptions import Arcor2Exception from arcor2.helpers import port_from_url from arcor2.logging import get_aiologger logger = get_aiologger("Logger") logging_level = Level.from_string(os.getenv("ARCOR2_LOGGER_LEVEL", "info")) # TODO maybe use the same machinery (arcor2/ws_server) for RPCs/Events as in ARServer/Execution? # ...but for now this is much more simpler and just enough async def handle_requests(websocket: WsClient, path: str) -> None: assert not sys.stdout.closed # closed stdout was problem when creating and shutting down logger for each client try: data = await websocket.recv() except websockets.exceptions.ConnectionClosed: return
from websockets.server import WebSocketServerProtocol as WsClient import arcor2_execution import arcor2_execution_data from arcor2 import json, ws_server from arcor2.data import common, compile_json_schemas from arcor2.data import rpc as arcor2_rpc from arcor2.data.events import Event, PackageInfo, PackageState, ProjectException from arcor2.exceptions import Arcor2Exception from arcor2.helpers import port_from_url from arcor2.logging import get_aiologger from arcor2_execution_data import EVENTS, URL, events, rpc from arcor2_execution_data.common import PackageSummary, ProjectMeta from arcor2_execution_data.package import PROJECT_PATH, read_package_meta, write_package_meta logger = get_aiologger("Execution") PROCESS: Union[asyncio.subprocess.Process, None] = None PACKAGE_STATE_EVENT: PackageState = PackageState(PackageState.Data()) # undefined state RUNNING_PACKAGE_ID: Optional[str] = None # in case of man. written scripts, this might not be sent PACKAGE_INFO_EVENT: Optional[PackageInfo] = None TASK = None CLIENTS: Set = set() MAIN_SCRIPT_NAME = "script.py" EVENT_MAPPING = {evt.__name__: evt for evt in EVENTS}
import os from collections import defaultdict from typing import Any, DefaultDict, Dict, List, Optional, Set, Tuple, Union from websockets.server import WebSocketServerProtocol as WsClient from arcor2.data import events from arcor2.logging import get_aiologger from arcor2.object_types.abstract import Generic from arcor2_arserver.lock import Lock from arcor2_arserver.object_types.data import ObjectTypeDict from arcor2_arserver.user import Users from arcor2_arserver_data.events.common import ShowMainScreen logger = get_aiologger("ARServer") # TODO move logger to separate file VERBOSE: bool = False PORT: int = int(os.getenv("ARCOR2_SERVER_PORT", 6789)) MAIN_SCREEN: Optional[ShowMainScreen.Data] = ShowMainScreen.Data(ShowMainScreen.Data.WhatEnum.ScenesList) OBJECT_TYPES: ObjectTypeDict = {} SCENE_OBJECT_INSTANCES: Dict[str, Generic] = {} RUNNING_ACTION: Optional[str] = None # ID of an action that is being executed during project editing RUNNING_ACTION_PARAMS: Optional[List[Any]] = None PACKAGE_STATE = events.PackageState.Data() PACKAGE_INFO: Optional[events.PackageInfo.Data] = None