Method with shell and a temp file. This is hopefully fast.
483101
def sqlite_by_shell(self, destination):
        """"""
        script_path = new_temp_path()
        self.sqlite_dump_shell(script_path)
        shell_output('sqlite3 -bail -init "%s" "%s" .quit' % (script, destination))
        script.remove()
417877
def a_temp_file():
    """"""
    filename = None
    try:
        tmpfile = tempfile.NamedTemporaryFile(delete=False)
        filename = tmpfile.name
        yield tmpfile
    finally:
        if filename and os.path.exists(filename):
            os.remove(filename)
1158457
def with_temp_file
      filename = original_filename || content.default_file_name
      basename = [ File.basename(filename, ".*"), File.extname(filename) ]
      infile = Tempfile.open(basename, Ddr::Models.tempdir, encoding: 'ascii-8bit')
      begin
        infile.write(content.content)
        infile.close
        verify_checksum!(infile)
        yield infile.path
      ensure
        infile.close unless infile.closed?
        File.unlink(infile)
      end
    end
919204
def open_tempfile_if_missing(object, &block)
      if ::FileTest.file?(object)
        ::File.open(object, &block)
      else
        tempfile = Tempfile.new('tty-file-diff')
        tempfile << object
        tempfile.rewind

        block[tempfile]

        unless tempfile.nil?
          tempfile.close
          tempfile.unlink
        end
      end
    end
141084
def execute(self):
        '''  '''

        # Create a temporary directory
        self.temp_dir = tempfile.mkdtemp()
        os.chdir(self.temp_dir)

        # Spin up the directory watcher
        DirWatcher(self.temp_dir, self.file_created)

        # Spin up tcpdump
        self.subprocess_manager(self.tcpdump_cmd)
306236
def tempdir(*args, **kwargs):
    

    d = tempfile.mkdtemp(*args, **kwargs)
    try:
        yield d
    finally:
        shutil.rmtree(d)
60302
def _mkstemp_inner(dir, pre, suf, flags):
    """"""

    names = _get_candidate_names()

    for seq in range(TMP_MAX):
        name = next(names)
        file = _os.path.join(dir, pre + name + suf)
        try:
            fd = _os.open(file, flags, 0o600)
            return (fd, _os.path.abspath(file))
        except FileExistsError:
            continue    # try again
        except PermissionError:
            # This exception is thrown when a directory with the chosen name
            # already exists on windows.
            if _os.name == 'nt':
                continue
            else:
                raise

    raise FileExistsError(_errno.EEXIST,
                          "No usable temporary file name found")
853014
def popen(command, tempFile):
    
    fileHandle = open(tempFile, 'w')
    logger.debug("Running the command: %s" % command)
    sts = subprocess.call(command, shell=True, stdout=fileHandle, bufsize=-1)
    fileHandle.close()
    if sts != 0:
        raise RuntimeError("Command: %s exited with non-zero status %i" % (command, sts))
    return sts
1280299
def mktemp(self, container: Container) -> str:
        
        r = self.__api.post('containers/{}/tempfile'.format(container.uid))
        if r.status_code == 200:
            return r.json()
        self.__api.handle_erroneous_response(r)
993741
def EnsureTempDirIsSane(directory):
  """"""

  if not os.path.isabs(directory):
    raise ErrorBadPath("Directory %s is not absolute" % directory)

  if os.path.isdir(directory):
    # The temp dir already exists, we probably created it already but
    # let's check to make sure.
    if not client_utils.VerifyFileOwner(directory):
      # Just delete it, it's only temp dirs and we don't own it. If
      # this goes wrong we just raise.
      shutil.rmtree(directory)

  if not os.path.isdir(directory):
    os.makedirs(directory)

    # Make directory 700 before we write the file
    if sys.platform == "win32":
      from grr_response_client import client_utils_windows  # pylint: disable=g-import-not-at-top
      client_utils_windows.WinChmod(directory,
                                    ["FILE_GENERIC_READ", "FILE_GENERIC_WRITE"])
    else:
      os.chmod(directory, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)
497256
def membuf_tempfile(memfile):
    """"""
    memfile.seek(0, 0)

    tmpfd, tmpname = mkstemp(suffix='.rar')
    tmpf = os.fdopen(tmpfd, "wb")

    try:
        while True:
            buf = memfile.read(BSIZE)
            if not buf:
                break
            tmpf.write(buf)
        tmpf.close()
    except:
        tmpf.close()
        os.unlink(tmpname)
        raise
    return tmpname
617557
private static File createTempFile(Context ctx, String fileName) throws IOException {
        File storageDir = new File(ctx.getFilesDir(), "temp");
        storageDir.mkdir();
        return nonDuplicateFile(storageDir, fileName);
    }
997258
def getTempFile(suffix="", rootDir=None):
    
    if rootDir is None:
        handle, tmpFile = tempfile.mkstemp(suffix)
        os.close(handle)
        return tmpFile
    else:
        tmpFile = os.path.join(rootDir, "tmp_" + getRandomAlphaNumericString() + suffix)
        open(tmpFile, 'w').close()
        os.chmod(tmpFile, 0777) #Ensure everyone has access to the file.
        return tmpFile
54839
def _tempfilepager(generator, cmd, color):
    """"""
    import tempfile
    filename = tempfile.mktemp()
    # TODO: This never terminates if the passed generator never terminates.
    text = "".join(generator)
    if not color:
        text = strip_ansi(text)
    encoding = get_best_encoding(sys.stdout)
    with open_stream(filename, 'wb')[0] as f:
        f.write(text.encode(encoding))
    try:
        os.system(cmd + ' "' + filename + '"')
    finally:
        os.unlink(filename)
371712
def temporary_directory():
    
    dir_name = tempfile.mkdtemp()
    yield dir_name
    if os.path.exists(dir_name):
        shutil.rmtree(dir_name)
1352441
def _prepare_job(request, candidates):
    
    temp_dir = tempfile.mkdtemp()
    inifiles = []
    arch = request.FILES.get('archive')
    if arch is None:
        # move each file to a new temp dir, using the upload file names,
        # not the temporary ones
        for each_file in request.FILES.values():
            new_path = os.path.join(temp_dir, each_file.name)
            shutil.move(each_file.temporary_file_path(), new_path)
            if each_file.name in candidates:
                inifiles.append(new_path)
        return inifiles
    # else extract the files from the archive into temp_dir
    return readinput.extract_from_zip(arch, candidates)
1143851
def with_temp_dir(dir=nil)
      dir ||= Dir.mktmpdir(TEMP_PREFIX, @temp_root)
      dir = Pathname.new(dir)

      yield dir
    ensure
      FileUtils.rm_rf(dir.to_s)
    end