MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / start_process

Function start_process

web/pgadmin/tools/psql/__init__.py:296–369  ·  view source on GitHub ↗

Start the pty terminal and execute psql command and emit results to user. :param data: :return:

(data)

Source from the content-addressed store, hash-verified

294@sio.on('start_process', namespace='/pty')
295@socket_login_required
296def start_process(data):
297 """
298 Start the pty terminal and execute psql command and emit results to user.
299 :param data:
300 :return:
301 """
302 @copy_current_request_context
303 def read_and_forward_pty_output(sid, data):
304 pty_handel_io(connection_data, data, sid)
305
306 # Check user is authenticated and PSQL is enabled in config.
307 if current_user.is_authenticated and config.ENABLE_PSQL:
308 connection_data = []
309 connection_successful = False
310 try:
311 db = ''
312 if data['db']:
313 db = underscore_unescape(data['db'])
314
315 data['db'] = db
316
317 _, manager = _get_connection(int(data['sid']), data)
318 psql_utility = manager.utility('sql')
319 if psql_utility is None or not os.path.exists(psql_utility):
320 sio.emit('pty-output',
321 {
322 'result': gettext(
323 'PSQL utility not found. Specify the valid '
324 'binary path in the preferences for the '
325 'appropriate server version, or select '
326 '"Set as default" to use an existing binary '
327 'path.'),
328 'error': True},
329 namespace='/pty', room=request.sid)
330 return
331 connection_data = get_connection_str(psql_utility, db,
332 manager)
333 connection_successful = True
334 except Exception as e:
335 # If any error raised during the start the PSQL emit error to UI.
336 # request.sid: This sid is socket id.
337 error_msg = 'Error while running psql command: {0}'.format(e)
338 if str(e) == 'Server is not connected.':
339 error_msg = 'Error while opening psql tool: {0}'.format(e)
340
341 sio.emit('conn_error',
342 {'error': error_msg},
343 namespace='/pty',
344 room=request.sid)
345
346 if connection_successful:
347 try:
348 if str(data['sid']) not in app.config['sid_soid_mapping']:
349 # request.sid: refer request.sid as socket id.
350 app.config['sid_soid_mapping'][str(data['sid'])] = list()
351 app.config['sid_soid_mapping'][str(data['sid'])].append(
352 request.sid)
353 else:

Callers

nothing calls this directly

Calls 8

underscore_unescapeFunction · 0.90
gettextFunction · 0.85
get_connection_strFunction · 0.85
emitMethod · 0.80
appendMethod · 0.80
_get_connectionFunction · 0.70
utilityMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected