Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
 Copied from Paperclip
341264
def make_tmpname(basename, n)
      extension = File.extname(basename)
      sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n.to_i, extension)
    end
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
375598
def tempfile_path(content)
      tempfile = Tempfile.new('tty-editor')
      tempfile << content
      tempfile.flush
      unless tempfile.nil?
        tempfile.close
      end
      tempfile.path
    end
121974
function(callback) {
          if (!context.copyOriginal) {
            return callback(null);
          }
          var suffix = 'original.' + context.extension;
          var tempFile = context.tempFolder + '/' + suffix;
          if (context.extension !== 'jpg') {
            // Don't forget to tell the caller that we did the work,
            // even if it was just a copy
            context.adjustedOriginal = tempFile;
            return copyFile(context.workingPath, tempFile, callback);
          }

          var args = [ context.workingPath ];
          if (context.crop) {
            args.push('-crop');
            args.push(context.crop.left);
            args.push(context.crop.top);
            args.push(context.crop.width);
            args.push(context.crop.height);
          }
          args.push('-write');
          args.push(tempFile);
          context.adjustedOriginal = tempFile;

          var proc = childProcess.spawn('imagecrunch', args);
          proc.on('close', function(code) {
            if (code !== 0) {
              return callback(code);
            }
            return callback(null);
          });
        }
1291887
private File createTempFilename(File permanentFile, File journalDirectory) {
        String tempFilename = "_" + permanentFile.getName();
        File file2 = new File(journalDirectory, tempFilename);
        return file2;
    }
532312
def replace_ext(filename, new_ext):
    """"""
    filename_base = os.path.splitext(filename)[0]
    new_filename = '{}.{}'.format(filename_base, new_ext)
    return new_filename
287980
def file(suffix='', prefix='tmp', parent=None):
    '''
    
    '''
    fh_, tmp_ = tempfile.mkstemp(suffix, prefix, parent)
    os.close(fh_)
    return tmp_
1229358
def strToTempfile(s, suffix=None, prefix=None, dir=None, binary=False):
    
    fd, filename = tempfile.mkstemp(**dict((k,v) for (k,v) in
                                           [('suffix',suffix),('prefix',prefix),('dir', dir)]
                                           if v is not None))
    spitOut(s, fd, binary)
    return filename
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)
597396
private static void renameTmpFile(FileSystem hdfs, String targetTmpPath, String tmpSuffix)
    {
        String basePath = extractBasePath(targetTmpPath, tmpSuffix);

        boolean isFileExists = true;

        try
        {
            isFileExists = hdfs.exists(new Path(basePath));
        }
        catch (IOException ioex)
        {
            String logFormat = "Failed to search target file exists. Skip file rename. : TargetUri={0}";
            String logMessage = MessageFormat.format(logFormat, basePath);
            logger.warn(logMessage, ioex);
            return;
        }

        if (isFileExists)
        {
            String logFormat = "File exists renamed target. Skip file rename. : BeforeUri={0} , AfterUri={1}";
            String logMessage = MessageFormat.format(logFormat, targetTmpPath, basePath);
            logger.warn(logMessage);
        }
        else
        {
            try
            {
                hdfs.rename(new Path(targetTmpPath), new Path(basePath));
            }
            catch (IOException ioex)
            {
                String logFormat = "Failed to HDFS file rename. Skip rename file and continue preprocess. : BeforeUri={0} , AfterUri={1}";
                String logMessage = MessageFormat.format(logFormat, targetTmpPath, basePath);
                logger.warn(logMessage, ioex);
            }
        }
    }
576472
def replace_ext(filename, ext):
    
    if ext.startswith('.'):
        ext = ext[1:]
    stem, _ = os.path.splitext(filename)
    return (stem + '.' + ext)
981425
function makeTempFile() {
    const n = Math.floor(Math.random() * 100000)
    const tempFile = path.join(os.tmpdir(), `node-exiftool_test_${n}.jpg`)
    return new Promise((resolve, reject) => {
        const rs = fs.createReadStream(jpegFile)
        const ws = fs.createWriteStream(tempFile)
        rs.on('error', reject)
        ws.on('error', reject)
        ws.on('close', () => {
            resolve(tempFile)
        })
        rs.pipe(ws)
    })
}
1018794
def _temporary_filenames(total):
    """"""
    temp_files = [_get_temporary_filename('optimage-') for i in range(total)]
    yield temp_files
    for temp_file in temp_files:
        try:
            os.remove(temp_file)
        except OSError:
            # Continue in case we could not remove the file. One reason is that
            # the fail was never created.
            pass
281607
def _CreateTempDir(prefix, run_dir=None):
  
  temp_dir = tempfile.mkdtemp(prefix=prefix + '-', dir=run_dir)
  try:
    yield temp_dir
  finally:
    shutil.rmtree(temp_dir)
206158
def filenameToModname(self, filename):
        """"""
        for ext in reversed(self._exts):
            if filename.endswith(ext):
                filename = filename[:-len(ext)]
                break
        else:
            self.warn(filename, '%s: unknown file name extension', filename)
        filename = os.path.abspath(filename)
        elements = filename.split(os.path.sep)
        modname = []
        while elements:
            modname.append(elements[-1])
            del elements[-1]
            if not os.path.exists(os.path.sep.join(elements + ['__init__.py'])):
                break
        modname.reverse()
        modname = ".".join(modname)
        return modname
432840
function copyToTemp () {
    fs.readFile(inPath, function (err, inFile) {
      if (err) return cb(err)
      var tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now())
      fs.mkdir(tmpPath, function (err) {
        if (err) return cb(err)
        fs.writeFile(path.join(tmpPath, path.basename(inPath)), inFile, function (err) {
          if (err) return cb(err)
          inPath = tmpPath
          doZip()
        })
      })
    })
  }
1141890
def replace_in_file(self, file_path, old_exp, new_exp):
        
        self.term.print_info(u"Making replacement into {}"
                                 .format(self.term.text_in_color(file_path,
                                                                 TERM_GREEN)))
        # write the new version into a temporary file
        tmp_file = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
        for filelineno, line in enumerate(io.open(file_path, encoding="utf-8")):
            if old_exp in line:
                line = line.replace(old_exp, new_exp)
            try:
                tmp_file.write(line.encode('utf-8'))
            except TypeError:
                tmp_file.write(line)

        name = tmp_file.name # keep the name
        tmp_file.close()
        shutil.copy(name, file_path) # replace the original one
        os.remove(name)