Log command line in output files
This commit is contained in:
parent
e73f69f25e
commit
c7c4460196
1 changed files with 7 additions and 3 deletions
|
@ -70,7 +70,7 @@ class Power:
|
||||||
|
|
||||||
return power
|
return power
|
||||||
|
|
||||||
def to_file(self, jobid):
|
def to_file(self, jobid, header=""):
|
||||||
"""Dumps power data to file. Returns filename is succesfull and None if unsucessfull."""
|
"""Dumps power data to file. Returns filename is succesfull and None if unsucessfull."""
|
||||||
fname = self.filename(jobid)
|
fname = self.filename(jobid)
|
||||||
if os.path.exists(fname):
|
if os.path.exists(fname):
|
||||||
|
@ -79,7 +79,7 @@ class Power:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(fname, "w+") as f:
|
with open(fname, "w+") as f:
|
||||||
f.write(self.header())
|
f.write(header + self.header())
|
||||||
f.write(self.body())
|
f.write(self.body())
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Error: could not write to file ", fname)
|
print("Error: could not write to file ", fname)
|
||||||
|
@ -205,6 +205,7 @@ class App:
|
||||||
self.db = MonitoringDB(self.config.verbose)
|
self.db = MonitoringDB(self.config.verbose)
|
||||||
|
|
||||||
def run_all(self):
|
def run_all(self):
|
||||||
|
header = f"# {config.datetime}: {config.cmd}\n#\n"
|
||||||
for jobid in self.config.jobid:
|
for jobid in self.config.jobid:
|
||||||
try:
|
try:
|
||||||
power = Power.from_db(self.db, jobid, self.config.interval)
|
power = Power.from_db(self.db, jobid, self.config.interval)
|
||||||
|
@ -212,14 +213,17 @@ class App:
|
||||||
print('No data found for job ID "{}"'.format(jobid))
|
print('No data found for job ID "{}"'.format(jobid))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fn = power.to_file(jobid)
|
fn = power.to_file(jobid, header)
|
||||||
if fn:
|
if fn:
|
||||||
print('Created file {fn}'.format(fn=fn))
|
print('Created file {fn}'.format(fn=fn))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
config = parse_arguments(sys.argv[1:])
|
config = parse_arguments(sys.argv[1:])
|
||||||
|
config.cmd = " ".join(sys.argv)
|
||||||
|
config.datetime = f"{datetime.now()}"
|
||||||
|
|
||||||
main = App(config)
|
main = App(config)
|
||||||
main.run_all()
|
main.run_all()
|
||||||
|
|
Loading…
Reference in a new issue