Adapt function in helpers.py to changes in ui.

This commit is contained in:
Jonathan Grizou 2013-07-07 00:20:43 +02:00
parent da6d2d21d5
commit 0d0cf95269
8 changed files with 14 additions and 11 deletions

View File

@ -55,7 +55,7 @@ def command(args):
if tags is not None: if tags is not None:
p.tags = set(tags.split(',')) p.tags = set(tags.split(','))
# Check if another doc file is specified in bibtex # 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: if docfile is None:
docfile = docfile2 docfile = docfile2
elif docfile2 is not None: elif docfile2 is not None:

View File

@ -32,7 +32,7 @@ def command(args):
if copy is None: if copy is None:
copy = config().import_copy copy = config().import_copy
rp = repo.Repository(config()) rp = repo.Repository(config())
key = parse_reference(ui, rp, reference) key = parse_reference(rp, reference)
paper = rp.get_paper(key) paper = rp.get_paper(key)
try: try:
add_docfile_to_paper(rp, paper, docfile=document, copy=copy) add_docfile_to_paper(rp, paper, docfile=document, copy=copy)

View File

@ -22,7 +22,7 @@ def command(args):
reference = args.reference reference = args.reference
rp = repo.Repository(config()) rp = repo.Repository(config())
key = parse_reference(ui, rp, reference) key = parse_reference(rp, reference)
paper = rp.get_paper(key) paper = rp.get_paper(key)
filepath = rp._metafile(key) if meta else rp._bibfile(key) filepath = rp._metafile(key) if meta else rp._bibfile(key)

View File

@ -28,7 +28,7 @@ def command(args):
rp = repo.Repository(config()) rp = repo.Repository(config())
papers = [rp.get_paper(c) papers = [rp.get_paper(c)
for c in parse_references(ui, rp, references)] for c in parse_references(rp, references)]
if len(papers) == 0: if len(papers) == 0:
papers = rp.all_papers() papers = rp.all_papers()
bib = BibliographyData() bib = BibliographyData()

View File

@ -3,6 +3,7 @@ from .. import color
from .. import pretty from .. import pretty
from ..repo import InvalidReference from ..repo import InvalidReference
from ..paper import NoDocumentFile from ..paper import NoDocumentFile
from ..uis import get_ui()
def add_references_argument(parser, single=False): 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) 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: try:
file_path = paper.get_document_file_from_bibdata(remove=True) file_path = paper.get_document_file_from_bibdata(remove=True)
if files.check_file(file_path): if files.check_file(file_path):
return file_path return file_path
else: else:
ui = get_ui()
ui.warning("File does not exist for %s (%s)." ui.warning("File does not exist for %s (%s)."
% (paper.citekey, file_path)) % (paper.citekey, file_path))
except NoDocumentFile: except NoDocumentFile:
return None return None
def parse_reference(ui, rp, ref): def parse_reference(rp, ref):
try: try:
return rp.ref2citekey(ref) return rp.ref2citekey(ref)
except InvalidReference: except InvalidReference:
ui = get_ui()
ui.error("no paper with reference: %s." ui.error("no paper with reference: %s."
% color.dye(ref, color.citekey)) % color.dye(ref, color.citekey))
ui.exit(-1) ui.exit(-1)
def parse_references(ui, rp, refs): def parse_references(rp, refs):
citekeys = [parse_reference(ui, rp, ref) for ref in refs] citekeys = [parse_reference(rp, ref) for ref in refs]
return citekeys return citekeys
def paper_oneliner(p, n = 0, citekey_only = False): def paper_oneliner(p, n = 0, citekey_only = False):

View File

@ -31,7 +31,7 @@ def command(args):
# Extract papers from bib # Extract papers from bib
papers = Paper.many_from_path(bibpath, fatal=False) papers = Paper.many_from_path(bibpath, fatal=False)
for p in papers: 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: if doc_file is None:
ui.warning("No file for %s." % p.citekey) ui.warning("No file for %s." % p.citekey)
add_paper_with_docfile(rp, p, docfile=doc_file, copy=copy) add_paper_with_docfile(rp, p, docfile=doc_file, copy=copy)

View File

@ -24,7 +24,7 @@ def command(args):
reference = args.reference reference = args.reference
rp = repo.Repository(config()) rp = repo.Repository(config())
key = parse_reference(ui, rp, reference) key = parse_reference(rp, reference)
paper = rp.get_paper(key) paper = rp.get_paper(key)
if with_command is None: if with_command is None:
with_command = config().open_cmd with_command = config().open_cmd

View File

@ -20,7 +20,7 @@ def command(args):
references = args.references references = args.references
rp = repo.Repository(config()) rp = repo.Repository(config())
citekeys = parse_references(ui, rp, references) citekeys = parse_references(rp, references)
if force is None: if force is None:
are_you_sure = ("Are you sure you want to delete paper(s) [%s]" are_you_sure = ("Are you sure you want to delete paper(s) [%s]"
" (this will also delete associated documents)?" " (this will also delete associated documents)?"