|
|
|
@ -110,7 +110,7 @@ class DocBroker(object):
|
|
|
|
|
* these document have an adress of the type "docsdir://citekey.pdf"
|
|
|
|
|
* docsdir:// correspond to /path/to/pubsdir/doc (configurable)
|
|
|
|
|
* document outside of the repository will not be removed.
|
|
|
|
|
* deliberately, there is no move_doc method.
|
|
|
|
|
* move_doc only applies from inside to inside the docsdir
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, directory, scheme='docsdir', subdir='doc'):
|
|
|
|
@ -129,8 +129,21 @@ class DocBroker(object):
|
|
|
|
|
# def doc_exists(self, citekey, ext='.txt'):
|
|
|
|
|
# return check_file(os.path.join(self.docdir, citekey + ext), fail=False)
|
|
|
|
|
|
|
|
|
|
def copy_doc(self, citekey, source_path, overwrite=False):
|
|
|
|
|
""" Copy a document to the pubsdir/doc, and return the location
|
|
|
|
|
def real_docpath(self, docpath):
|
|
|
|
|
"""Return the full path
|
|
|
|
|
Essentially transform pubsdir://doc/{citekey}.{ext} to /path/to/pubsdir/doc/{citekey}.{ext}.
|
|
|
|
|
Return absoluted paths of regular ones otherwise.
|
|
|
|
|
"""
|
|
|
|
|
if self.in_docsdir(docpath):
|
|
|
|
|
parsed = urlparse.urlparse(docpath)
|
|
|
|
|
if parsed.path == '':
|
|
|
|
|
docpath = os.path.join(self.docdir, parsed.netloc)
|
|
|
|
|
else:
|
|
|
|
|
docpath = os.path.join(self.docdir, parsed.netloc, parsed.path[1:])
|
|
|
|
|
return os.path.normpath(os.path.abspath(docpath))
|
|
|
|
|
|
|
|
|
|
def add_doc(self, citekey, source_path, overwrite=False):
|
|
|
|
|
""" Add a document to the docsdir, and return its location.
|
|
|
|
|
|
|
|
|
|
The document will be named {citekey}.{ext}.
|
|
|
|
|
The location will be docsdir://{citekey}.{ext}.
|
|
|
|
@ -162,15 +175,17 @@ class DocBroker(object):
|
|
|
|
|
if check_file(filepath):
|
|
|
|
|
os.remove(filepath)
|
|
|
|
|
|
|
|
|
|
def real_docpath(self, docpath):
|
|
|
|
|
"""Return the full path
|
|
|
|
|
Essentially transform pubsdir://doc/{citekey}.{ext} to /path/to/pubsdir/doc/{citekey}.{ext}.
|
|
|
|
|
Return absoluted paths of regular ones otherwise.
|
|
|
|
|
def rename_doc(self, docpath, new_citekey):
|
|
|
|
|
""" Move a document inside the docsdir
|
|
|
|
|
|
|
|
|
|
:raise IOError: if docpath doesn't point to a file
|
|
|
|
|
if new_citekey doc exists already.
|
|
|
|
|
:raise ValueError: if docpath is not in docsdir().
|
|
|
|
|
|
|
|
|
|
if an exception is raised, the files on disk haven't changed.
|
|
|
|
|
"""
|
|
|
|
|
if self.in_docsdir(docpath):
|
|
|
|
|
parsed = urlparse.urlparse(docpath)
|
|
|
|
|
if parsed.path == '':
|
|
|
|
|
docpath = os.path.join(self.docdir, parsed.netloc)
|
|
|
|
|
else:
|
|
|
|
|
docpath = os.path.join(self.docdir, parsed.netloc, parsed.path[1:])
|
|
|
|
|
return os.path.normpath(os.path.abspath(docpath))
|
|
|
|
|
if not self.in_docsdir(docpath):
|
|
|
|
|
raise ValueError('cannot rename an external file ({}).'.format(docpath))
|
|
|
|
|
|
|
|
|
|
new_notepath = self.add_doc(new_citekey, docpath)
|
|
|
|
|
self.remove_doc(docpath)
|