valid_citekey function in bibstruct
This commit is contained in:
parent
9bf88649a3
commit
3fee6b9403
@ -51,6 +51,12 @@ def author_last(author_str):
|
|||||||
return author_str.split(',')[0]
|
return author_str.split(',')[0]
|
||||||
|
|
||||||
|
|
||||||
|
def valid_citekey(citekey):
|
||||||
|
"""Return if a citekey is a valid filename or not"""
|
||||||
|
# FIXME: a bit crude, but efficient for now (and allows unicode citekeys)
|
||||||
|
return not '/' in citekey
|
||||||
|
|
||||||
|
|
||||||
def generate_citekey(bibdata):
|
def generate_citekey(bibdata):
|
||||||
""" Generate a citekey from bib_data.
|
""" Generate a citekey from bib_data.
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ from . import import_cmd
|
|||||||
# bonus
|
# bonus
|
||||||
from . import websearch_cmd
|
from . import websearch_cmd
|
||||||
from . import url_cmd
|
from . import url_cmd
|
||||||
#from . import bibtex_cmd
|
|
||||||
|
@ -32,7 +32,6 @@ CORE_CMDS = collections.OrderedDict([
|
|||||||
|
|
||||||
('websearch', commands.websearch_cmd),
|
('websearch', commands.websearch_cmd),
|
||||||
('url', commands.url_cmd),
|
('url', commands.url_cmd),
|
||||||
#('bibtex', commands.bibtex_cmd),
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,11 +198,9 @@ class Repository(object):
|
|||||||
:param base_key: the base key in question.
|
:param base_key: the base key in question.
|
||||||
:param bibentry: the bib entry to possibly generate the citekey.
|
:param bibentry: the bib entry to possibly generate the citekey.
|
||||||
"""
|
"""
|
||||||
# can't have `/` in citekeys
|
if not bibstruct.valid_citekey(base_key):
|
||||||
# FIXME: a bit crude, but efficient for now (and allows unicode citekeys)
|
|
||||||
# TODO: check that the generated citekey does not have a slash too.
|
|
||||||
if '/' in base_key:
|
|
||||||
base_key = bibstruct.generate_citekey(bibentry)
|
base_key = bibstruct.generate_citekey(bibentry)
|
||||||
|
# TODO: check that the generated citekey does not have a slash too.
|
||||||
for n in itertools.count():
|
for n in itertools.count():
|
||||||
if not base_key + _base27(n) in self.citekeys:
|
if not base_key + _base27(n) in self.citekeys:
|
||||||
return base_key + _base27(n)
|
return base_key + _base27(n)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user