FIX inconsistent error on push for existing paper.
The error raised by Repository.push_paper was different depending on whether the existence of the paper in the repository was tested directly through the filebroker (quicker when list of citekeys in not loaded) or through the regular __contains__ method.
This commit is contained in:
parent
2f1a8ae42a
commit
de3dda85d1
@ -71,12 +71,12 @@ class FileBroker(object):
|
||||
os.remove(bibfilepath)
|
||||
|
||||
def exists(self, citekey, both=True):
|
||||
meta_exists = check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False)
|
||||
bib_exists = check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False)
|
||||
if both:
|
||||
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) and
|
||||
check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False))
|
||||
return meta_exists and bib_exists
|
||||
else:
|
||||
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) or
|
||||
check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False))
|
||||
return meta_exists or bib_exists
|
||||
|
||||
|
||||
def listing(self, filestats=True):
|
||||
|
@ -1,5 +1,3 @@
|
||||
import shutil
|
||||
import glob
|
||||
import itertools
|
||||
|
||||
from . import bibstruct
|
||||
@ -7,6 +5,7 @@ from . import events
|
||||
from . import datacache
|
||||
from .paper import Paper
|
||||
|
||||
|
||||
def _base27(n):
|
||||
return _base27((n - 1) // 26) + chr(ord('a') + ((n - 1) % 26)) if n else ''
|
||||
|
||||
@ -65,9 +64,8 @@ class Repository(object):
|
||||
if True, mimick the behavior of updating a paper
|
||||
"""
|
||||
bibstruct.check_citekey(paper.citekey)
|
||||
if (not overwrite) and self.databroker.exists(paper.citekey, both = False):
|
||||
raise IOError('files using the {} citekey already exists'.format(paper.citekey))
|
||||
if (not overwrite) and self.citekeys is not None and paper.citekey in self.citekeys:
|
||||
if (not overwrite) and (self.databroker.exists(paper.citekey, both=False)
|
||||
or (citekey in self)):
|
||||
raise CiteKeyCollision('citekey {} already in use'.format(paper.citekey))
|
||||
|
||||
self.databroker.push_bibdata(paper.citekey, paper.bibdata)
|
||||
@ -138,4 +136,3 @@ class Repository(object):
|
||||
for p in self.all_papers():
|
||||
tags = tags.union(p.tags)
|
||||
return tags
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user