From: Marc Schink Date: Mon, 20 May 2019 16:14:46 +0000 (+0200) Subject: contrib/rpc_examples: Add (dis)connect methods X-Git-Tag: v0.11.0-rc1~538 X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff_plain;h=refs%2Fchanges%2F89%2F5189%2F2;ds=sidebyside contrib/rpc_examples: Add (dis)connect methods Add these methods such that the OpenOcd class can also be used outside of a 'with' statement. Change-Id: I927c93fff2dc05cc74daa56360a7262e736a639f Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5189 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index 4b1516ad90..9d17e76957 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -49,10 +49,16 @@ class OpenOcd: self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def __enter__(self): - self.sock.connect((self.tclRpcIp, self.tclRpcPort)) + self.connect() return self def __exit__(self, type, value, traceback): + self.disconnect() + + def connect(self): + self.sock.connect((self.tclRpcIp, self.tclRpcPort)) + + def disconnect(self): try: self.send("exit") finally: