thermal: simplify running trace-cmd report on another directory
trace-cmd report allows you to give the full path to the trace file.
Use it instead of cding to the directory.
diff --git a/cr2/thermal.py b/cr2/thermal.py
index 96d0ae0..1a1751e 100644
--- a/cr2/thermal.py
+++ b/cr2/thermal.py
@@ -76,17 +76,9 @@
if not os.path.isfile(trace_fname):
raise IOError("No such file or directory: {}".format(trace_fname))
- previous_path = os.getcwd()
- os.chdir(self.basepath)
-
- # This would better be done with a context manager (i.e.
- # http://stackoverflow.com/a/13197763/970766)
- try:
- with open(os.devnull) as devnull:
- out = check_output(["trace-cmd", "report"], stderr=devnull)
-
- finally:
- os.chdir(previous_path)
+ with open(os.devnull) as devnull:
+ out = check_output(["trace-cmd", "report", trace_fname],
+ stderr=devnull)
with open(os.path.join(self.basepath, "trace.txt"), "w") as fout:
fout.write(out)