From ad73c53afc21b044a230eb278c0a3eebc7d5fd0c Mon Sep 17 00:00:00 2001 From: aditya Date: Tue, 3 Oct 2023 21:07:42 +0530 Subject: [PATCH] Future class not needed in python3, revc_msg bug fix, The file is now completely functional Signed-off-by: aditya --- scripts/avogadro-remote.py | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/scripts/avogadro-remote.py b/scripts/avogadro-remote.py index 9fafbb5c..b19a6f97 100755 --- a/scripts/avogadro-remote.py +++ b/scripts/avogadro-remote.py @@ -1,16 +1,11 @@ #!/usr/bin/python - -from __future__ import print_function - import sys import json import socket import struct import tempfile - class Connection: '''Process a JSON-RPC request''' - def __init__(self, name="avogadro"): """ Connect to the local named pipe @@ -19,16 +14,14 @@ def __init__(self, name="avogadro"): """ # create socket self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - # connect try: self.sock.connect(tempfile.gettempdir() + "/" + name) # print the connection statement - print("reply:" + str(self.__json("recv_msg",None))) + print("CONNECTION ESTABLISHED SUCCESSFULLY") except Exception as exception: print("error while connecting: " + str(exception)) sys.exit(1) - def __json(self, method, file): """ Send a JSON-RPC request to the named pipe. @@ -38,15 +31,9 @@ def __json(self, method, file): """ if method == "recv_msg": - size = 1024 packet = self.sock.recv(size) - return packet[4:] - # try: - # return json.loads(msg_packet) - # except Exception as exception: - # print("error: " + str(exception)) - # return {} + print("reply:" + str(packet[4: ])) else: msg = { "jsonrpc": "2.0", @@ -58,24 +45,24 @@ def __json(self, method, file): size = len(json_msg) header = struct.pack(">I", size) packet = header + json_msg.encode("ascii") - self.sock.send(packet) - + self.sock.send(packet) def open_file(self, file): """Opens file""" # param: file is filename input by the user in string method = "openFile" - self.__json(method,file) - + self.__json(method,file) + self.__json("recv_msg",None) def save_graphic(self, file): """Save Graphic""" method = "saveGraphic" self.__json(method,file) - + self.__json("recv_msg",None) def kill(self): """To kill the current operation""" method = "kill" self.__json(method,None) - + self.__json("recv_msg",None) def close(self): '''Close the socket to the named pipe''' - self.sock.close() \ No newline at end of file + self.sock.close() + print("CONNECTION CLOSED SUCCESSFULLY") \ No newline at end of file