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)
|
os.remove(bibfilepath)
|
||||||
|
|
||||||
def exists(self, citekey, both=True):
|
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:
|
if both:
|
||||||
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) and
|
return meta_exists and bib_exists
|
||||||
check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False))
|
|
||||||
else:
|
else:
|
||||||
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) or
|
return meta_exists or bib_exists
|
||||||
check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False))
|
|
||||||
|
|
||||||
|
|
||||||
def listing(self, filestats=True):
|
def listing(self, filestats=True):
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import shutil
|
|
||||||
import glob
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from . import bibstruct
|
from . import bibstruct
|
||||||
@ -7,6 +5,7 @@ from . import events
|
|||||||
from . import datacache
|
from . import datacache
|
||||||
from .paper import Paper
|
from .paper import Paper
|
||||||
|
|
||||||
|
|
||||||
def _base27(n):
|
def _base27(n):
|
||||||
return _base27((n - 1) // 26) + chr(ord('a') + ((n - 1) % 26)) if n else ''
|
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
|
if True, mimick the behavior of updating a paper
|
||||||
"""
|
"""
|
||||||
bibstruct.check_citekey(paper.citekey)
|
bibstruct.check_citekey(paper.citekey)
|
||||||
if (not overwrite) and self.databroker.exists(paper.citekey, both = False):
|
if (not overwrite) and (self.databroker.exists(paper.citekey, both=False)
|
||||||
raise IOError('files using the {} citekey already exists'.format(paper.citekey))
|
or (citekey in self)):
|
||||||
if (not overwrite) and self.citekeys is not None and paper.citekey in self.citekeys:
|
|
||||||
raise CiteKeyCollision('citekey {} already in use'.format(paper.citekey))
|
raise CiteKeyCollision('citekey {} already in use'.format(paper.citekey))
|
||||||
|
|
||||||
self.databroker.push_bibdata(paper.citekey, paper.bibdata)
|
self.databroker.push_bibdata(paper.citekey, paper.bibdata)
|
||||||
@ -138,4 +136,3 @@ class Repository(object):
|
|||||||
for p in self.all_papers():
|
for p in self.all_papers():
|
||||||
tags = tags.union(p.tags)
|
tags = tags.union(p.tags)
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user