88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# *****************************************************************************
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 2 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along with
|
|
# this program; if not, write to the Free Software Foundation, Inc.,
|
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
# Module authors:
|
|
# Markus Zolliker <markus.zolliker@psi.ch>
|
|
#
|
|
# *****************************************************************************
|
|
|
|
import sys
|
|
import time
|
|
import termios
|
|
import subprocess
|
|
from servman import ServiceManager, ServiceDown
|
|
from servman.sicsclient import sics_client
|
|
|
|
|
|
def run_command(cmd, wait=False):
|
|
if wait:
|
|
old = termios.tcgetattr(sys.stdin)
|
|
try:
|
|
proc = subprocess.Popen(cmd.split())
|
|
proc.wait()
|
|
except KeyboardInterrupt:
|
|
proc.terminate()
|
|
finally:
|
|
# in case cmd changed tty attributes
|
|
termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, old)
|
|
print('')
|
|
else:
|
|
subprocess.Popen(cmd.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
|
|
class SeaManager(ServiceManager):
|
|
group = 'sea'
|
|
services = ('sea', 'graph')
|
|
|
|
def do_cli(self, ins):
|
|
try:
|
|
self.check_running(ins, 'sea')
|
|
except ServiceDown as e:
|
|
print('%s, try to start...' % e)
|
|
self.do_start(ins)
|
|
time.sleep(1) # make sure caller did read the message
|
|
except KeyError as e: # running on an other machine?
|
|
pass
|
|
run_command('six -sea %s' % ins, wait=True)
|
|
|
|
def do_gui(self, ins=''):
|
|
try:
|
|
self.check_running(ins, 'sea')
|
|
except ServiceDown as e:
|
|
print('%s, try to start...' % e)
|
|
self.do_start(ins)
|
|
time.sleep(1) # make sure caller did read the message
|
|
except KeyError as e: # running on an other machine?
|
|
pass
|
|
run_command('SeaClient %s' % ins)
|
|
print('starting sea gui %s' % ins)
|
|
time.sleep(5)
|
|
|
|
|
|
def get_cfg(self, ins, service):
|
|
"""return cfg info about running programs, if relevant
|
|
|
|
return samenv name
|
|
"""
|
|
if service != 'sea': # ignore when service == 'graph'
|
|
return ''
|
|
try:
|
|
return sics_client(('localhost', self.info[ins]['sea']), 'samenv name')
|
|
except Exception as e:
|
|
print(self.info)
|
|
return repr(e)
|