From 53a0f0a86e876ba5480a077ec9c07251b4750667 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 28 Apr 2014 18:20:45 +0200 Subject: [PATCH] Fixes path conversion for add_doc. Note: in current state the non-copy addition of document is not implemented. This commit also adds the raise of a NotImplementedError if the behavior is requested. --- pubs/commands/add_cmd.py | 4 ++++ pubs/content.py | 14 +++++++++----- pubs/filebroker.py | 2 -- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 8800b7a..56765b4 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -100,12 +100,16 @@ def command(args): ui.warning(('Skipping document file from bib file ' '{}, using {} instead.').format(bib_docfile, docfile)) + docfile = docfile + if docfile is not None: copy_doc = args.copy if copy_doc is None: copy_doc = config().import_copy if copy_doc: docfile = rp.databroker.add_doc(citekey, docfile) + else: + raise NotImplementedError # create the paper diff --git a/pubs/content.py b/pubs/content.py index bc33c4f..18f8c50 100644 --- a/pubs/content.py +++ b/pubs/content.py @@ -39,6 +39,10 @@ def _check_system_path_is(nature, path, fail=True): return answer +def system_path(path): + return os.path.abspath(os.path.expanduser(path)) + + def check_file(path, fail=True): syspath = system_path(path) return (_check_system_path_exists(syspath, fail=fail) @@ -64,10 +68,6 @@ def write_file(filepath, data): f.write(data) -def system_path(path): - return os.path.abspath(os.path.expanduser(path)) - - # dealing with formatless content def content_type(path): @@ -117,7 +117,9 @@ def get_content(path, ui=None): return read_file(path) -def move_content(source, target, overwrite = False): +def move_content(source, target, overwrite=False): + source = system_path(source) + target = system_path(target) if source == target: return if not overwrite and os.path.exists(target): @@ -126,6 +128,8 @@ def move_content(source, target, overwrite = False): def copy_content(source, target, overwrite=False): + source = system_path(source) + target = system_path(target) if source == target: return if not overwrite and os.path.exists(target): diff --git a/pubs/filebroker.py b/pubs/filebroker.py index 29faea2..53bdb75 100644 --- a/pubs/filebroker.py +++ b/pubs/filebroker.py @@ -145,8 +145,6 @@ class DocBroker(object): docpath = os.path.join(self.docdir, parsed.netloc) else: docpath = os.path.join(self.docdir, parsed.netloc, parsed.path[1:]) - elif content_type(docpath) != 'file': - return docpath return docpath def add_doc(self, citekey, source_path, overwrite=False):