From c02f5c3a88a9eaf2312aa90e5a02405043361129 Mon Sep 17 00:00:00 2001 From: awlane Date: Mon, 3 Feb 2025 09:46:19 -0600 Subject: [PATCH] Allow logfile parameter to be set to optional for Application object. Also fix a minor issue with traffic generator experiment imports not consistently working by relocating to NLSR subdirectory. Change-Id: Iad04ee0e3bb64a89133f45721c5d2c1e4c468dbf --- examples/{ => nlsr}/traffic_generator.py | 2 +- minindn/apps/application.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) rename examples/{ => nlsr}/traffic_generator.py (98%) diff --git a/examples/traffic_generator.py b/examples/nlsr/traffic_generator.py similarity index 98% rename from examples/traffic_generator.py rename to examples/nlsr/traffic_generator.py index d67e7e2..5b5620c 100644 --- a/examples/traffic_generator.py +++ b/examples/nlsr/traffic_generator.py @@ -39,7 +39,7 @@ from minindn.apps.nfd import Nfd from minindn.apps.nlsr import Nlsr from minindn.util import copyExistentFile -from examples.nlsr.nlsr_common import getParser +from nlsr_common import getParser def trafficServer(node, serverConfFile): """ diff --git a/minindn/apps/application.py b/minindn/apps/application.py index d7b0b87..aca153d 100644 --- a/minindn/apps/application.py +++ b/minindn/apps/application.py @@ -22,6 +22,7 @@ # If not, see . from minindn.util import getPopen +from typing import Union, Optional class Application(object): def __init__(self, node): @@ -34,11 +35,14 @@ def __init__(self, node): self.logDir = '{}/log'.format(self.homeDir) self.node.cmd('mkdir -p {}'.format(self.logDir)) - def start(self, command, logfile, envDict=None): + def start(self, command: Union[str, list], logfile: Optional[str]=None, envDict: Optional[dict]=None) -> None: if self.process is None: - self.logfile = open('{}/{}'.format(self.logDir, logfile), 'w') if isinstance(command, str): command = command.split() + if not logfile: + self.process = getPopen(self.node, command, envDict) + return + self.logfile = open('{}/{}'.format(self.logDir, logfile), 'w') self.process = getPopen(self.node, command, envDict, stdout=self.logfile, stderr=self.logfile)