From de3dda85d195cae0386b51a43e13975b2c9d1dc1 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Tue, 15 Apr 2014 19:32:29 +0200 Subject: [PATCH] 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. --- pubs/filebroker.py | 8 ++++---- pubs/repo.py | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pubs/filebroker.py b/pubs/filebroker.py index c6b1b0d..012c062 100644 --- a/pubs/filebroker.py +++ b/pubs/filebroker.py @@ -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): diff --git a/pubs/repo.py b/pubs/repo.py index e5c68fa..bdaf43d 100644 --- a/pubs/repo.py +++ b/pubs/repo.py @@ -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 -