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.
main
Olivier Mangin 7 years ago
parent 7d1c678d3d
commit 668d30ffbf
No known key found for this signature in database
GPG Key ID: D72FEC1C3120A884

@ -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))

@ -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.")
if copy:
doc_add_group.add_argument(
'-C', '--copy', action='store_const', dest='doc_add', const='copy',
default=None,
'-C', '--copy', action='store_const', dest='doc_copy', const='copy',
help="copy document (keep source).")
if move:
doc_add_group.add_argument(
'-M', '--move', action='store_const', dest='doc_add', const='move',
default=None,
'-M', '--move', action='store_const', dest='doc_copy', const='move',
help="move document (copy and remove source).")

@ -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']

@ -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()

Loading…
Cancel
Save