[dvsim] Use builtins wherever possible
This change gets rid of `os.system` calls, `grep`s and other things that
are better achieved by using python built-ins.
Apart from that, there are lint fixes and other very minor changes.
Signed-off-by: Srikrishna Iyer <sriyer@google.com>
diff --git a/util/dvsim/OneShotCfg.py b/util/dvsim/OneShotCfg.py
index 1612734..2dc3d5a 100644
--- a/util/dvsim/OneShotCfg.py
+++ b/util/dvsim/OneShotCfg.py
@@ -7,12 +7,12 @@
import logging as log
import os
-import sys
from collections import OrderedDict
from Deploy import CompileOneShot
from FlowCfg import FlowCfg
from Modes import BuildModes, Modes
+from utils import rm_path
class OneShotCfg(FlowCfg):
@@ -110,13 +110,9 @@
# Purge the output directories. This operates on self.
def _purge(self):
- if self.scratch_path:
- try:
- log.info("Purging scratch path %s", self.scratch_path)
- os.system("/bin/rm -rf " + self.scratch_path)
- except IOError:
- log.error('Failed to purge scratch directory %s',
- self.scratch_path)
+ assert self.scratch_path
+ log.info("Purging scratch path %s", self.scratch_path)
+ rm_path(self.scratch_path)
def _create_objects(self):
# Create build and run modes objects
@@ -142,21 +138,9 @@
def _create_dirs(self):
'''Create initial set of directories
'''
- # Invoking system calls has a performance penalty.
- # Construct a single command line chained with '&&' to invoke
- # the system call only once, rather than multiple times.
- create_link_dirs_cmd = ""
for link in self.links.keys():
- create_link_dirs_cmd += "/bin/rm -rf " + self.links[link] + " && "
- create_link_dirs_cmd += "mkdir -p " + self.links[link] + " && "
- create_link_dirs_cmd += " true"
-
- try:
- os.system(create_link_dirs_cmd)
- except IOError:
- log.error("Error running when running the cmd \"%s\"",
- create_link_dirs_cmd)
- sys.exit(1)
+ rm_path(self.links[link])
+ os.makedirs(self.links[link])
def _create_deploy_objects(self):
'''Create deploy objects from build modes