From 18dae114b357966ea815defe8b78759e375b3fee Mon Sep 17 00:00:00 2001 From: "Paul K. Korir, PhD" Date: Fri, 23 Mar 2018 16:37:42 +0000 Subject: [PATCH] Clear all - sff notes clear --all [@|file.sff] - tests for this - allow operations on multiple ids at once e.g. sff notes del -i 1,2,3,4 -D @ --- sfftk/core/parser.py | 9 +++++++++ sfftk/notes/modify.py | 3 --- sfftk/unittests/test_core.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sfftk/core/parser.py b/sfftk/core/parser.py index 2ed187c..5504aec 100644 --- a/sfftk/core/parser.py +++ b/sfftk/core/parser.py @@ -691,6 +691,12 @@ def add_args(parser, the_arg): add_args(clear_notes_parser, config_path) add_args(clear_notes_parser, shipped_configs) add_args(clear_notes_parser, sff_file) +clear_notes_parser.add_argument( + '--all', + action='store_true', + default=False, + help="clear all notes; USE WITH CARE!" +) clear_notes_parser.add_argument( '--from-global', action='store_true', @@ -1066,6 +1072,9 @@ def parse_args(_args): args.segment_id = [from_segment] else: args.segment_id = from_segment + elif args.all: + args.from_global = True + args.from_all_segments = True elif args.notes_subcommand == "merge": if args.output is None: diff --git a/sfftk/notes/modify.py b/sfftk/notes/modify.py index 1c94d80..52ac811 100644 --- a/sfftk/notes/modify.py +++ b/sfftk/notes/modify.py @@ -583,7 +583,6 @@ def add_note(args, configs): sff_seg.segment = note.add_to_segment(segment) print NoteView(sff_seg.segment, _long=True) found_segment = True - break if not found_segment: print_date("Segment of ID(s) {} not found".format(", ".join(map(str, args.segment_id)))) # export @@ -621,7 +620,6 @@ def edit_note(args, configs): sff_seg.segment = note.edit_in_segment(segment) print NoteView(sff_seg.segment, _long=True) found_segment = True - break if not found_segment: print_date("Segment of ID(s) {} not found".format(", ".join(map(str, args.segment_id)))) # export @@ -655,7 +653,6 @@ def del_note(args, configs): sff_seg.segment = note.del_from_segment(segment) print NoteView(sff_seg.segment, _long=True) found_segment = True - break if not found_segment: print_date("Segment of ID(s) {} not found".format(", ".join(map(str, args.segment_id)))) # export diff --git a/sfftk/unittests/test_core.py b/sfftk/unittests/test_core.py index 7e74f11..4ad50f5 100644 --- a/sfftk/unittests/test_core.py +++ b/sfftk/unittests/test_core.py @@ -739,6 +739,16 @@ def test_clear_global_only(self): args, _ = parse_args(shlex.split(cmd)) self.assertTrue(args.from_global) + def test_clear_all(self): + """Test that we can clear all notes""" + cmd = "notes clear --all --config-path {config_fn} file.sff".format( + config_fn=self.config_fn, + ) + args, _ = parse_args(shlex.split(cmd)) + self.assertTrue(args.all) + self.assertTrue(args.from_global) + self.assertTrue(args.from_all_segments) + # ========================================================================= # notes: save # =========================================================================