def parse_command(string: str): try: command = string.split(command_delimiter) return json_decode(command[1]) except: traceback.print_exc(file=sys.stdout) raise RuntimeError('cant decode command')
def parse_command(string: str): try: command = string.split(command_delimiter) return json_decode(command[1]) except: traceback.print_exc(file=sys.stdout) raise RuntimeError('cant decode command')
def command_install(self): state = json_decode(self.params) result = core.core.Core.get_instance().install(state['products'], state['parameters'], False, True) state["parameters"] = result['parameters'] self.params = json_encode(state) self.save()
def process_command(self, line, job): command = line.split(core.core.command_delimiter) command_json = json_decode(command[1]) if command_json["command"] == "start_work_job": job.setup_job(int(command_json["job_id"])) logging.debug("job is setuping %i" % command_json["job_id"]) return False if command_json["command"] == "error": line = "<a id='error{0}' href='#'><strong>{1}</strong></a>\ <p class='error{0} error'>{2}</p>".format( command_json["job_id"], command_json["message"], command_json["trace"]) log_msg = self.put_new_message( LogMessage(message=line, job_object=job.current_job, task_id=job.task_id, job_process=job, task_state=JobDataModel.STATUS_RUNNING, source="worker", level=logging.ERROR)) return log_msg # means unrecognized command if command_json["command"] == "ping": return False return False
def json_request(request): """ Парсит тело http-запроса из джейсона в питоньи объекты (словари и списки) """ s = request.body if isinstance(s, bytes): s = s.decode('utf-8') return json_decode(s)
def on_message(self, message): """ when we receive some message we want some message handler.. for this example i will just print message to console """ obj = json_decode(message) self.writing_logs(obj) return
def task2json(self, parent_pid): task = TaskManager.get_task(self.task_id) JobList = [] for job in task.jobs: dict_obj = {"job_id": job.id, "params": json_decode(job.params), "command": job.command, "parent_pid": parent_pid} JobList.append(dict_obj) return json.dumps(JobList)
def on_message(self, message): """ when we receive some message we want some message handler.. for this example i will just print message to console """ try: request = json_decode(message) if "create" in request: Result = self.create_console(request) self.write_message(json_encode({"status": Result})) return if "cancel" in request: logging.debug("cancel console") if self.background_object: self.background_object.close() self.close() return if "ping" in request: if "path" in request: path = request["path"] console_obj = WebConsole.get_console(path) if console_obj: self.writing_output(request) else: self.write_empty_pong() return if "ctrl_c" in request: console_instance = WebConsole.get_console(request["path"]) if console_instance: self.background_object.close() self.close() return if "command" in request: console_instance = WebConsole.get_console(request["path"]) if console_instance: console_instance.execute(request['command']) self.writing_output(request) else: self.writing_console_down(request) return except Exception as e: error = traceback.format_exc() self.writing_error(error)
def on_message(self, message): """ when we receive some message we want some message handler.. for this example i will just print message to console """ try: request = json_decode(message) if "create" in request: Result = self.create_console(request) self.write_message(json_encode({"status": Result})) return if "cancel" in request: logging.debug("cancel console") if self.background_object: self.background_object.close() self.close() return if "ping" in request: if "path" in request: path = request["path"] console_obj = WebConsole.get_console(path) if console_obj: self.writing_output(request) else: self.write_empty_pong() return if "ctrl_c" in request: console_instance = WebConsole.get_console(request["path"]) if console_instance: self.background_object.close() self.close() return if "command" in request: console_instance = WebConsole.get_console(request["path"]) if console_instance: console_instance.execute(request['command']) self.writing_output(request) else: self.writing_console_down(request) return except Exception as e: error = traceback.format_exc() self.writing_error(error)
def to_dict(self): """ для сериализации в json :return: """ return { 'id': self.id, 'created': self.created.isoformat(), 'updated': self.updated.isoformat(), 'title': self.title, 'command': self.command, 'params': json_decode(self.params) if self.params else None, 'params_str': self.params, 'status': self.status, 'error_message': self.error_message, 'is_finished': True if self.status in (self.STATUS_DONE, self.STATUS_FAILED, self.STATUS_CANCELED) else False }
def to_json(self): return json_decode({"task": self.id})
def command_upgrade(self): state = json_decode(self.params) result = core.core.Core.get_instance().upgrade(state['products'], state.get('parameters')) state["parameters"] = result['parameters'] self.params = json_encode(state) self.save()