Merge branch 'develop' into feat/python3
This commit is contained in:
commit
c45b64506a
@ -82,7 +82,7 @@ def command(args):
|
||||
base_key = bibstruct.extract_citekey(bibdata)
|
||||
citekey = rp.unique_citekey(base_key)
|
||||
else:
|
||||
rp.databroker.exists(citekey, both=False)
|
||||
rp.databroker.exists(citekey, meta_check=False)
|
||||
|
||||
p = paper.Paper(bibdata, citekey=citekey)
|
||||
|
||||
|
@ -39,13 +39,22 @@ class DataBroker(object):
|
||||
def remove(self, citekey):
|
||||
self.filebroker.remove(citekey)
|
||||
|
||||
def exists(self, citekey, both = True):
|
||||
return self.filebroker.exists(citekey, both=both)
|
||||
def exists(self, citekey, meta_check=False):
|
||||
""" Checks wether the bibtex of a citekey exists.
|
||||
|
||||
:param meta_check: if True, will return if both the bibtex and the meta file exists.
|
||||
"""
|
||||
return self.filebroker.exists(citekey, meta_check=meta_check)
|
||||
|
||||
def citekeys(self):
|
||||
listings = self.listing(filestats=False)
|
||||
return set(listings['bibfiles'])
|
||||
|
||||
def listing(self, filestats=True):
|
||||
return self.filebroker.listing(filestats=filestats)
|
||||
|
||||
def verify(self, bibdata_raw):
|
||||
"""Will return None if bibdata_raw can't be decoded"""
|
||||
try:
|
||||
return self.endecoder.decode_bibdata(bibdata_raw)
|
||||
except ValueError:
|
||||
|
@ -7,7 +7,7 @@ class DataCache(object):
|
||||
Has two roles :
|
||||
1. Provides a buffer between the commands and the hard drive.
|
||||
Until a command request a hard drive ressource, it does not touch it.
|
||||
2. Keeps a up-to-date, pickled version of the repository, to speed up things
|
||||
2. Keeps an up-to-date, pickled version of the repository, to speed up things
|
||||
when they are a lot of files. Update are also done only when required.
|
||||
Changes are detected using data modification timestamps.
|
||||
|
||||
@ -46,18 +46,16 @@ class DataCache(object):
|
||||
def remove(self, citekey):
|
||||
self.databroker.remove(citekey)
|
||||
|
||||
def exists(self, citekey, both=True):
|
||||
return self.databroker.exists(citekey, both=both)
|
||||
def exists(self, citekey, meta_check=False):
|
||||
return self.databroker.exists(citekey, meta_check=meta_check)
|
||||
|
||||
def citekeys(self):
|
||||
listings = self.listing(filestats=False)
|
||||
return set(listings['metafiles']).intersection(listings['bibfiles'])
|
||||
return self.databroker.citekeys()
|
||||
|
||||
def listing(self, filestats=True):
|
||||
return self.databroker.listing(filestats=filestats)
|
||||
|
||||
def verify(self, bibdata_raw):
|
||||
"""Will return None if bibdata_raw can't be decoded"""
|
||||
return self.databroker.verify(bibdata_raw)
|
||||
|
||||
# docbroker
|
||||
|
@ -71,13 +71,16 @@ class FileBroker(object):
|
||||
if check_file(bibfilepath):
|
||||
os.remove(system_path(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 meta_exists and bib_exists
|
||||
else:
|
||||
return meta_exists or bib_exists
|
||||
def exists(self, citekey, meta_check=False):
|
||||
""" Checks wether the bibtex of a citekey exists.
|
||||
|
||||
:param meta_check: if True, will return if both the bibtex and the meta file exists.
|
||||
"""
|
||||
does_exists = check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False)
|
||||
if meta_check:
|
||||
meta_exists = check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False)
|
||||
does_exists = does_exists and meta_exists
|
||||
return does_exists
|
||||
|
||||
def listing(self, filestats=True):
|
||||
metafiles = []
|
||||
|
@ -50,7 +50,8 @@ class Repository(object):
|
||||
|
||||
def pull_paper(self, citekey):
|
||||
"""Load a paper by its citekey from disk, if necessary."""
|
||||
if self.databroker.exists(citekey, both = True):
|
||||
if self.databroker.exists(citekey, meta_check=True):
|
||||
#TODO meta_check=False and default meta generation
|
||||
return Paper(self.databroker.pull_bibdata(citekey),
|
||||
citekey=citekey,
|
||||
metadata=self.databroker.pull_metadata(citekey))
|
||||
@ -64,7 +65,7 @@ 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)
|
||||
if (not overwrite) and (self.databroker.exists(paper.citekey, meta_check=False)
|
||||
or (paper.citekey in self)):
|
||||
raise CiteKeyCollision('citekey {} already in use'.format(paper.citekey))
|
||||
if not paper.added:
|
||||
|
@ -32,6 +32,7 @@ or for bibtex containing a single file:
|
||||
Requirements
|
||||
------------
|
||||
- python >= 2.6
|
||||
- [pyYaml](http://pyyaml.org)
|
||||
- [bibtexparser](https://github.com/sciunto/python-bibtexparser)
|
||||
|
||||
|
||||
|
2
setup.py
2
setup.py
@ -8,7 +8,7 @@ setup(name='pubs',
|
||||
author_email='fabien.benureau+inria@gmail.com',
|
||||
url='',
|
||||
description='research papers manager',
|
||||
requires=['bibtexparser'],
|
||||
requires=['bibtexparser', 'pyyaml'],
|
||||
packages=find_packages(),
|
||||
scripts=['pubs/pubs']
|
||||
)
|
||||
|
@ -25,11 +25,12 @@ class TestDataBroker(unittest.TestCase):
|
||||
db = db_class('tmp', create=True)
|
||||
|
||||
db.push_metadata('citekey1', page99_metadata)
|
||||
self.assertTrue(db.exists('citekey1', both=False))
|
||||
self.assertFalse(db.exists('citekey1', both=True))
|
||||
self.assertFalse(db.exists('citekey1', meta_check=True))
|
||||
self.assertFalse(db.exists('citekey1', meta_check=False))
|
||||
|
||||
db.push_bibdata('citekey1', page99_bibdata)
|
||||
self.assertTrue(db.exists('citekey1', both=True))
|
||||
self.assertTrue(db.exists('citekey1', meta_check=False))
|
||||
self.assertTrue(db.exists('citekey1', meta_check=True))
|
||||
|
||||
self.assertEqual(db.pull_metadata('citekey1'), page99_metadata)
|
||||
pulled = db.pull_bibdata('citekey1')['Page99']
|
||||
|
Loading…
x
Reference in New Issue
Block a user