Allow specification of working directory via constructor argument and related cleanup
Change-Id: Ifc73371c920d1d4e47b1fa04e57de5aebd2a6b40
diff --git a/examples/ping-demo.py b/examples/ping-demo.py
index 550c0df..5db8087 100644
--- a/examples/ping-demo.py
+++ b/examples/ping-demo.py
@@ -80,7 +80,7 @@
# Start ping server
info("Starting pings...\n")
- pingserver_log = open("/tmp/minindn/c/ndnpingserver.log", "w")
+ pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
stderr=pingserver_log)
diff --git a/examples/psync/full_sync.py b/examples/psync/full_sync.py
index d256a3b..d74a284 100644
--- a/examples/psync/full_sync.py
+++ b/examples/psync/full_sync.py
@@ -68,7 +68,7 @@
time.sleep(300)
totalUpdates = int(host.cmd('grep -r Update {}/*/psync.logs | wc -l'
- .format(args.workDir)))
+ .format(ndn.workDir)))
expectedUpdates = (maxUpdatesPerUserPrefixPerNode *
len(ndn.net.hosts) * (len(ndn.net.hosts) - 1) * numUserPrefixesPerNode)
diff --git a/examples/traffic_generator.py b/examples/traffic_generator.py
index 48bbd07..d67e7e2 100644
--- a/examples/traffic_generator.py
+++ b/examples/traffic_generator.py
@@ -25,7 +25,7 @@
"""
This example demonstrates the functionality of the Traffic generator. It consists of a traffic
server and client. The server will listen for interest on the prefix specified in the server
-configuration file. The client will send a designated number of interests to the server and
+configuration file. The client will send a designated number of interests to the server and
get the data back.
More details on traffic generator here: https://github.com/named-data/ndn-traffic-generator
"""
@@ -91,8 +91,8 @@
# lets make node "a" as a traffic-server node, and node "c" as a traffic-client node
server = ndn.net['a']
client = ndn.net['c']
- serverConf = '{}/{}/server-conf'.format(ndn.args.workDir, server.name)
- clientConf = '{}/{}/client-conf'.format(ndn.args.workDir, client.name)
+ serverConf = '{}/{}/server-conf'.format(ndn.workDir, server.name)
+ clientConf = '{}/{}/client-conf'.format(ndn.workDir, client.name)
copyExistentFile(server, possibleServerConfPath, serverConf)
copyExistentFile(server, possibleClientConfPath, clientConf)
diff --git a/minindn/minindn.py b/minindn/minindn.py
index c710d52..10dbcb4 100644
--- a/minindn/minindn.py
+++ b/minindn/minindn.py
@@ -55,7 +55,7 @@
resultDir = None
def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, noTopo=False,
- link=TCLink, **mininetParams):
+ link=TCLink, workDir=None, **mininetParams):
"""
Create MiniNDN object
:param parser: Parent parser of Mini-NDN parser
@@ -70,7 +70,11 @@
self.parser = Minindn.parseArgs(parser)
self.args = self.parser.parse_args()
- Minindn.workDir = os.path.abspath(self.args.workDir)
+ if not workDir:
+ Minindn.workDir = os.path.abspath(self.args.workDir)
+ else:
+ Minindn.workDir = os.path.abspath(workDir)
+
Minindn.resultDir = self.args.resultDir
if not topoFile:
diff --git a/minindn/wifi/minindnwifi.py b/minindn/wifi/minindnwifi.py
index c403fc4..54b4aad 100644
--- a/minindn/wifi/minindnwifi.py
+++ b/minindn/wifi/minindnwifi.py
@@ -21,6 +21,7 @@
# along with Mini-NDN, e.g., in COPYING.md file.
# If not, see <http://www.gnu.org/licenses/>.
+import os
import argparse
import sys
import configparser
@@ -36,7 +37,7 @@
class MinindnWifi(Minindn):
""" Class for handling default args, Mininet-wifi object and home directories """
- def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, noTopo=False, link=WirelessLink, **mininetParams):
+ def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, noTopo=False, link=WirelessLink, workDir=None, **mininetParams):
"""Create Mini-NDN-Wifi object
parser: Parent parser of Mini-NDN-Wifi parser (use to specify experiment arguments)
topo: Mininet topo object (optional)
@@ -48,7 +49,11 @@
self.parser = self.parseArgs(parser)
self.args = self.parser.parse_args()
- Minindn.workDir = self.args.workDir
+ if not workDir:
+ Minindn.workDir = os.path.abspath(self.args.workDir)
+ else:
+ Minindn.workDir = os.path.abspath(workDir)
+
Minindn.resultDir = self.args.resultDir
self.topoFile = None