diff options
author | Douglas Bagnall <douglas.bagnall@catalyst.net.nz> | 2018-10-19 16:39:36 +1300 |
---|---|---|
committer | Douglas Bagnall <dbagnall@samba.org> | 2019-01-08 23:55:32 +0100 |
commit | d1a1c5d60113727fad1208c91060f4d318dea412 (patch) | |
tree | 2f940fd740a8beaa230335309d385bfb1d026776 /script | |
parent | b275baebd7e7fa8576cb49737a886f02e3615640 (diff) | |
download | samba-d1a1c5d60113727fad1208c91060f4d318dea412.tar.gz |
traffic learner: avoid truncated output files on error
add_argument(type=argparse.FileType('w'), ...) will open the file
and leave it empty if the script fails.
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'script')
-rwxr-xr-x | script/traffic_learner | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/script/traffic_learner b/script/traffic_learner index b46521f70cd..cad1a64a133 100755 --- a/script/traffic_learner +++ b/script/traffic_learner @@ -31,7 +31,7 @@ info = logger.info def main(): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument('-o', '--out', type=argparse.FileType('w'), + parser.add_argument('-o', '--out', help="write model here") parser.add_argument('--dns-mode', choices=['inline', 'count'], help='how to deal with DNS', default='count') @@ -45,6 +45,13 @@ def main(): error("Please specify a filename using the --out option.") return 1 + try: + outfile = open(args.out, 'w') + except IOError as e: + error("could not open %s" % args.out) + error(e) + return 1 + if args.SUMMARY_FILE is sys.stdin: info("reading from STDIN...") |