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']['docsdir'] = docsdir
|
||||
conf['main']['open_cmd'] = config.default_open_cmd()
|
||||
conf = config.post_process_conf(conf)
|
||||
config.save_conf(conf)
|
||||
|
||||
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 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')
|
||||
|
||||
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():
|
||||
"""Load the default configuration"""
|
||||
default_conf = configobj.ConfigObj(configspec=configspec)
|
||||
validator = validate.Validator()
|
||||
default_conf.validate(validator, copy=True)
|
||||
default_conf = post_process_conf(default_conf)
|
||||
return default_conf
|
||||
|
||||
|
||||
@ -52,6 +59,7 @@ def load_conf(check=True, path=None):
|
||||
if check:
|
||||
check_conf(conf)
|
||||
conf.filename = path
|
||||
conf = post_process_conf(conf)
|
||||
return conf
|
||||
|
||||
|
||||
|
@ -9,11 +9,11 @@ class DataBroker(object):
|
||||
Requests are optimistically made, and exceptions are raised if something goes wrong.
|
||||
"""
|
||||
|
||||
def __init__(self, directory, create=False):
|
||||
self.filebroker = filebroker.FileBroker(directory, create=create)
|
||||
def __init__(self, pubsdir, docsdir, create=False):
|
||||
self.filebroker = filebroker.FileBroker(pubsdir, create=create)
|
||||
self.endecoder = endecoder.EnDecoder()
|
||||
self.docbroker = filebroker.DocBroker(directory, scheme='docsdir', subdir='doc')
|
||||
self.notebroker = filebroker.DocBroker(directory, scheme='notesdir', subdir='notes')
|
||||
self.docbroker = filebroker.DocBroker(docsdir, scheme='docsdir', subdir='')
|
||||
self.notebroker = filebroker.DocBroker(pubsdir, scheme='notesdir', subdir='notes')
|
||||
|
||||
# cache
|
||||
|
||||
|
@ -94,8 +94,9 @@ class DataCache(object):
|
||||
|
||||
For the moment, only (1) is implemented.
|
||||
"""
|
||||
def __init__(self, directory, create=False):
|
||||
self.directory = directory
|
||||
def __init__(self, pubsdir, docsdir, create=False):
|
||||
self.pubsdir = pubsdir
|
||||
self.docsdir = docsdir
|
||||
self._databroker = None
|
||||
self._metacache = None
|
||||
self._bibcache = None
|
||||
@ -108,7 +109,8 @@ class DataCache(object):
|
||||
@property
|
||||
def databroker(self):
|
||||
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
|
||||
|
||||
@property
|
||||
@ -124,7 +126,8 @@ class DataCache(object):
|
||||
return self._bibcache
|
||||
|
||||
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):
|
||||
"""Write cache to disk"""
|
||||
|
@ -150,7 +150,7 @@ class DocBroker(object):
|
||||
def __init__(self, directory, scheme='docsdir', subdir='doc'):
|
||||
self.scheme = scheme
|
||||
self.docdir = os.path.join(directory, subdir)
|
||||
if not check_directory(self.docdir, fail = False):
|
||||
if not check_directory(self.docdir, fail=False):
|
||||
os.mkdir(system_path(self.docdir))
|
||||
|
||||
def in_docsdir(self, docpath):
|
||||
|
@ -39,7 +39,8 @@ class Repository(object):
|
||||
def __init__(self, conf, create=False):
|
||||
self.conf = conf
|
||||
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):
|
||||
self.databroker.close()
|
||||
|
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.bak
|
||||
src/
|
||||
|
@ -23,7 +23,7 @@ class TestDataBroker(fake_env.TestFakeFs):
|
||||
for db_class in [databroker.DataBroker, datacache.DataCache]:
|
||||
self.reset_fs()
|
||||
|
||||
db = db_class('tmp', create=True)
|
||||
db = db_class('tmp', 'tmp/doc', create=True)
|
||||
|
||||
db.push_metadata('citekey1', page99_metadata)
|
||||
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')
|
||||
|
||||
db = db_class('repo', create=False)
|
||||
db = db_class('repo', 'repo/doc', create=False)
|
||||
|
||||
self.assertEqual(db.pull_bibentry('Page99'), page99_bibentry)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user