Honor custom pubsdoc in config
This commit is contained in:
parent
2aad93b526
commit
0f84268ebf
@ -42,6 +42,7 @@ def command(conf, args):
|
|||||||
conf['main']['pubsdir'] = pubsdir
|
conf['main']['pubsdir'] = pubsdir
|
||||||
conf['main']['docsdir'] = docsdir
|
conf['main']['docsdir'] = docsdir
|
||||||
conf['main']['open_cmd'] = config.default_open_cmd()
|
conf['main']['open_cmd'] = config.default_open_cmd()
|
||||||
|
conf = config.post_process_conf(conf)
|
||||||
config.save_conf(conf)
|
config.save_conf(conf)
|
||||||
|
|
||||||
Repository(conf, create=True)
|
Repository(conf, create=True)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
from .conf import get_confpath, load_default_conf, load_conf, save_conf, check_conf
|
from .conf import get_confpath, load_default_conf, load_conf, save_conf, check_conf
|
||||||
from .conf import default_open_cmd
|
from .conf import default_open_cmd, post_process_conf
|
||||||
|
@ -11,12 +11,19 @@ from .spec import configspec
|
|||||||
|
|
||||||
DFT_CONFIG_PATH = os.path.expanduser('~/.pubsrc')
|
DFT_CONFIG_PATH = os.path.expanduser('~/.pubsrc')
|
||||||
|
|
||||||
|
def post_process_conf(conf):
|
||||||
|
"""Do some post processing on the configuration"""
|
||||||
|
if conf['main']['docsdir'] == 'docsdir://':
|
||||||
|
conf['main']['docsdir'] = os.path.join(conf['main']['pubsdir'], 'doc')
|
||||||
|
return conf
|
||||||
|
|
||||||
|
|
||||||
def load_default_conf():
|
def load_default_conf():
|
||||||
"""Load the default configuration"""
|
"""Load the default configuration"""
|
||||||
default_conf = configobj.ConfigObj(configspec=configspec)
|
default_conf = configobj.ConfigObj(configspec=configspec)
|
||||||
validator = validate.Validator()
|
validator = validate.Validator()
|
||||||
default_conf.validate(validator, copy=True)
|
default_conf.validate(validator, copy=True)
|
||||||
|
default_conf = post_process_conf(default_conf)
|
||||||
return default_conf
|
return default_conf
|
||||||
|
|
||||||
|
|
||||||
@ -52,6 +59,7 @@ def load_conf(check=True, path=None):
|
|||||||
if check:
|
if check:
|
||||||
check_conf(conf)
|
check_conf(conf)
|
||||||
conf.filename = path
|
conf.filename = path
|
||||||
|
conf = post_process_conf(conf)
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ class DataBroker(object):
|
|||||||
Requests are optimistically made, and exceptions are raised if something goes wrong.
|
Requests are optimistically made, and exceptions are raised if something goes wrong.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, directory, create=False):
|
def __init__(self, pubsdir, docsdir, create=False):
|
||||||
self.filebroker = filebroker.FileBroker(directory, create=create)
|
self.filebroker = filebroker.FileBroker(pubsdir, create=create)
|
||||||
self.endecoder = endecoder.EnDecoder()
|
self.endecoder = endecoder.EnDecoder()
|
||||||
self.docbroker = filebroker.DocBroker(directory, scheme='docsdir', subdir='doc')
|
self.docbroker = filebroker.DocBroker(docsdir, scheme='docsdir', subdir='')
|
||||||
self.notebroker = filebroker.DocBroker(directory, scheme='notesdir', subdir='notes')
|
self.notebroker = filebroker.DocBroker(pubsdir, scheme='notesdir', subdir='notes')
|
||||||
|
|
||||||
# cache
|
# cache
|
||||||
|
|
||||||
|
@ -94,8 +94,9 @@ class DataCache(object):
|
|||||||
|
|
||||||
For the moment, only (1) is implemented.
|
For the moment, only (1) is implemented.
|
||||||
"""
|
"""
|
||||||
def __init__(self, directory, create=False):
|
def __init__(self, pubsdir, docsdir, create=False):
|
||||||
self.directory = directory
|
self.pubsdir = pubsdir
|
||||||
|
self.docsdir = docsdir
|
||||||
self._databroker = None
|
self._databroker = None
|
||||||
self._metacache = None
|
self._metacache = None
|
||||||
self._bibcache = None
|
self._bibcache = None
|
||||||
@ -108,7 +109,8 @@ class DataCache(object):
|
|||||||
@property
|
@property
|
||||||
def databroker(self):
|
def databroker(self):
|
||||||
if self._databroker is None:
|
if self._databroker is None:
|
||||||
self._databroker = databroker.DataBroker(self.directory, create=False)
|
self._databroker = databroker.DataBroker(self.pubsdir, self.docsdir,
|
||||||
|
create=False)
|
||||||
return self._databroker
|
return self._databroker
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -124,7 +126,8 @@ class DataCache(object):
|
|||||||
return self._bibcache
|
return self._bibcache
|
||||||
|
|
||||||
def _create(self):
|
def _create(self):
|
||||||
self._databroker = databroker.DataBroker(self.directory, create=True)
|
self._databroker = databroker.DataBroker(self.pubsdir, self.docsdir,
|
||||||
|
create=True)
|
||||||
|
|
||||||
def flush_cache(self, force=False):
|
def flush_cache(self, force=False):
|
||||||
"""Write cache to disk"""
|
"""Write cache to disk"""
|
||||||
|
@ -39,7 +39,8 @@ class Repository(object):
|
|||||||
def __init__(self, conf, create=False):
|
def __init__(self, conf, create=False):
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
self._citekeys = None
|
self._citekeys = None
|
||||||
self.databroker = DataCache(self.conf['main']['pubsdir'], create=create)
|
self.databroker = DataCache(self.conf['main']['pubsdir'],
|
||||||
|
self.conf['main']['docsdir'], create=create)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.databroker.close()
|
self.databroker.close()
|
||||||
|
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.bak
|
*.bak
|
||||||
|
src/
|
||||||
|
@ -23,7 +23,7 @@ class TestDataBroker(fake_env.TestFakeFs):
|
|||||||
for db_class in [databroker.DataBroker, datacache.DataCache]:
|
for db_class in [databroker.DataBroker, datacache.DataCache]:
|
||||||
self.reset_fs()
|
self.reset_fs()
|
||||||
|
|
||||||
db = db_class('tmp', create=True)
|
db = db_class('tmp', 'tmp/doc', create=True)
|
||||||
|
|
||||||
db.push_metadata('citekey1', page99_metadata)
|
db.push_metadata('citekey1', page99_metadata)
|
||||||
self.assertFalse(db.exists('citekey1', meta_check=True))
|
self.assertFalse(db.exists('citekey1', meta_check=True))
|
||||||
@ -50,7 +50,7 @@ class TestDataBroker(fake_env.TestFakeFs):
|
|||||||
|
|
||||||
fake_env.copy_dir(self.fs, os.path.join(os.path.dirname(__file__), 'testrepo'), 'repo')
|
fake_env.copy_dir(self.fs, os.path.join(os.path.dirname(__file__), 'testrepo'), 'repo')
|
||||||
|
|
||||||
db = db_class('repo', create=False)
|
db = db_class('repo', 'repo/doc', create=False)
|
||||||
|
|
||||||
self.assertEqual(db.pull_bibentry('Page99'), page99_bibentry)
|
self.assertEqual(db.pull_bibentry('Page99'), page99_bibentry)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user