From 668d30ffbf7f6d1abc35658b7ea6091b0a9ac8e1 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 20 Aug 2018 12:14:25 +0200 Subject: [PATCH] Allows move for import on explicit option. - uses `copy` as a default (hence no need for the option), - does not use `doc_add` config for import. --- changelog.md | 2 ++ pubs/command_utils.py | 18 ++++++++---------- pubs/commands/add_cmd.py | 6 +++--- pubs/commands/import_cmd.py | 16 ++++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/changelog.md b/changelog.md index f21ba39..4ab4d92 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,8 @@ ### Implemented enhancements +- Adds `move`, and `link` options for handling of documents during import (copy being the default). [(#159)](https://github.com/pubs/pubs/pull/159) + - Better dialog after editing paper [(#142)](https://github.com/pubs/pubs/issues/142) - Add a command to open urls ([#139](https://github.com/pubs/pubs/issues/139) by [ksunden](https://github.com/ksunden)) diff --git a/pubs/command_utils.py b/pubs/command_utils.py index 445f203..0446824 100644 --- a/pubs/command_utils.py +++ b/pubs/command_utils.py @@ -3,18 +3,16 @@ or help messages. """ -def add_doc_add_arguments(parser, move=True): +def add_doc_copy_arguments(parser, copy=True): doc_add_group = parser.add_mutually_exclusive_group() doc_add_group.add_argument( - '-L', '--link', action='store_const', dest='doc_add', const='link', + '-L', '--link', action='store_const', dest='doc_copy', const='link', default=None, help="don't copy document files, just create a link.") - doc_add_group.add_argument( - '-C', '--copy', action='store_const', dest='doc_add', const='copy', - default=None, - help="copy document (keep source).") - if move: + if copy: doc_add_group.add_argument( - '-M', '--move', action='store_const', dest='doc_add', const='move', - default=None, - help="move document (copy and remove source).") + '-C', '--copy', action='store_const', dest='doc_copy', const='copy', + help="copy document (keep source).") + doc_add_group.add_argument( + '-M', '--move', action='store_const', dest='doc_copy', const='move', + help="move document (copy and remove source).") diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 4510db7..dfa9bb1 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -12,7 +12,7 @@ from .. import apis from .. import pretty from .. import utils from .. import endecoder -from ..command_utils import add_doc_add_arguments +from ..command_utils import add_doc_copy_arguments from ..completion import CommaSeparatedTagsCompletion @@ -35,7 +35,7 @@ def parser(subparsers, conf): ).completer = CommaSeparatedTagsCompletion(conf) parser.add_argument('-k', '--citekey', help='citekey associated with the paper;\nif not provided, one will be generated automatically.', default=None, type=p3.u_maybe) - add_doc_add_arguments(parser) + add_doc_copy_arguments(parser) return parser @@ -134,7 +134,7 @@ def command(conf, args): '{}, using {} instead.').format(bib_docfile, docfile)) # create the paper - doc_add = args.doc_add + doc_add = args.doc_copy if doc_add is None: doc_add = conf['main']['doc_add'] diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index 8f11bc9..7cbf3b6 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -7,10 +7,11 @@ from .. import repo from .. import endecoder from .. import bibstruct from .. import color +from .. import content from ..paper import Paper from ..uis import get_ui from ..content import system_path, read_text_file -from ..command_utils import add_doc_add_arguments +from ..command_utils import add_doc_copy_arguments _ABORT_USE_IGNORE_MSG = "Aborting import. Use --ignore-malformed to ignore." @@ -33,7 +34,7 @@ def parser(subparsers, conf): parser.add_argument( '-i', '--ignore-malformed', action='store_true', default=False, help="Ignore malformed and unreadable files and entries") - add_doc_add_arguments(parser, move=False) + add_doc_copy_arguments(parser, copy=False) return parser @@ -94,10 +95,7 @@ def command(conf, args): ui = get_ui() bibpath = args.bibpath - doc_add = args.doc_add - if doc_add is None: - doc_add = conf['main']['doc_add'] - copy = doc_add in ('copy', 'move') + doc_import = args.doc_copy or 'copy' rp = repo.Repository(conf) # Extract papers from bib @@ -111,7 +109,9 @@ def command(conf, args): if docfile is None: ui.warning("No file for {}.".format(p.citekey)) else: - rp.push_doc(p.citekey, docfile, copy=copy) - # FIXME should move the file if configured to do so. + rp.push_doc(p.citekey, docfile, + copy=(doc_import in ('copy', 'move'))) + if doc_import == 'move' and content.content_type(docfile) != 'url': + content.remove_file(docfile) rp.close()