|
16 | 16 |
|
17 | 17 | class StatRunner(object):
|
18 | 18 |
|
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 | + """ |
20 | 25 | self.script_path = script_path
|
21 | 26 | self.runstring = self.__determine_runner()
|
22 | 27 | self.runner = self.runstring[0]
|
23 | 28 | self.output_encoding = output_encoding
|
| 29 | + self.no_overwrite = no_overwrite |
24 | 30 |
|
25 | 31 | self.__setup()
|
26 | 32 |
|
@@ -62,6 +68,14 @@ def __ensure_data_dir_state(self):
|
62 | 68 |
|
63 | 69 | def __write_data_dump(self, runner, script_path, fname, dump):
|
64 | 70 | 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 | + |
65 | 79 | with open(data_fname, "w+") as data:
|
66 | 80 | data.write(dump)
|
67 | 81 |
|
@@ -92,10 +106,16 @@ def gather_stats(self, iters):
|
92 | 106 | "--encoding", "-e", required=False, type=str, default="utf-8",
|
93 | 107 | help="The expected encoding of the script output."
|
94 | 108 | )
|
| 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 | + ) |
95 | 113 | args = vars(parser.parse_args())
|
96 | 114 |
|
97 | 115 | limit = int(args["limit"])
|
98 | 116 | script_path = args["script-path"][0]
|
99 | 117 |
|
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 | + ) |
101 | 121 | runner.gather_stats(limit)
|
0 commit comments