blob: 6970cb77e23aa3f8766e9478c72b2ce20e08fa7c [file] [log] [blame]
Ashlesh Gawande6c86e302019-09-17 22:27:05 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015-2019, The University of Memphis,
4# Arizona Board of Regents,
5# Regents of the University of California.
6#
7# This file is part of Mini-NDN.
8# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
9#
10# Mini-NDN is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# Mini-NDN is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with Mini-NDN, e.g., in COPYING.md file.
22# If not, see <http://www.gnu.org/licenses/>.
23
24from minindn.util import getPopen
25
26class Application(object):
27 def __init__(self, node):
28 self.node = node
29 self.process = None
30 self.logfile = None
31 self.homeDir = self.node.params['params']['homeDir']
32
33 # Make directory for log file
34 self.logDir = '{}/log'.format(self.homeDir)
35 self.node.cmd('mkdir -p {}'.format(self.logDir))
36
37 def start(self, command, logfile, envDict=None):
38 if self.process is None:
39 self.logfile = open('{}/{}'.format(self.logDir, logfile), 'w')
40 self.process = getPopen(self.node, command.split(), envDict,
41 stdout=self.logfile, stderr=self.logfile)
42
43 def stop(self):
44 if self.process is not None:
45 self.process.kill()
46 self.process = None
47 if self.logfile is not None:
48 self.logfile.close()