|
|
|
@ -4,6 +4,7 @@ from .helpers import add_paper_with_docfile, extract_doc_path_from_bibdata
|
|
|
|
|
from ..configs import config
|
|
|
|
|
from ..uis import get_ui
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parser(subparsers):
|
|
|
|
|
parser = subparsers.add_parser('import',
|
|
|
|
|
help='import paper(s) to the repository')
|
|
|
|
@ -13,6 +14,8 @@ def parser(subparsers):
|
|
|
|
|
help="copy document files into library directory (default)")
|
|
|
|
|
parser.add_argument('-C', '--nocopy', action='store_false', dest='copy',
|
|
|
|
|
help="don't copy document files (opposite of -c)")
|
|
|
|
|
parser.add_argument('keys', nargs='*',
|
|
|
|
|
help="one or several keys to import from the file")
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -29,9 +32,17 @@ def command(args):
|
|
|
|
|
copy = config().import_copy
|
|
|
|
|
rp = repo.Repository(config())
|
|
|
|
|
# Extract papers from bib
|
|
|
|
|
papers = Paper.many_from_path(bibpath, fatal=False)
|
|
|
|
|
for p in papers:
|
|
|
|
|
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)
|
|
|
|
|
papers = Paper.many_from_path(bibpath)
|
|
|
|
|
keys = args.keys or papers.keys()
|
|
|
|
|
for k in keys:
|
|
|
|
|
try:
|
|
|
|
|
p = papers[k]
|
|
|
|
|
if isinstance(p, Exception):
|
|
|
|
|
ui.error('Could not load entry for citekey {}.'.format(k))
|
|
|
|
|
else:
|
|
|
|
|
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)
|
|
|
|
|
except KeyError:
|
|
|
|
|
ui.error('No entry found for citekey {}.'.format(k))
|
|
|
|
|