Permalink
Browse files

Make runinplace more flexible

* Quote the arguments, so filenames with spaces cause no breakage
* Detect if "%2" is actually used, if not, don't copy, but still
  benefit from check and substituion.
  • Loading branch information...
1 parent b02205b commit 1134f95c047f062cf7333626aeaf53211d9d7665 Kay Hayen committed with Sep 30, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 nikola/filters.py
View
@@ -47,10 +47,15 @@ def runinplace(command, infile):
tmpdir = tempfile.mkdtemp()
tmpfname = os.path.join(tmpdir, os.path.basename(infile))
- command = command.replace('%1', infile)
- command = command.replace('%2', tmpfname)
+ command = command.replace('%1', "'%s'" % infile)
+
+ needs_tmp = "%2" in command
+ command = command.replace('%2', "'%s'"% tmpfname)
+
subprocess.check_call(command, shell=True)
- shutil.move(tmpfname, infile)
+
+ if needs_tmp:
+ shutil.move(tmpfname, infile)
def yui_compressor(infile):

0 comments on commit 1134f95

Please sign in to comment.