From 0d0cf9526943730a04d7c2a1b981a0e7f0183218 Mon Sep 17 00:00:00 2001 From: Jonathan Grizou Date: Sun, 7 Jul 2013 00:20:43 +0200 Subject: [PATCH] Adapt function in helpers.py to changes in ui. --- papers/commands/add_cmd.py | 2 +- papers/commands/attach_cmd.py | 2 +- papers/commands/edit_cmd.py | 2 +- papers/commands/export_cmd.py | 2 +- papers/commands/helpers.py | 11 +++++++---- papers/commands/import_cmd.py | 2 +- papers/commands/open_cmd.py | 2 +- papers/commands/remove_cmd.py | 2 +- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/papers/commands/add_cmd.py b/papers/commands/add_cmd.py index 1e27268..2cdeed8 100644 --- a/papers/commands/add_cmd.py +++ b/papers/commands/add_cmd.py @@ -55,7 +55,7 @@ def command(args): if tags is not None: p.tags = set(tags.split(',')) # Check if another doc file is specified in bibtex - docfile2 = extract_doc_path_from_bibdata(p, ui) + docfile2 = extract_doc_path_from_bibdata(p) if docfile is None: docfile = docfile2 elif docfile2 is not None: diff --git a/papers/commands/attach_cmd.py b/papers/commands/attach_cmd.py index 1d48ad3..3a4b00a 100644 --- a/papers/commands/attach_cmd.py +++ b/papers/commands/attach_cmd.py @@ -32,7 +32,7 @@ def command(args): if copy is None: copy = config().import_copy rp = repo.Repository(config()) - key = parse_reference(ui, rp, reference) + key = parse_reference(rp, reference) paper = rp.get_paper(key) try: add_docfile_to_paper(rp, paper, docfile=document, copy=copy) diff --git a/papers/commands/edit_cmd.py b/papers/commands/edit_cmd.py index 4bd59d4..2f8dcd3 100644 --- a/papers/commands/edit_cmd.py +++ b/papers/commands/edit_cmd.py @@ -22,7 +22,7 @@ def command(args): reference = args.reference rp = repo.Repository(config()) - key = parse_reference(ui, rp, reference) + key = parse_reference(rp, reference) paper = rp.get_paper(key) filepath = rp._metafile(key) if meta else rp._bibfile(key) diff --git a/papers/commands/export_cmd.py b/papers/commands/export_cmd.py index 0728f28..37e5d46 100644 --- a/papers/commands/export_cmd.py +++ b/papers/commands/export_cmd.py @@ -28,7 +28,7 @@ def command(args): rp = repo.Repository(config()) papers = [rp.get_paper(c) - for c in parse_references(ui, rp, references)] + for c in parse_references(rp, references)] if len(papers) == 0: papers = rp.all_papers() bib = BibliographyData() diff --git a/papers/commands/helpers.py b/papers/commands/helpers.py index c9df8a7..e915878 100644 --- a/papers/commands/helpers.py +++ b/papers/commands/helpers.py @@ -3,6 +3,7 @@ from .. import color from .. import pretty from ..repo import InvalidReference from ..paper import NoDocumentFile +from ..uis import get_ui() def add_references_argument(parser, single=False): @@ -28,29 +29,31 @@ def add_paper_with_docfile(repo, paper, docfile=None, copy=False): add_docfile_to_paper(repo, paper, docfile, copy=copy) -def extract_doc_path_from_bibdata(paper, ui): +def extract_doc_path_from_bibdata(paper): try: file_path = paper.get_document_file_from_bibdata(remove=True) if files.check_file(file_path): return file_path else: + ui = get_ui() ui.warning("File does not exist for %s (%s)." % (paper.citekey, file_path)) except NoDocumentFile: return None -def parse_reference(ui, rp, ref): +def parse_reference(rp, ref): try: return rp.ref2citekey(ref) except InvalidReference: + ui = get_ui() ui.error("no paper with reference: %s." % color.dye(ref, color.citekey)) ui.exit(-1) -def parse_references(ui, rp, refs): - citekeys = [parse_reference(ui, rp, ref) for ref in refs] +def parse_references(rp, refs): + citekeys = [parse_reference(rp, ref) for ref in refs] return citekeys def paper_oneliner(p, n = 0, citekey_only = False): diff --git a/papers/commands/import_cmd.py b/papers/commands/import_cmd.py index 1610c28..5f36471 100644 --- a/papers/commands/import_cmd.py +++ b/papers/commands/import_cmd.py @@ -31,7 +31,7 @@ def command(args): # Extract papers from bib papers = Paper.many_from_path(bibpath, fatal=False) for p in papers: - doc_file = extract_doc_path_from_bibdata(p, ui) + doc_file = extract_doc_path_from_bibdata(p) if doc_file is None: ui.warning("No file for %s." % p.citekey) add_paper_with_docfile(rp, p, docfile=doc_file, copy=copy) diff --git a/papers/commands/open_cmd.py b/papers/commands/open_cmd.py index ca989cf..670899e 100644 --- a/papers/commands/open_cmd.py +++ b/papers/commands/open_cmd.py @@ -24,7 +24,7 @@ def command(args): reference = args.reference rp = repo.Repository(config()) - key = parse_reference(ui, rp, reference) + key = parse_reference(rp, reference) paper = rp.get_paper(key) if with_command is None: with_command = config().open_cmd diff --git a/papers/commands/remove_cmd.py b/papers/commands/remove_cmd.py index abc2008..76e7e6e 100644 --- a/papers/commands/remove_cmd.py +++ b/papers/commands/remove_cmd.py @@ -20,7 +20,7 @@ def command(args): references = args.references rp = repo.Repository(config()) - citekeys = parse_references(ui, rp, references) + citekeys = parse_references(rp, references) if force is None: are_you_sure = ("Are you sure you want to delete paper(s) [%s]" " (this will also delete associated documents)?"