Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import os
00011 import signal
00012 import rocon_console.console as console
00013
00014
00015
00016
00017
00018
00019 class LaunchInfo(object):
00020 __slots__ = [
00021 'name',
00022 'running',
00023 'process',
00024 ]
00025
00026 def __init__(self, name, running, process):
00027 """
00028 :param str name:
00029 :param bool running:
00030 :param rocon_python_utils.system.Popen process:
00031 """
00032 self.name = name
00033 self.running = running
00034 self.process = process
00035
00036 def shutdown(self):
00037 '''
00038 Shutdown the process, if there is a process. Note that the internal
00039 process variable can be None signifying that this is a dummy interaction
00040 for use with pairing mode.
00041 '''
00042 if self.process is not None:
00043 self.process.send_signal(signal.SIGINT)
00044
00045 def __str__(self):
00046 '''
00047 Format the interaction into a human-readable string.
00048 '''
00049 s = console.bold + "Launch Info" + console.reset + '\n'
00050 s += console.bold + " Name " + console.reset + " : " + console.yellow + self.name + console.reset + '\n'
00051 s += console.bold + " Running" + console.reset + " : " + console.yellow + str(self.running) + console.reset + '\n'
00052 s += console.bold + " Process" + console.reset + " : " + console.yellow + str(self.process) + console.reset + '\n'
00053 return s
00054
00055
00056 class RosLaunchInfo(LaunchInfo):
00057 __slots__ = [
00058 'temporary_files',
00059 '_terminal_shutdown_hook',
00060 ]
00061
00062 def __init__(self, name, running, process, terminal_shutdown_hook, temporary_files=[]):
00063 """
00064 :param str name:
00065 :param bool running:
00066 :param rocon_python_utils.system.Popen process:
00067 :param func terminal_shutdown_hook: function to call on shutdown to kill the roslaunched terminal window
00068 :param tempfile.NamedTemporaryFile[] temporary_files: files that need to be unlinked later.
00069 """
00070 super(RosLaunchInfo, self).__init__(name, running, process)
00071 self.temporary_files = temporary_files
00072 self._terminal_shutdown_hook = terminal_shutdown_hook
00073
00074
00075 def shutdown(self):
00076 self._terminal_shutdown_hook(processes=[self.process], hold=False)
00077 for temporary_file in self.temporary_files:
00078 console.logdebug(" unlinking %s" % temporary_file.name)
00079 try:
00080 os.unlink(temporary_file.name)
00081 except OSError:
00082 pass