Esempio n. 1
0
 def __contains__(self, key):
     from fabric.state import env
     seek_gateway = False
     key = normalize_to_string(key)
     if env.gateway:
         seek_gateway = normalize_to_string(env.gateway) != key
     if seek_gateway:
         key = normalize_to_string(env.gateway) + '_' + key
     return dict.__contains__(self, key)
Esempio n. 2
0
    def connect(self, key):
        """
        Force a new connection to host string.
        """
        from fabric.state import env

        user, host, port = normalize(key)
        key = normalize_to_string(key)
        seek_gateway = True
        # break the loop when the host is gateway itself
        if env.gateway:
            seek_gateway = normalize_to_string(env.gateway) != key
            key = normalize_to_string(env.gateway)+'_'+key
        self[key] = connect(
            user, host, port, cache=self, seek_gateway=seek_gateway)
Esempio n. 3
0
 def __getitem__(self, key):
     """
     Autoconnect + return connection object
     """
     from fabric.state import env
     seek_gateway = False
     key = normalize_to_string(key)
     if env.gateway:
         seek_gateway = normalize_to_string(env.gateway) != key
     if key not in self and (not seek_gateway or \
            normalize_to_string(env.gateway)+'_'+key not in self):
         self.connect(key)
     if seek_gateway:
         key = normalize_to_string(env.gateway) + '_' + key
     return dict.__getitem__(self, key)
Esempio n. 4
0
File: tasks.py Progetto: Dgo-list/iq
        def inner(args, kwargs, queue, name, env):
            state.env.update(env)

            def submit(result):
                queue.put({'name': name, 'result': result})

            try:
                key = normalize_to_string(state.env.host_string)
                state.connections.pop(key, "")
                submit(task.run(*args, **kwargs))
            except BaseException, e:  # We really do want to capture everything
                # SystemExit implies use of abort(), which prints its own
                # traceback, host info etc -- so we don't want to double up
                # on that. For everything else, though, we need to make
                # clear what host encountered the exception that will
                # print.
                if e.__class__ is not SystemExit:
                    sys.stderr.write(
                        "!!! Parallel execution exception under host %r:\n" %
                        name)
                    submit(e)
                # Here, anything -- unexpected exceptions, or abort()
                # driven SystemExits -- will bubble up and terminate the
                # child process.
                raise
Esempio n. 5
0
 def inner(args, kwargs, queue, name):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     try:
         result = task.run(*args, **kwargs)
     except BaseException, e:  # We really do want to capture everything
         result = e
Esempio n. 6
0
 def inner(args, kwargs, queue, name):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     try:
         result = task.run(*args, **kwargs)
     except BaseException, e: # We really do want to capture everything
         result = e
Esempio n. 7
0
        def inner(args, kwargs, queue, name, worker, env):
            #setup the correct host_string for this process
            #since the env currently has the worker cfarm name as the
            #host_string which is always the actual connection_name
            env['host_string'] = worker.connection_name
            state.env.update(env)

            def submit(result):
                queue.put({'name': name, 'result': result})
            try:
                key = normalize_to_string(state.env.host_string)
                state.connections.pop(key, "")

                #copy kwargs and remove workers and replace it
                #with the current worker this only works since we control
                #the tasks we are calling
                my_kwargs = kwargs
                my_kwargs.pop('workers')
                my_kwargs['worker']=worker

                submit(task.run(*args, **kwargs))
            except BaseException, e: # We really do want to capture everything
                # SystemExit implies use of abort(), which prints its own
                # traceback, host info etc -- so we don't want to double up
                # on that. For everything else, though, we need to make
                # clear what host encountered the exception that will
                # print.
                if e.__class__ is not SystemExit:
                    sys.stderr.write("!!! Parallel execution exception under host %r:\n" % name)
                    submit(e)
                # Here, anything -- unexpected exceptions, or abort()
                # driven SystemExits -- will bubble up and terminate the
                # child process.
                raise
Esempio n. 8
0
 def inner(*args, **kwargs):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     try:
         to_call(*args, **kwargs)
     except SystemExit, e:
         if not state.env.skip_on_failure:
             raise
Esempio n. 9
0
 def inner(args, kwargs, queue, name):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     try:
         result = task.run(*args, **kwargs)
     except BaseException, e: # We really do want to capture everything
         result = e
         # But still print it out, otherwise users won't know what the
         # f**k. Especially if the task is run at top level and nobody's
         # doing anything with the return value.
         print >> sys.stderr, "!!! Parallel execution exception under host %r:" % name
         sys.excepthook(*sys.exc_info())
Esempio n. 10
0
 def inner(args, kwargs, queue, name):
     try:
         key = normalize_to_string(state.env.host_string)
         state.connections.pop(key, "")
         result = task.run(*args, **kwargs)
     except BaseException, e: # We really do want to capture everything
         result = e
         # But still print it out, otherwise users won't know what the
         # f**k. Especially if the task is run at top level and nobody's
         # doing anything with the return value.
         # BUT don't do this if it's a SystemExit as that implies use of
         # abort(), which does its own printing.
         if e.__class__ is not SystemExit:
             print >> sys.stderr, "!!! Parallel execution exception under host %r:" % name
             sys.excepthook(*sys.exc_info())
         # Conversely, if it IS SystemExit, we can raise it to ensure a
         # correct return value.
         else:
             raise
Esempio n. 11
0
 def inner(args, kwargs, queue, name):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     try:
         result = task.run(*args, **kwargs)
     except BaseException, e:  # We really do want to capture everything
         result = e
         # But still print it out, otherwise users won't know what the
         # f**k. Especially if the task is run at top level and nobody's
         # doing anything with the return value.
         # BUT don't do this if it's a SystemExit as that implies use of
         # abort(), which does its own printing.
         if e.__class__ is not SystemExit:
             print >> sys.stderr, "!!! Parallel execution exception under host %r:" % name
             sys.excepthook(*sys.exc_info())
         # Conversely, if it IS SystemExit, we can raise it to ensure a
         # correct return value.
         else:
             raise
Esempio n. 12
0
        def inner(args, kwargs, queue, name, env):
            state.env.update(env)

            def submit(result):
                queue.put({'name': name, 'result': result})

            try:
                key = normalize_to_string(state.env.host_string)
                state.connections.pop(key, "")
                submit(task.run(*args, **kwargs))
            except NetworkError, e:
                # Backwards compat test re: whether to use an exception or
                # abort
                if not state.env.use_exceptions_for['network']:
                    func = warn if state.env.skip_bad_hosts else abort
                    from fabric.io import prefixed_output
                    with prefixed_output("[%s]: " % state.env.host_string):
                        error(e.message, func=func, exception=e.wrapped)
                else:
                    raise
Esempio n. 13
0
            def inner(args, kwargs, queue, name):
                def submit(result):
                    queue.put({'name': name, 'result': result})

                try:
                    key = normalize_to_string(state.env.host_string)
                    state.connections.pop(key, "")
                    submit(task.run(*args, **kwargs))
                except BaseException, e: # We really do want to capture everything
                    # SystemExit implies use of abort(), which prints its own
                    # traceback, host info etc -- so we don't want to double up
                    # on that. For everything else, though, we need to make
                    # clear what host encountered the exception that will
                    # print.
                    if e.__class__ is not SystemExit:
                        print >> sys.stderr, "!!! Parallel execution exception under host %r:" % name
                        submit(e)
                    # Here, anything -- unexpected exceptions, or abort()
                    # driven SystemExits -- will bubble up and terminate the
                    # child process.
                    raise
Esempio n. 14
0
 def inner(*args, **kwargs):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     task.run(*args, **kwargs)
Esempio n. 15
0
File: tasks.py Progetto: sjmh/fabric
 def inner(*args, **kwargs):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     task.run(*args, **kwargs)
Esempio n. 16
0
 def inner(args, kwargs, queue):
     key = normalize_to_string(state.env.host_string)
     state.connections.pop(key, "")
     result = task.run(*args, **kwargs)
     queue.put(result)