From a648e3fbbecb8d629c17977202373c395e8140c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Mon, 30 Sep 2019 14:22:21 +0200 Subject: [PATCH] #930: Remove duplicate code and fix some typos. --- .../modules/server/OpenGnSys/__init__.py | 110 ++++-------------- 1 file changed, 23 insertions(+), 87 deletions(-) diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index 188157a..ac49ac4 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -33,7 +33,9 @@ from __future__ import unicode_literals import os import random import shutil +import signal import string +import subprocess import threading import time import urllib @@ -45,12 +47,12 @@ from opengnsys.workers import ServerWorker from six.moves.urllib import parse - # Check authorization header decorator def check_secret(fnc): """ Decorator to check for received secret key and raise exception if it isn't valid. """ + def wrapper(*args, **kwargs): try: this, path, get_params, post_params, server = args # @UnusedVariable @@ -73,6 +75,7 @@ def catch_background_error(fnc): fnc(*args, **kwargs) except Exception as e: this.REST.sendMessage('error?id={}'.format(kwargs.get('requestId', 'error')), {'error': '{}'.format(e)}) + return wrapper @@ -160,48 +163,8 @@ class OpenGnSysWorker(ServerWorker): if os_type == 'oglive': # Send configuration data, if needed if send_config: - self.REST.sendMessage('clients/configs', {'mac': self.interface.mac, 'ip': self.interface.ip, - 'config': operations.get_configuration()}) - self._launch_browser(menu_url) - - def _launch_browser(self, url): - """ - Launchs the Browser with specified URL - :param url: URL to show - """ - logger.debug('Launching browser with URL: {}'.format(url)) - if hasattr(self.browser, 'process'): - self.browser['process'].kill() - self.browser['url'] = url - self.browser['process'] = subprocess.Popen(['browser', '-qws', url]) - - def _task_command(self, route, code, op_id): - """ - Task to execute a command and return results to a server URI - :param route: server callback REST route to return results - :param code: code to execute - :param op_id: operation id. - """ - menu_url = '' - # Show execution tacking log, if OGAgent runs on ogLive - os_type = operations.os_type.lower() - if os_type == 'oglive': - menu_url = self.browser['url'] - self._launch_browser('http://localhost/cgi-bin/httpd-log.sh') - # Executing command - (stat, out, err) = operations.exec_command(code) - # Removing command from the list - for c in self.commands: - if c.getName() == op_id: - self.commands.remove(c) - # Removing the REST API prefix, if needed - if route.startswith(self.REST.endpoint): - route = route[len(self.REST.endpoint):] - # Sending results - self.REST.sendMessage(route, {'mac': self.interface.mac, 'ip': self.interface.ip, 'trace': op_id, - 'status': stat, 'output': out, 'error': err}) - # Show latest menu, if OGAgent runs on ogLive - if os_type == 'oglive': + self.REST.sendMessage('client/configs', {'mac': self.interface.mac, 'ip': self.interface.ip, + 'config': operations.get_configuration()}) self._launch_browser(menu_url) def onActivation(self): @@ -262,20 +225,20 @@ class OpenGnSysWorker(ServerWorker): # Completing OGAgent initialization process os_type = operations.os_type.lower() if os_type == 'oglive': - ### Following code may be separated in a different function to launch browser while catching disk configuration + # # Following code may be separated in a different function to launch browser while get disk configuration message = """

OpenGnsys 3 -
+