Skip to content

Commit

Permalink
Avoid printing incomplete Gcode: write to tmp file first, then rename…
Browse files Browse the repository at this point in the history
… atomically.
  • Loading branch information
jcrocholl committed Nov 29, 2014
1 parent 74e0860 commit 9a0739d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clean_gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def rewrite(infile, outfile, verbose=False):
if len(sys.argv) < 2:
sys.exit('usage: clean_gcode.py <filename> [--verbose]')
infilename = sys.argv[1]
tmpfilename = '%s.tmp%s' % os.path.splitext(infilename)
with open(infilename, 'r') as infile:
with open(tmpfilename, 'w') as tmpfile:
rewrite(infile, tmpfile, '--verbose' in sys.argv)
outfilename = '%s.clean%s' % os.path.splitext(infilename)
with open(infilename) as infile:
with open(outfilename, 'w') as outfile:
rewrite(infile, outfile, '--verbose' in sys.argv)
os.rename(tmpfilename, outfilename)

0 comments on commit 9a0739d

Please sign in to comment.