Skip to content

Commit 073a356

Browse files
committed
Requests from the PR
Rename of key of slicer profile data; Introduction and use of PushCwd class.
1 parent 78bddb7 commit 073a356

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

security-scanner/analyser.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import time
33
import json
4-
import shutil
4+
import utility
55

66

77
def __get_my_dir(): return os.path.dirname(os.path.realpath(__file__))
@@ -109,7 +109,7 @@ def run_program_slicing(
109109
timeout,
110110
verbosity
111111
):
112-
prof = { "calling_goto_instrument": [] }
112+
prof = {"calling_slicer": []}
113113
prof_start_time = time.time()
114114

115115
with open(json_cfg_fname) as data_file:
@@ -121,8 +121,6 @@ def run_program_slicing(
121121
src_idx_name = int(src_plain_fname[src_plain_fname.rfind("_")+1:])
122122
dst_goto_program_fname = os.path.join(results_dir, "sliced_goto_program_" + str(src_idx_name) + ".gbf")
123123

124-
old_cwd = os.getcwd()
125-
os.chdir(results_dir)
126124
command = (
127125
get_goto_instrument_pathname() + " " +
128126
"--full-slice " +
@@ -132,16 +130,16 @@ def run_program_slicing(
132130
)
133131
prof_calling_goto_instrument_start_time = time.time()
134132
print("Invoking 'goto-instrument' ...")
135-
if verbosity >= 9:
136-
print("CWD: " + results_dir)
137-
print("CMD: " + command)
138-
# TODO: Uncomment the next line when the slicer is functional!
139-
# os.system(command)
140-
prof["calling_goto_instrument"].append({
133+
with utility.PushCwd(results_dir) as cwd:
134+
if verbosity >= 9:
135+
print("CWD: " + cwd.get())
136+
print("CMD: " + command)
137+
# TODO: Uncomment the next line when the slicer is functional!
138+
# os.system(command)
139+
prof["calling_slicer"].append({
141140
"gbf_idx": src_idx_name,
142141
"duration": time.time() - prof_calling_goto_instrument_start_time
143142
})
144-
os.chdir(old_cwd)
145143

146144
result.append(cfg.copy())
147145
# TODO: Uncomment the next line when the slicer is functional!

security-scanner/utility.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
4+
class PushCwd:
5+
def __init__(self, dirname):
6+
self._cwd = os.path.realpath(dirname)
7+
self._old_cwd = None
8+
9+
def __enter__(self):
10+
os.chdir(self._cwd)
11+
self._old_cwd = os.getcwd()
12+
return self
13+
14+
def __exit__(self, _, __, ___):
15+
if self._old_cwd is not None:
16+
os.chdir(self._old_cwd)
17+
18+
def get(self):
19+
return self._cwd

0 commit comments

Comments
 (0)