def runinplace(command, infile):
 if (not isinstance(command, list)):
  command = shlex.split(command)
 tmpdir = None
 if ('%2' in command):
  tmpdir = tempfile.mkdtemp(prefix='nikola')
  tmpfname = os.path.join(tmpdir, os.path.basename(infile))
 try:
  list_replace(command, '%1', infile)
  if tmpdir:
   list_replace(command, '%2', tmpfname)
  subprocess.check_call(command)
  if tmpdir:
   shutil.move(tmpfname, infile)
 finally:
  if tmpdir:
   shutil.rmtree(tmpdir)

def runinplace ( command , infile ) : if ( not isinstance ( command , list ) ) : command = shlex . split ( command ) tmpdir = None if ( '%2' in command ) : tmpdir = tempfile . mkdtemp ( prefix = 'nikola' ) tmpfname = os . path . join ( tmpdir , os . path . basename ( infile ) ) try : list_replace ( command , '%1' , infile ) if tmpdir : list_replace ( command , '%2' , tmpfname ) subprocess . check_call ( command ) if tmpdir : shutil . move ( tmpfname , infile ) finally : if tmpdir : shutil . rmtree ( tmpdir )
run a command in-place on a file .