|
|
@ -26,8 +26,10 @@ def parser(subparsers, conf):
|
|
|
|
parser = subparsers.add_parser('add', help='add a paper to the repository')
|
|
|
|
parser = subparsers.add_parser('add', help='add a paper to the repository')
|
|
|
|
parser.add_argument('bibfile', nargs='?', default=None,
|
|
|
|
parser.add_argument('bibfile', nargs='?', default=None,
|
|
|
|
help='bibtex file')
|
|
|
|
help='bibtex file')
|
|
|
|
parser.add_argument('-D', '--doi', help='doi number to retrieve the bibtex entry, if it is not provided', default=None, action=ValidateDOI)
|
|
|
|
id_arg = parser.add_mutually_exclusive_group()
|
|
|
|
parser.add_argument('-I', '--isbn', help='isbn number to retrieve the bibtex entry, if it is not provided', default=None)
|
|
|
|
id_arg.add_argument('-D', '--doi', help='doi number to retrieve the bibtex entry, if it is not provided', default=None, action=ValidateDOI)
|
|
|
|
|
|
|
|
id_arg.add_argument('-I', '--isbn', help='isbn number to retrieve the bibtex entry, if it is not provided', default=None)
|
|
|
|
|
|
|
|
id_arg.add_argument('-X', '--arxiv', help='arXiv ID to retrieve the bibtex entry, if it is not provided', default=None)
|
|
|
|
parser.add_argument('-d', '--docfile', help='pdf or ps file', default=None)
|
|
|
|
parser.add_argument('-d', '--docfile', help='pdf or ps file', default=None)
|
|
|
|
parser.add_argument('-t', '--tags', help='tags associated to the paper, separated by commas',
|
|
|
|
parser.add_argument('-t', '--tags', help='tags associated to the paper, separated by commas',
|
|
|
|
default=None
|
|
|
|
default=None
|
|
|
@ -85,24 +87,22 @@ def command(conf, args):
|
|
|
|
|
|
|
|
|
|
|
|
# get bibtex entry
|
|
|
|
# get bibtex entry
|
|
|
|
if bibfile is None:
|
|
|
|
if bibfile is None:
|
|
|
|
if args.doi is None and args.isbn is None:
|
|
|
|
if args.doi is None and args.isbn is None and args.arxiv is None:
|
|
|
|
bibentry = bibentry_from_editor(conf, ui, rp)
|
|
|
|
bibentry = bibentry_from_editor(conf, ui, rp)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if args.doi is not None:
|
|
|
|
bibentry = None
|
|
|
|
bibentry_raw = apis.doi2bibtex(args.doi)
|
|
|
|
try:
|
|
|
|
bibentry = rp.databroker.verify(bibentry_raw)
|
|
|
|
if args.doi is not None:
|
|
|
|
if bibentry is None:
|
|
|
|
bibentry = apis.get_bibentry_from_api(args.doi, 'doi', rp)
|
|
|
|
ui.error('invalid doi {} or unable to retrieve bibfile from it.'.format(args.doi))
|
|
|
|
elif args.isbn is not None:
|
|
|
|
if args.isbn is None:
|
|
|
|
bibentry = apis.get_bibentry_from_api(args.isbn, 'isbn', rp)
|
|
|
|
ui.exit(1)
|
|
|
|
# TODO distinguish between cases, offer to open the error page in a webbrowser.
|
|
|
|
if args.isbn is not None:
|
|
|
|
# TODO offer to confirm/change citekey
|
|
|
|
bibentry_raw = apis.isbn2bibtex(args.isbn)
|
|
|
|
elif args.arxiv is not None:
|
|
|
|
bibentry = rp.databroker.verify(bibentry_raw)
|
|
|
|
bibentry = apis.get_bibentry_from_api(args.arxiv, 'arxiv', rp)
|
|
|
|
if bibentry is None:
|
|
|
|
except apis.ReferenceNotFoundException as e:
|
|
|
|
ui.error('invalid isbn {} or unable to retrieve bibfile from it.'.format(args.isbn))
|
|
|
|
ui.error(e.message)
|
|
|
|
ui.exit(1)
|
|
|
|
ui.exit(1)
|
|
|
|
# TODO distinguish between cases, offer to open the error page in a webbrowser.
|
|
|
|
|
|
|
|
# TODO offer to confirm/change citekey
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bibentry_raw = content.get_content(bibfile, ui=ui)
|
|
|
|
bibentry_raw = content.get_content(bibfile, ui=ui)
|
|
|
|
bibentry = rp.databroker.verify(bibentry_raw)
|
|
|
|
bibentry = rp.databroker.verify(bibentry_raw)
|
|
|
|