Merge branch 'PR_resolve_citekey' of https://github.com/beuerle/pubs into beuerle-PR_resolve_citekey

main
Fabien C. Y. Benureau 5 years ago
commit 7e98939202
No known key found for this signature in database
GPG Key ID: C3FB5E831A249A9A

@ -71,7 +71,7 @@ def command(conf, args):
# ui.exit() # ui.exit()
if args.action == 'add': if args.action == 'add':
citekey = resolve_citekey(rp, args.citekey[0], ui=ui, exit_on_fail=True) citekey = resolve_citekey(rp, conf, args.citekey[0], ui=ui, exit_on_fail=True)
paper = rp.pull_paper(citekey) paper = rp.pull_paper(citekey)
if paper.docpath is not None and not args.force: if paper.docpath is not None and not args.force:
@ -98,7 +98,7 @@ def command(conf, args):
elif args.action == 'remove': elif args.action == 'remove':
for key in resolve_citekey_list(rp, args.citekeys, ui=ui, exit_on_fail=True): for key in resolve_citekey_list(rp, conf, args.citekeys, ui=ui, exit_on_fail=True):
paper = rp.pull_paper(key) paper = rp.pull_paper(key)
# if there is no document (and the user cares) -> inform + continue # if there is no document (and the user cares) -> inform + continue
@ -126,7 +126,7 @@ def command(conf, args):
color.dye_err(args.path[0], 'filepath'))) color.dye_err(args.path[0], 'filepath')))
ui.exit(1) ui.exit(1)
for key in resolve_citekey_list(rp, args.citekeys, ui=ui, exit_on_fail=True): for key in resolve_citekey_list(rp, conf, args.citekeys, ui=ui, exit_on_fail=True):
try: try:
paper = rp.pull_paper(key) paper = rp.pull_paper(key)
doc = paper.docpath doc = paper.docpath
@ -143,7 +143,7 @@ def command(conf, args):
elif args.action == 'open': elif args.action == 'open':
with_command = args.cmd with_command = args.cmd
citekey = resolve_citekey(rp, args.citekey[0], ui=ui, exit_on_fail=True) citekey = resolve_citekey(rp, conf, args.citekey[0], ui=ui, exit_on_fail=True)
paper = rp.pull_paper(citekey) paper = rp.pull_paper(citekey)
if paper.docpath is None: if paper.docpath is None:

@ -30,7 +30,7 @@ def command(conf, args):
meta = args.meta meta = args.meta
rp = repo.Repository(conf) rp = repo.Repository(conf)
citekey = resolve_citekey(rp, args.citekey, ui=ui, exit_on_fail=True) citekey = resolve_citekey(rp, conf, args.citekey, ui=ui, exit_on_fail=True)
paper = rp.pull_paper(citekey) paper = rp.pull_paper(citekey)
coder = EnDecoder() coder = EnDecoder()

@ -46,7 +46,7 @@ def command(conf, args):
if len(args.citekeys) < 1: if len(args.citekeys) < 1:
papers = rp.all_papers() papers = rp.all_papers()
else: else:
for key in resolve_citekey_list(repo=rp, citekeys=args.citekeys, ui=ui, exit_on_fail=True): for key in resolve_citekey_list(rp, conf, args.citekeys, ui=ui, exit_on_fail=True):
papers.append(rp.pull_paper(key)) papers.append(rp.pull_paper(key))
bib = {} bib = {}

@ -23,7 +23,7 @@ def command(conf, args):
ui = get_ui() ui = get_ui()
rp = repo.Repository(conf) rp = repo.Repository(conf)
citekey = resolve_citekey(rp, args.citekey, ui=ui, exit_on_fail=True) citekey = resolve_citekey(rp, conf, args.citekey, ui=ui, exit_on_fail=True)
notepath = rp.databroker.real_notepath(citekey, rp.conf['main']['note_extension']) notepath = rp.databroker.real_notepath(citekey, rp.conf['main']['note_extension'])
if args.append is None: if args.append is None:
ui.edit_file(notepath, temporary=False) ui.edit_file(notepath, temporary=False)

@ -25,7 +25,7 @@ def command(conf, args):
force = args.force force = args.force
rp = repo.Repository(conf) rp = repo.Repository(conf)
keys = resolve_citekey_list(repo=rp, citekeys=args.citekeys, ui=ui, exit_on_fail=True) keys = resolve_citekey_list(rp, conf, args.citekeys, ui=ui, exit_on_fail=True)
plural = 's' if len(keys) > 1 else '' plural = 's' if len(keys) > 1 else ''
if force is None: if force is None:

@ -26,7 +26,7 @@ def command(conf, args):
rp = repo.Repository(conf) rp = repo.Repository(conf)
# TODO: here should be a test whether the new citekey is valid # TODO: here should be a test whether the new citekey is valid
key = resolve_citekey(repo=rp, citekey=args.citekey, ui=ui, exit_on_fail=True) key = resolve_citekey(rp, conf, args.citekey, ui=ui, exit_on_fail=True)
paper = rp.pull_paper(key) paper = rp.pull_paper(key)
rp.rename_paper(paper, args.new_citekey) rp.rename_paper(paper, args.new_citekey)
ui.message("The '{}' citekey has been renamed into '{}'".format( ui.message("The '{}' citekey has been renamed into '{}'".format(

@ -89,7 +89,7 @@ def command(conf, args):
else: else:
not_citekey = False not_citekey = False
try: try:
citekeyOrTag = resolve_citekey(repo=rp, citekey=citekeyOrTag, ui=ui, exit_on_fail=True) citekeyOrTag = resolve_citekey(rp, conf, citekeyOrTag, ui=ui, exit_on_fail=True)
except SystemExit: except SystemExit:
not_citekey = True not_citekey = True
if not not_citekey: if not not_citekey:

@ -22,7 +22,7 @@ def command(conf, args):
ui = get_ui() ui = get_ui()
rp = repo.Repository(conf) rp = repo.Repository(conf)
for key in resolve_citekey_list(rp, args.citekey, ui=ui, exit_on_fail=False): for key in resolve_citekey_list(rp, conf, args.citekey, ui=ui, exit_on_fail=False):
try: try:
paper = rp.pull_paper(key) paper = rp.pull_paper(key)
url = paper.bibdata['url'] url = paper.bibdata['url']

@ -7,7 +7,7 @@ from . import color
from . import pretty from . import pretty
def resolve_citekey(repo, citekey, ui=None, exit_on_fail=True): def resolve_citekey(repo, conf, citekey, ui=None, exit_on_fail=True):
"""Check that a citekey exists, or autocompletes it if not ambiguous. """Check that a citekey exists, or autocompletes it if not ambiguous.
:returns found citekey :returns found citekey
""" """
@ -39,12 +39,12 @@ def resolve_citekey(repo, citekey, ui=None, exit_on_fail=True):
return citekey return citekey
def resolve_citekey_list(repo, citekeys, ui=None, exit_on_fail=True): def resolve_citekey_list(repo, conf, citekeys, ui=None, exit_on_fail=True):
shutdown = False shutdown = False
keys = [] keys = []
for key in citekeys: for key in citekeys:
try: try:
keys.append(resolve_citekey(repo, key, ui, exit_on_fail)) keys.append(resolve_citekey(repo, conf, key, ui=ui, exit_on_fail=exit_on_fail))
except SystemExit: except SystemExit:
shutdown = exit_on_fail shutdown = exit_on_fail

Loading…
Cancel
Save