예제 #1
0
class LocalLauncher(SandboxLauncher):
    def __init__(self,
                 execparams,
                 initProps,
                 initialize,
                 configProps,
                 debugger,
                 window,
                 timeout,
                 shared,
                 stdout=None):
        self._execparams = execparams
        self._debugger = debugger
        self._window = window
        self._initProps = initProps
        self._initialize = initialize
        self._configProps = configProps
        self._timeout = timeout
        self._shared = shared
        self._stdout = stdout

    def _getImplementation(self, spd, identifier):
        for implementation in spd.get_implementation():
            if implementation.get_id() == identifier:
                return implementation
        raise KeyError, "Softpkg '%s' has no implementation '%s'" % (
            spd.get_name(), identifier)

    def _resolveDependencies(self, sdrRoot, device, implementation):
        dep_files = []
        for dependency in implementation.get_dependency():
            softpkg = dependency.get_softpkgref()
            if not softpkg:
                continue
            filename = softpkg.get_localfile().get_name()
            log.trace("Resolving softpkg dependency '%s'", filename)
            local_filename = sdrRoot.domPath(filename)
            dep_spd = parsers.spd.parse(local_filename)
            dep_impl = softpkg.get_implref()
            if dep_impl:
                impl = self._getImplementation(dep_spd, dep_impl.get_refid())
            else:
                # No implementation requested, find one that matches the device
                impl = device.matchImplementation(sdrRoot, local_filename,
                                                  dep_spd)

            log.trace("Using implementation '%s'", impl.get_id())
            dep_localfile = impl.get_code().get_localfile().get_name()
            dep_files.append(
                sdrRoot.relativePath(local_filename, dep_localfile))

            # Resolve nested dependencies.
            dep_files.extend(self._resolveDependencies(sdrRoot, device, impl))

        return dep_files

    def _cleanHeap(self, pid):
        filename = '/dev/shm/heap-' + str(pid)
        if (os.path.isfile(filename)):
            os.remove(filename)

    def launch(self, comp):
        # Build up the full set of command line arguments
        execparams = comp._getExecparams()
        execparams.update(self._execparams)
        execparams.update(self._getRequiredExecparams(comp))

        # Set up the debugger if requested
        debugger = self._debugger
        try:
            if isinstance(debugger, basestring):
                if debugger == 'pdb':
                    debugger = PDB()
                elif debugger == 'jdb':
                    debugger = JDB()
                elif debugger == 'gdb':
                    debugger = GDB()
                elif debugger == 'valgrind':
                    debugger = Valgrind()
            elif isinstance(debugger, Debugger):
                # check for PDB, JDB, Valgrind, or GDB
                pass
            elif debugger is None:
                pass
            else:
                raise RuntimeError, 'not supported'
        except Exception, e:
            log.warning('Cannot run debugger %s (%s)', debugger, e)
            debugger = None

        # If using an interactive debugger that directly runs the command, put
        # it in a window so it doesn't compete for the terminal.
        window = self._window
        if debugger and debugger.modifiesCommand():
            if debugger.isInteractive() and not debugger.canAttach():
                if not window:
                    window = 'xterm'

        # Allow symbolic names for windows
        if isinstance(window, basestring):
            try:
                if window == 'xterm':
                    window = terminal.XTerm(comp._instanceName)
                elif window == 'gnome-terminal':
                    window = terminal.GnomeTerm(comp._instanceName)
                else:
                    raise RuntimeError, 'not supported'
            except Exception, e:
                log.warning('Cannot run terminal %s (%s)', window, e)
                debugger = None
예제 #2
0
        sleepIncrement = 0.1
        while self.getReference(comp) is None:
            if not process.isAlive():
                raise RuntimeError, "%s '%s' terminated before registering with virtual environment" % (
                    self._getType(), comp._instanceName)
            time.sleep(sleepIncrement)
            timeout -= sleepIncrement
            if timeout < 0:
                process.terminate()
                raise RuntimeError, "%s '%s' did not register with virtual environment" % (
                    self._getType(), comp._instanceName)

        # Attach a debugger to the process.
        if debugger and debugger.canAttach():
            if not window:
                window = terminal.XTerm('%s (%s)' %
                                        (debugger.name(), comp._instanceName))
            debug_command, debug_args = debugger.attach(process)
            debug_command, debug_args = window.command(debug_command,
                                                       debug_args)
            debug_process = launcher.LocalProcess(debug_command, debug_args)
            process.addChild(debug_process)

        # Store the process on the component proxy.
        if impl.get_code().get_type() == 'SharedLibrary' and self._shared:
            comp._process = None
            comp._pid = None
        else:
            comp._process = process
            comp._pid = process.pid()

        # Return the now-resolved CORBA reference.