Skip to content

Commit

Permalink
Implement linking in add (issue #83)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrogallo committed Aug 27, 2018
1 parent 8e6c31a commit 177e1f1
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions papis/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
papis -l machine-learning add --from-url https://arxiv.org/abs/1712.03134
- If you do not want copy the original pdfs into the library, you can
also tell papis to just create a link to them, for example
.. code::
papis add --link ~/Documents/interesting.pdf --from-doi 10.10763/1.3237134
will add an entry into the papis library, but the pdf document will remain
at ``~/Documents/interesting.pdf``, and in the document's folder
there will be a link to ``~/Documents/interesting.pdf`` instead of the
file itself. Of course you always have to be sure that the
document at ``~/Documents/interesting.pdf`` does not disappear, otherwise
you will end up without a document to open.
Examples in python
^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -224,6 +238,7 @@ def run(
open_file=False,
edit=False,
commit=False,
link=False,
no_document=False
):
"""
Expand Down Expand Up @@ -448,11 +463,19 @@ def run(
)
continue
if not no_document:
logger.debug(
"[CP] '%s' to '%s'" %
(in_file_path, endDocumentPath)
)
shutil.copy(in_file_path, endDocumentPath)
if link:
in_file_abspath = os.path.abspath(in_file_path)
logger.debug(
"[SYMLINK] '%s' to '%s'" %
(in_file_abspath, endDocumentPath)
)
os.symlink(in_file_abspath, endDocumentPath)
else:
logger.debug(
"[CP] '%s' to '%s'" %
(in_file_path, endDocumentPath)
)
shutil.copy(in_file_path, endDocumentPath)

data['files'] = new_file_list

Expand Down Expand Up @@ -595,6 +618,12 @@ def run(
help="Commit document if library is a git repository",
default=False
)
@click.option(
"--link/--no-link",
help="Instead of copying the file to the library, create a link to"
"its original location",
default=False
)
@click.option(
"--no-document",
default=False,
Expand All @@ -619,6 +648,7 @@ def cli(
open,
edit,
commit,
link,
no_document
):
"""Add a document into a given library
Expand Down Expand Up @@ -676,5 +706,6 @@ def cli(
open_file=open,
edit=edit,
commit=commit,
link=link,
no_document=no_document
)

0 comments on commit 177e1f1

Please sign in to comment.