Skip to content

Commit

Permalink
Merge pull request #196 from jwhitlock/cleanup-temp
Browse files Browse the repository at this point in the history
Cleanup temporary files from fast diff
  • Loading branch information
jwhitlock authored Nov 4, 2021
2 parents 35b37b3 + 3173fa1 commit d9879ab
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions tcadmin/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import click
import blessings
import attr
import tempfile
import subprocess
from tempfile import NamedTemporaryFile

from .util.ansi import strip_ansi
from .resources import Resources
Expand All @@ -19,25 +19,24 @@


def fast_diff(left, right, n):
left_file = tempfile.NamedTemporaryFile("w")
left_file.write("\n".join(left))
right_file = tempfile.NamedTemporaryFile("w")
right_file.write("\n".join(right))
output = subprocess.run(
[
"diff",
f"-U{n}",
"--label",
"current",
"--label",
"generated",
left_file.name,
right_file.name,
],
encoding="utf8",
stdout=subprocess.PIPE,
).stdout
return output.split("\n")
with NamedTemporaryFile("w") as left_file, NamedTemporaryFile("w") as right_file:
left_file.write("\n".join(left))
right_file.write("\n".join(right))
output = subprocess.run(
[
"diff",
f"-U{n}",
"--label",
"current",
"--label",
"generated",
left_file.name,
right_file.name,
],
encoding="utf8",
stdout=subprocess.PIPE,
).stdout
return output.split("\n")


diff_options.add(
Expand Down

0 comments on commit d9879ab

Please sign in to comment.