This involved many changes, some side effects of the change include: - remove of all `u"abc"` forms, in favor of `from __future__ import unicode_literals`. Their usage was inconsistent anyway, leading to problems when mixing with unicode content. - improve the tests, to allow printing for usecase even when crashing. Should make future test easier. This is done with a rather hacky `StdIO` class in `p3`, but it works. - for some reason, the skipped test for Python 2 seems to work now. While the previous point might seem related, it is not clear that this is actually the case.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from ..uis import get_ui
|
|
from .. import color
|
|
from .. import repo
|
|
from ..utils import resolve_citekey
|
|
from ..completion import CiteKeyCompletion
|
|
|
|
|
|
def parser(subparsers, conf):
|
|
parser = subparsers.add_parser('rename',
|
|
help='rename the citekey of a repository')
|
|
parser.add_argument('citekey', help='current citekey'
|
|
).completer = CiteKeyCompletion(conf)
|
|
parser.add_argument('new_citekey', help='new citekey')
|
|
return parser
|
|
|
|
|
|
def command(conf, args):
|
|
"""
|
|
:param bibfile: bibtex file (in .bib, .bibml or .yaml format.
|
|
:param docfile: path (no url yet) to a pdf or ps file
|
|
"""
|
|
|
|
ui = get_ui()
|
|
rp = repo.Repository(conf)
|
|
|
|
# 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)
|
|
paper = rp.pull_paper(key)
|
|
rp.rename_paper(paper, args.new_citekey)
|
|
ui.message("The '{}' citekey has been renamed into '{}'".format(
|
|
color.dye_out(args.citekey, 'citekey'),
|
|
color.dye_out(args.new_citekey, 'citekey')))
|
|
|
|
rp.close()
|