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

Submodule refactoring #20

Open
wants to merge 2 commits into
base: old_manager
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
118 changes: 118 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

.idea/

docs/.jekyll-cache/

.jekyll-cache
_site

# IDEs
.vscode

# jetbrains files
.idea/

# react stuff
node_modules/

lerna-debug.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.changelog
.npm/
webpack-stats.json
*.DS_Store
react_frontend/static
developer_scripts
**.log
Binary file removed manager/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed manager/comms/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file removed manager/libs/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed manager/manager/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed manager/ram_logging/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
File renamed without changes.
Binary file added src/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
File renamed without changes.
Binary file added src/comms/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added src/comms/__pycache__/new_consumer.cpython-38.pyc
Binary file not shown.
8 changes: 3 additions & 5 deletions manager/comms/consumer.py → src/comms/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import websockets
from websockets.server import WebSocketServerProtocol

from src.manager.comms.consumer_message import ManagerConsumerMessage, ManagerConsumerMessageException
from src.manager.ram_logging.log_manager import LogManager
from .consumer_message import ManagerConsumerMessage, ManagerConsumerMessageException
from ..ram_logging.log_manager import LogManager

logger = LogManager.logger

Expand All @@ -17,9 +17,7 @@ class ManagerConsumer:
"""

def __init__(self, host, port):
from src.manager.manager import Manager


from ..manager.manager import Manager
"""
Initializes a new ManagerConsumer
@param host: host for connections, '0.0.0.0' to bind all interfaces
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions manager/comms/new_consumer.py → src/comms/new_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from websocket_server import WebsocketServer
from datetime import datetime

from src.manager.comms.consumer_message import ManagerConsumerMessageException, ManagerConsumerMessage
from src.manager.ram_logging.log_manager import LogManager
from .consumer_message import ManagerConsumerMessageException, ManagerConsumerMessage
from ..ram_logging.log_manager import LogManager


class Client:
Expand Down Expand Up @@ -42,9 +42,12 @@ def handle_client_disconnect(self, client, server):
if client is None:
return
LogManager.logger.info(f"client disconnected: {client}")

# TODO: remove print
now = datetime.now()
time_string = now.strftime("%H:%M:%S")
print(time_string)
print(f"client disconnected: {client} at {time_string}")

message = ManagerConsumerMessage(**{'id': str(uuid4()), 'command': 'disconnect'})
self.manager_queue.put(message)
self.client = None
Expand Down
File renamed without changes.
Binary file added src/libs/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from src.manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from ...manager.application.robotics_python_application_interface import IRoboticsPythonApplication


class BrainExercise(IRoboticsPythonApplication):
def pause(self):
pass

def resume(self):
pass

def terminate(self):
pass

def load_code(self, code: str):
pass

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import threading
import websocket

from src.manager.ram_logging.log_manager import LogManager
from ....ram_logging.log_manager import LogManager


class Client(threading.Thread):
Expand Down Expand Up @@ -37,6 +37,7 @@ def on_message(self, ws, message):
self.callback(self.name, message)

def on_error(self, ws, error):
LogManager.logger.info(f"There was an error in {self.name} client connection.")
LogManager.logger.error(error)

def on_close(self, ws, status, msg):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import rosservice
from threading import Thread

from src.manager.libs.applications.compatibility.client import Client
from src.manager.libs.process_utils import stop_process_and_children
from src.manager.ram_logging.log_manager import LogManager
from src.manager.manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from src.manager.manager.lint.linter import Lint
from ...applications.compatibility.client import Client
from ...process_utils import stop_process_and_children
from ....ram_logging.log_manager import LogManager
from ....manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from ....manager.lint.linter import Lint


class CompatibilityExerciseWrapper(IRoboticsPythonApplication):
Expand All @@ -28,11 +28,9 @@ def __init__(self, exercise_command, gui_command, update_callback):
f'{home_dir}/ws_code.log',
'websocket_code=ready')
if process_ready:
LogManager.logger.info(
f"Exercise code {exercise_command} launched")
LogManager.logger.info(f"Exercise code {exercise_command} launched")
time.sleep(1)
self.exercise_connection = Client(
'ws://127.0.0.1:1905', 'exercise', self.server_message)
self.exercise_connection = Client('ws://127.0.0.1:1905', 'exercise', self.server_message)
self.exercise_connection.start()
else:
self.exercise_server.kill()
Expand All @@ -43,18 +41,16 @@ def __init__(self, exercise_command, gui_command, update_callback):
if process_ready:
LogManager.logger.info(f"Exercise gui {gui_command} launched")
time.sleep(1)
self.gui_connection = Client(
'ws://127.0.0.1:2303', 'gui', self.server_message)
self.gui_connection = Client('ws://127.0.0.1:2303', 'gui', self.server_message)
self.gui_connection.start()
else:
self.gui_server.kill()
raise RuntimeError(f"Exercise GUI {gui_command} could not be run")

self.running = True

self.start_send_freq_thread()


def send_freq(self, exercise_connection, is_alive):
"""Send the frequency of the brain and gui to the exercise server"""
while is_alive():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@

import psutil

from src.manager.libs.process_utils import stop_process_and_children
from src.manager.manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from src.manager.manager.lint.linter import Lint
from src.manager.manager.docker_thread.docker_thread import DockerThread

from src.manager.libs.applications.compatibility.client import Client
from src.manager.libs.process_utils import stop_process_and_children
from src.manager.ram_logging.log_manager import LogManager
from src.manager.manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from src.manager.manager.lint.linter import Lint
from ...process_utils import stop_process_and_children
from ....manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from ....manager.lint.linter import Lint

import os


class RoboticsApplicationWrapper(IRoboticsPythonApplication):

def __init__(self, update_callback):
Expand All @@ -29,8 +23,9 @@ def __init__(self, update_callback):
self.user_process = None

def _create_process(self, cmd):
#print("creando procesos")
process = subprocess.Popen(f"{cmd}", shell=True, stdout = sys.stdout, stderr=subprocess.STDOUT, bufsize=1024, universal_newlines=True)
# print("creando procesos")
process = subprocess.Popen(f"{cmd}", shell=True, stdout=sys.stdout, stderr=subprocess.STDOUT, bufsize=1024,
universal_newlines=True)
psProcess = psutil.Process(pid=process.pid)
return psProcess

Expand All @@ -44,9 +39,9 @@ def load_code(self, code: str):
self.f = open("user_code.py", "w")
self.f.write(code)
self.f.close()
#self.update_callback("Hello World")
# self.update_callback("Hello World")

def run(self):
def run(self):
self.user_process = self._create_process(f"DISPLAY=:2 python {self.f.name}")

self.running = True
Expand Down Expand Up @@ -92,9 +87,9 @@ def suspend_resume(self, signal):
# send signal to processes
for p in children:
try:
if(signal == "pause"):
if (signal == "pause"):
p.suspend()
if(signal == "resume"):
if (signal == "resume"):
p.resume()
except psutil.NoSuchProcess:
pass
pass
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from src.manager.manager.application.robotics_python_application_interface import IRoboticsPythonApplication
from ...manager.application.robotics_python_application_interface import IRoboticsPythonApplication


class RoboticsApplication(IRoboticsPythonApplication):
def pause(self):
pass

def resume(self):
pass

def terminate(self):
pass

Expand Down
Loading