From a2a87833301e237bfa94bdad80c01190f6b4a04b Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 14 Mar 2016 18:23:49 +0100 Subject: [PATCH] miscell cleanup and prettyfication in collector and application --- nepi/resources/all/collector.py | 45 ++++++++++++++--------------- nepi/resources/linux/application.py | 9 +++--- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/nepi/resources/all/collector.py b/nepi/resources/all/collector.py index 4729e015..18bcf3ac 100644 --- a/nepi/resources/all/collector.py +++ b/nepi/resources/all/collector.py @@ -20,7 +20,6 @@ from nepi.execution.attribute import Attribute, Flags, Types from nepi.execution.trace import Trace, TraceAttr from nepi.execution.resource import ResourceManager, clsinit_copy, \ ResourceState, ResourceAction -from nepi.util.sshfuncs import ProcStatus import os import tempfile @@ -46,21 +45,18 @@ class Collector(ResourceManager): @classmethod def _register_attributes(cls): - trace_name = Attribute("traceName", - "Name of the trace to be collected", - flags = Flags.Design) - - sub_dir = Attribute("subDir", - "Sub directory to collect traces into", - flags = Flags.Design) - - rename = Attribute("rename", - "Name to give to the collected trace file", - flags = Flags.Design) - - cls._register_attribute(trace_name) - cls._register_attribute(sub_dir) - cls._register_attribute(rename) + cls._register_attribute( + Attribute("traceName", + "Name of the trace to be collected", + flags = Flags.Design)) + cls._register_attribute( + Attribute("subDir", + "Sub directory to collect traces into", + flags = Flags.Design)) + cls._register_attribute( + Attribute("rename", + "Name to give to the collected trace file", + flags = Flags.Design)) def __init__(self, ec, guid): super(Collector, self).__init__(ec, guid) @@ -85,8 +81,8 @@ class Collector(ResourceManager): if subdir: self._store_path = os.path.join(self.store_path, subdir) - msg = "Creating local directory at %s to store %s traces " % ( - self.store_path, trace_name) + msg = "Creating local directory at {} to store {} traces "\ + .format(self.store_path, trace_name) self.info(msg) try: @@ -106,24 +102,25 @@ class Collector(ResourceManager): trace_name = self.get("traceName") rename = self.get("rename") or trace_name - msg = "Collecting '%s' traces to local directory %s" % ( - trace_name, self.store_path) + msg = "Collecting '{}' traces to local directory {}"\ + .format(trace_name, self.store_path) self.info(msg) rms = self.get_connected() for rm in rms: - fpath = os.path.join(self.store_path, "%d.%s" % (rm.guid, - rename)) + fpath = os.path.join(self.store_path, "{}.{}"\ + .format(rm.guid, rename)) try: result = self.ec.trace(rm.guid, trace_name) + print("collector.do_release ..") with open(fpath, "w") as f: f.write(result) except: import traceback err = traceback.format_exc() - msg = "Couldn't retrieve trace %s for %d at %s " % (trace_name, - rm.guid, fpath) + msg = "Couldn't retrieve trace {} for {} at {} "\ + .format(trace_name, rm.guid, fpath) self.error(msg, out = "", err = err) continue diff --git a/nepi/resources/linux/application.py b/nepi/resources/linux/application.py index ba9bbc38..0a0ed05d 100644 --- a/nepi/resources/linux/application.py +++ b/nepi/resources/linux/application.py @@ -168,11 +168,10 @@ class LinuxApplication(ResourceManager): @classmethod def _register_traces(cls): - stdout = Trace("stdout", "Standard output stream", enabled = True) - stderr = Trace("stderr", "Standard error stream", enabled = True) - - cls._register_trace(stdout) - cls._register_trace(stderr) + cls._register_trace( + Trace("stdout", "Standard output stream", enabled = True)) + cls._register_trace( + Trace("stderr", "Standard error stream", enabled = True)) def __init__(self, ec, guid): super(LinuxApplication, self).__init__(ec, guid) -- 2.43.0