Creates a temp directory executing the block provided. When done the
 temp directory and all it's contents are garbage collected.

 @yield [Proc] block
   A block that will be run

 @return [Object]
   Result of the block operation

 @api public
171981
def with_tmp_dir(&block)
      Dir.mktmpdir(SecureRandom.hex(3)) do |tmp_dir|
        Dir.chdir(tmp_dir, &block)
      end
    end
23018
def make_temp(suffix="", prefix="tmp", dir=None):
    
    temporary = tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir)
    os.close(temporary[0])
    try:
        yield temporary[1]
    finally:
        os.remove(temporary[1])
559527
def select
      new_instance = self.class.new
      if block_given?
        @data.each { |k,v| new_instance.data[k] = v if yield(k,v) }
      end
      return new_instance
    end
1166469
def lock!(*args)
      fail 'No block passed' unless block_given?

      lock(*args) do |lock_info|
        raise LockError, 'failed to acquire lock' unless lock_info
        return yield
      end
    end
122878
def and_yield(*args)
      yield eval_context = Object.new if block_given?
      @plan = Proc.new do |&block|
        eval_context.instance_exec(*args, &block)
      end
      self
    end
636185
def let meth, &proc
      proc || raise(ArgumentError, 'block is missing')
      vars[meth] = proc
      define_method(meth) { @__ms__vars[meth] ||= self.instance_exec(&proc) }
    end
891515
def _prepare_temp_dir(self):
    """"""
    if not shell_call(['sudo', 'rm', '-rf', os.path.join(self._temp_dir, '*')]):
      logging.error('Failed to cleanup temporary directory.')
      sys.exit(1)
    # NOTE: we do not create self._extracted_submission_dir
    # this is intentional because self._tmp_extracted_dir or it's subdir
    # will be renames into self._extracted_submission_dir
    os.mkdir(self._tmp_extracted_dir)
    os.mkdir(self._sample_input_dir)
    os.mkdir(self._sample_output_dir)
    # make output dir world writable
    shell_call(['chmod', 'a+rwX', '-R', self._sample_output_dir])
1057406
def each(&block)
      return @results.each(&block) if @results
      @results = []
      cur_v_i = Array.new(@data.keys.length, 0)
      keys = @data.keys.sort_by(&:to_s)
      result = {}
      keys.each do |key|
        result[key] = @data[key][0]
      end
      while true
        r = result.dup
        @results << r
        block.call(r) if block
        keys.each_with_index do |k, k_i|
          v_i = ((cur_v_i[k_i] = (1 + cur_v_i[k_i]) % @data[k].length))
          result[k] = @data[k][v_i]
          if v_i > 0 # Found next ?
            break
          elsif k_i == keys.length - 1 # Last?
            return
          end
        end
      end
      @results
    end
1364966
def tempdir():
    """"""
    directory_path = tempfile.mkdtemp()

    def clean_up():  # pylint: disable=missing-docstring
        shutil.rmtree(directory_path, onerror=on_error)

    with cd(directory_path, clean_up):
        yield directory_path
546044
def create
      @block = Block.builder(params)

      if @block.save
        render json: { status: :success }, status: :ok
      else
        render json: @block.errors, status: :unprocessable_entity
      end
    end
435136
def generate_dir(dest)
      return if @generated_dirs.has_key?(dest)

      path = interpolate(dest)
      empty_directory path

      @generated_dirs[dest] = path
      return path
    end
603438
def open(*args, &block)
      obj = new(*args)
      if block_given?
        begin
          yield obj
        ensure
          obj.close
        end
      else
        obj
      end
    end
1368978
def add( io )
      # spooling to a temp file because Gem::Format.from_io() closes the io
      # stream it is sent.  Why it does this, I do not know. This may be
      # removed once we are no longer using older rubygems
      tempfile = Tempfile.new(  "uploaded-gem.", temp_dir )
      tempfile.write( io.read )
      tempfile.rewind

      container = Stickler::GemContainer.new( tempfile.path )
      spec      = Stickler::SpecLite.new( container.spec.name, container.spec.version, container.spec.platform )
      specs     = search_for( spec )

      raise Error, "gem #{spec.full_name} already exists" unless specs.empty?

      tempfile.rewind
      return install( spec, tempfile )
    ensure
      tempfile.close!
    end
835563
def run_deferred(top_level_context)
      deferred_blocks = self.deferred_blocks
      @deferred_blocks = nil

      deferred_blocks.each do |target, block|
        context(target, &block)
      end

      if @deferred_blocks
        run_deferred(top_level_context)
      end
    end
737913
def output(data, stream_name = :stdout, &block)
        # Pass the output to the block
        if block.arity == 2
          args = [nil, nil]
          if stream_name == :stdout
            args[0] = data
          else
            args[1] = data
          end
          block.call(*args)
        else
          yield data if stream_name == :stdout
        end
      end
541551
def run(&_block)
      return_value = nil

      command = catch(:breakout_nav) do # Throws from PryByebug::Commands
        return_value = allowing_other_threads { yield }
        {} # Nothing thrown == no navigational command
      end

      # Pry instance to resume after stepping
      @pry = command[:pry]

      perform(command[:action], command[:options])

      return_value
    end
457308
def each(&block)
      # TODO: Using block.call here is slower than using yield by 5-10%, but
      # the latter segfaults on ruby 2.2 and above. Once that is fixed and
      # broken versions are sufficiently old, we should revert back to yield
      # with a warning that the broken versions are unsupported.
      #
      # For more context:
      # * https://bugs.ruby-lang.org/issues/11451
      # * https://github.com/hamstergem/hamster/issues/189
      @entries.each { |entry| block.call(entry) if entry }
      @children.each do |child|
        child.each(&block) if child
      end
      nil
    end