launch.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_qt_gui/license/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 import os
00011 import signal
00012 import rocon_console.console as console
00013 
00014 ##############################################################################
00015 # Classes
00016 ##############################################################################
00017 
00018 
00019 class LaunchInfo(object):
00020     __slots__ = [
00021         'name',      # unique name for this launch
00022         'running',   # running or not
00023         'process',   # the actual process handle (e.g. subprocess return)
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'  # noqa
00050         s += console.bold + "  Name   " + console.reset + "  : " + console.yellow + self.name + console.reset + '\n'  # noqa
00051         s += console.bold + "  Running" + console.reset + "  : " + console.yellow + str(self.running) + console.reset + '\n'  # noqa
00052         s += console.bold + "  Process" + console.reset + "  : " + console.yellow + str(self.process) + console.reset + '\n'  # noqa
00053         return s
00054 
00055 
00056 class RosLaunchInfo(LaunchInfo):
00057     __slots__ = [
00058         'temporary_files',          # list of temporary files that need to be unlinked
00059         '_terminal_shutdown_hook',  # handle to a rocon_launch.terminals.Terminal class' shutdown method
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         #self._shutdown = partial(roslaunch_terminal.shutdown_roslaunch_windows, [self.process], False)  # hold = False
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


rocon_remocon
Author(s): Daniel Stonier, Donguk Lee
autogenerated on Fri Feb 12 2016 02:50:18