def run_prompt(self): self.run(False) self.debug.print_debug(self, u'Entering interactive mode') prompt = Interactive(self.gv) manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath('//back/ref-list/ref') # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False for p in tree.xpath('//xref[@ref-type="bibr"]'): text = manipulate.get_stripped_text(p) prompt.print_(prompt.colorize('green', ("-" * 80))) if 'rid' in p.attrib and p.attrib['rid'] == 'TO_LINK': prompt.print_( u"Found an unhandled reference marker: {0}".format(text)) elif 'rid' in p.attrib: remote = next((x for x in ref_items if 'id' in x.attrib and ( x.attrib['id'] == p.attrib['rid'])), None) remote_text = manipulate.get_stripped_text( remote) if remote else '' prompt.print_( u"Found a handled reference marker: \"{0}\" which links to \"{1}\"" .format(text, remote_text)) opts = ('Skip', 'Delete', 'deleTe all', 'Enter search', 'Ibid', 'enter Link id', 'skip Rest', 'show Context') sel = '' if delete_all: sel = 'd' else: sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, ref_items, sel, tree=tree) if result == 'abort': manipulate.save_tree(tree) return elif result == 'delall': delete_all = True manipulate.save_tree(tree)
def run_prompt(self): self.run(False) self.debug.print_debug(self, u'Entering interactive mode') prompt = Interactive(self.gv) manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath('//back/ref-list/ref') # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False for p in tree.xpath('//xref[@ref-type="bibr"]'): text = manipulate.get_stripped_text(p) prompt.print_(prompt.colorize('green',("-" * 80))) if 'rid' in p.attrib and p.attrib['rid'] == 'TO_LINK': prompt.print_(u"Found an unhandled reference marker: {0}".format(text)) elif 'rid' in p.attrib: remote = next((x for x in ref_items if 'id' in x.attrib and (x.attrib['id'] == p.attrib['rid'])), None) remote_text = manipulate.get_stripped_text(remote) prompt.print_(u"Found a handled reference marker: \"{0}\" which links to \"{1}\"".format(text, remote_text)) opts = ('Skip', 'Delete', 'deleTe all', 'Enter search', 'Ibid', 'enter Link id', 'skip Rest', 'show Context') sel = '' if delete_all: sel = 'd' else: sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, ref_items, sel, tree=tree) if result == 'abort': manipulate.save_tree(tree) return elif result == 'delall': delete_all = True manipulate.save_tree(tree)