Skip to content

Commit 2ffe714

Browse files
committed
Add no overwrite flag.
1 parent a5b5748 commit 2ffe714

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

python/stat_runner.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616

1717
class StatRunner(object):
1818

19-
def __init__(self, script_path, output_encoding="utf-8"):
19+
def __init__(self, script_path, output_encoding="utf-8", no_overwrite=False):
20+
"""
21+
Defaults:
22+
- we assume that script output is encoded as utf-8
23+
- if we encounter a data dump of the same name, we just overwrite it
24+
"""
2025
self.script_path = script_path
2126
self.runstring = self.__determine_runner()
2227
self.runner = self.runstring[0]
2328
self.output_encoding = output_encoding
29+
self.no_overwrite = no_overwrite
2430

2531
self.__setup()
2632

@@ -62,6 +68,14 @@ def __ensure_data_dir_state(self):
6268

6369
def __write_data_dump(self, runner, script_path, fname, dump):
6470
data_fname = os.path.join(self.__make_data_dir_path(), fname)
71+
72+
if os.path.isfile(data_fname) and self.no_overwrite:
73+
print(
74+
"Dump with filename %s exists and we are not set to overwrite." % data_fname,
75+
file=sys.stderr
76+
)
77+
return
78+
6579
with open(data_fname, "w+") as data:
6680
data.write(dump)
6781

@@ -92,10 +106,16 @@ def gather_stats(self, iters):
92106
"--encoding", "-e", required=False, type=str, default="utf-8",
93107
help="The expected encoding of the script output."
94108
)
109+
parser.add_argument(
110+
"--no-overwrite", action="store_true",
111+
help="If present, terminate if a data dump of the same name is present."
112+
)
95113
args = vars(parser.parse_args())
96114

97115
limit = int(args["limit"])
98116
script_path = args["script-path"][0]
99117

100-
runner = StatRunner(script_path, output_encoding=args["encoding"])
118+
runner = StatRunner(
119+
script_path, output_encoding=args["encoding"], no_overwrite=args["no_overwrite"]
120+
)
101121
runner.gather_stats(limit)

0 commit comments

Comments
 (0)