def invoke(self, args, note_q_get): """ If neither sorting, nor the notes are requested, this method hands off the work to ``invoke_on_note``. All other cases are handled within this method. """ # we cover the easiest "default" approach with this guard clause: if not args.notes and not args.sort: self._printed_tags = set() super(TagsSubCommand, self).invoke(args, note_q_get) return # collect all tags and if required all corresponding notes tags_and_notes = {} for note in set(iter(note_q_get, QUEUE_END_SYMBOL)): for tag in note.tags: notes = tags_and_notes.setdefault(tag, set()) if args.notes: notes.add(note) # sort the tags if need be tags = tags_and_notes.keys() if args.sort: tags.sort(key=lambda s: s.lower()) # output for tag in tags: print_colored_2("#%s\n" % tag) if args.notes: for note in tags_and_notes[tag]: print_default("\t%s\n" % note)
def handle_args(self): """ This kicks off the actual operation (i.e. use the users' args, options and sub commands to server the request). """ self._parse_args() args = self.args Note.set_args(args) notes_q = Queue(False) find_process = Process(target=self._find_notes, args=(args.query, notes_q.put)) find_process.start() sub_command = self.sub_commands[args.subcommand] logging.debug("running sub command: '%s'", sub_command.__class__.__name__) try: sub_command.invoke(args, notes_q.get) except KeyboardInterrupt: find_process.terminate() print_default("\n") finally: find_process.join()
def invoke_on_note(self, args, note): self.listed_paths.append(note.abspath) print_colored("%u " % len(self.listed_paths), True) pathname, filename = path_split(note.path) print_default("%s%s" % (pathname, pathsep)) print_highlighted("%s%s" % (filename, linesep)) if args.tags: tags = note.tags if tags: print_default("\n") for tag in tags: print_colored_2("\t#%s\n" % tag) print_default("\n")