Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3e706b

Browse files
committed
Use appropriate program name in output.
1 parent f94bb75 commit d3e706b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

pymatbridge/pymatbridge.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def __init__(self, executable, socket_addr=None,
9292
self.context = None
9393
self.socket = None
9494

95+
def _program_name(self):
96+
raise NotImplemented
97+
9598
def _preamble_code(self):
9699
return ["addpath(genpath('%s'))" % MATLAB_FOLDER]
97100

@@ -111,7 +114,7 @@ def _run_server(self):
111114
# Start server/client session and make the connection
112115
def start(self):
113116
# Start the MATLAB server in a new process
114-
print "Starting MATLAB on ZMQ socket %s" % (self.socket_addr)
117+
print "Starting %s on ZMQ socket %s" % (self._program_name(), self.socket_addr)
115118
print "Send 'exit' command to kill the server"
116119
self._run_server()
117120

@@ -124,10 +127,10 @@ def start(self):
124127

125128
# Test if connection is established
126129
if self.is_connected():
127-
print "MATLAB started and connected!"
130+
print "%s started and connected!" % self._program_name()
128131
return True
129132
else:
130-
print "MATLAB failed to start"
133+
print "%s failed to start" % self._program_name()
131134
return False
132135

133136
def _response(self, **kwargs):
@@ -140,7 +143,7 @@ def _response(self, **kwargs):
140143
def stop(self):
141144
# Matlab should respond with "exit" if successful
142145
if self._response(cmd='exit') == "exit":
143-
print "MATLAB closed"
146+
print "%s closed" % self._program_name()
144147

145148
self.started = False
146149
return True
@@ -163,11 +166,12 @@ def is_connected(self):
163166
sys.stdout.write('.')
164167
time.sleep(1)
165168
if time.time() - start_time > self.maxtime:
166-
print "Matlab session timed out after %d seconds" % self.maxtime
169+
print "%s session timed out after %d seconds" % (self._program_name(), self.maxtime)
167170
return False
168171

169172
def is_function_processor_working(self):
170-
result = self.run_func('%s/test_functions/test_sum.m' % MATLAB_FOLDER, {'echo': 'Matlab: Function processor is working!'})
173+
result = self.run_func('%s/test_functions/test_sum.m' % MATLAB_FOLDER,
174+
{'echo': '%s: Function processor is working!' % self._program_name()})
171175
return result['success'] == 'true'
172176

173177
def _json_response(self, **kwargs):
@@ -237,6 +241,9 @@ def __init__(self, executable='matlab', socket_addr=None,
237241
super(Matlab, self).__init__(executable, socket_addr, id, log, maxtime,
238242
platform, startup_options)
239243

244+
def _program_name(self):
245+
return 'MATLAB'
246+
240247
def _execute_flag(self):
241248
return '-r'
242249

@@ -282,6 +289,9 @@ def __init__(self, executable='octave', socket_addr=None,
282289
super(Octave, self).__init__(executable, socket_addr, id, log, maxtime,
283290
platform, startup_options)
284291

292+
def _program_name(self):
293+
return 'Octave'
294+
285295
def _preamble_code(self):
286296
code = super(Octave, self)._preamble_code()
287297
if self.log:

0 commit comments

Comments
 (0)