def command(executable, args, env, path, usePTY, childFD, protocol,
            *proto_args, **proto_kwargs):

    deferredResult = defer.Deferred()

    proto_args += (deferredResult,)
    if 'timeout' in proto_kwargs:
        timeout = proto_kwargs.pop('timeout')
    else:
        timeout = None
    
    #for convience
    argfix = proto_kwargs.pop('fixargs', True)

    #setup the command line to re-enter this file and daemonize
    if proto_kwargs.get('daemonize', False):
        from droned.management import dmx
        from droned.logging import log
        log('DroneD is daemonizing "%s" on your behalf' % (executable,))
        if usePTY:
            env['DRONED_USE_TTY'] = "1"
        #massage the commandline args
        if path:
            env['DRONED_PATH'] = path
        #the path to the dmx utility
        path = os.path.sep.join(
            os.path.abspath(
                os.path.dirname(dmx.__file__)
            ).split(os.path.sep)[:-1]
        )
        #arguments to dmx
        args = ('dmx', executable) + args
        #switch out the executable for the same one that launched DroneD
        executable = sys.executable

    #laziness hack
    def _fix_args(cmd, a):
        """I fix your commandline args b/c you are probably lazy like me"""
        first = cmd.split(os.path.sep)[-1]
        if not len(a):
            a = (first,)
            return a
        if first != a[0]:
            a = (first,) + tuple(a)
        return a

    if argfix:
        newargs = []
        #sanitize arguments, b/c devs do silly things ... including myself
        for i in list(_fix_args(executable, args)):
            newargs += i.split(' ')
        args = tuple(newargs)

    try: #dmx work around
        import config
        reactor = config.reactor
    except:
        from twisted.internet import reactor
    #setup the client application to run
    app = MyClientCreator(reactor, protocol, *proto_args, **proto_kwargs)
    deferredSpawn = app.spawn(executable, args, env, path, usePTY, childFD)

    #If the spawn fails the protocol task fails
    deferredSpawn.addErrback(lambda failure: deferredResult.called or
        deferredResult.errback(failure)
    )

    from kitt.decorators import debugCall
    if 'debug' in proto_kwargs and proto_kwargs['debug'] == True:
        deferredResult.errback = debugCall( deferredResult.errback )
        deferredResult.callback = debugCall( deferredResult.callback )

    if timeout:
        reactor.callLater(timeout, cancelTask, deferredResult)

    #Inject the executable and args into the results in the callback chain
    def injectInfo(outcome):
        try:
            if isinstance(outcome, dict):
                outcome['executable'] = executable
                outcome['args'] = args
            elif isinstance(outcome, Failure):
                if not outcome.check(DroneCommandFailed):
                    outcome = {
                        'error' : outcome,
                        'executable' : executable,
                        'args' : args,
                    }
        except: pass #some process failures don't have resultContext
        return outcome

    if 'debug' in proto_kwargs and proto_kwargs['debug'] == True:
        injectInfo = debugCall( injectInfo )

    deferredResult.addBoth(injectInfo)

    return deferredResult
command(host, port, protocol, *proto_args, **proto_kwargs)
dataset/ETHPy150Open OrbitzWorldwide/droned/droned/lib/droned/clients/__init__.py/command