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
|
||||
|
||||
def to_file(self, jobid):
|
||||
def to_file(self, jobid, header=""):
|
||||
"""Dumps power data to file. Returns filename is succesfull and None if unsucessfull."""
|
||||
fname = self.filename(jobid)
|
||||
if os.path.exists(fname):
|
||||
|
@ -79,7 +79,7 @@ class Power:
|
|||
|
||||
try:
|
||||
with open(fname, "w+") as f:
|
||||
f.write(self.header())
|
||||
f.write(header + self.header())
|
||||
f.write(self.body())
|
||||
except IOError:
|
||||
print("Error: could not write to file ", fname)
|
||||
|
@ -205,6 +205,7 @@ class App:
|
|||
self.db = MonitoringDB(self.config.verbose)
|
||||
|
||||
def run_all(self):
|
||||
header = f"# {config.datetime}: {config.cmd}\n#\n"
|
||||
for jobid in self.config.jobid:
|
||||
try:
|
||||
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))
|
||||
continue
|
||||
|
||||
fn = power.to_file(jobid)
|
||||
fn = power.to_file(jobid, header)
|
||||
if fn:
|
||||
print('Created file {fn}'.format(fn=fn))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
from datetime import datetime
|
||||
config = parse_arguments(sys.argv[1:])
|
||||
config.cmd = " ".join(sys.argv)
|
||||
config.datetime = f"{datetime.now()}"
|
||||
|
||||
main = App(config)
|
||||
main.run_all()
|
||||
|
|
Loading…
Reference in a new issue