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 -