Skip to content

Commit

Permalink
Check for documents in all main commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrogallo committed Mar 9, 2019
1 parent eb9491a commit 639df31
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 3 deletions.
5 changes: 5 additions & 0 deletions papis/commands/addto.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import logging
import papis.cli
import click
import papis.strings


def run(document, filepaths):
Expand Down Expand Up @@ -100,6 +101,10 @@ def run(document, filepaths):
def cli(query, files, file_name):
"""Add files to an existing document"""
documents = papis.database.get().query(query)
logger = logging.getLogger('cli:addto')
if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)
return
document = papis.api.pick_doc(documents)
if not document:
return status.file_not_found
Expand Down
8 changes: 8 additions & 0 deletions papis/commands/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import papis.api
import click
import papis.database
import papis.strings
import logging


def run(document):
Expand All @@ -41,6 +43,12 @@ def run(document):
def cli(query, key):
"""Open document's url in a browser"""
documents = papis.database.get().query(query)
logger = logging.getLogger('cli:browse')

if len(documents) == 0:
logger.warning(papis.strings.no_documents_retrieved_message)
return 0

document = papis.api.pick_doc(documents)
if len(key):
papis.config.set('browse-key', key)
Expand Down
2 changes: 2 additions & 0 deletions papis/commands/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import papis.cli
import click
import logging
import papis.strings


def run(document, wait=True):
Expand Down Expand Up @@ -66,6 +67,7 @@ def cli(
documents = [document] if document else []

if len(documents) == 0:
logger.warning(papis.strings.no_documents_retrieved_message)
return 0

for document in documents:
Expand Down
5 changes: 5 additions & 0 deletions papis/commands/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
from papis.document import from_folder
import papis.config
import papis.bibtex
import papis.strings
import papis.cli
import click
import logging
Expand Down Expand Up @@ -457,6 +458,10 @@ def citations(ctx, query, doc_folder, max_citations, save, rmfile):
search=query
)

if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)
return

doc = papis.api.pick_doc(documents)
db = papis.database.get()
citations_file = os.path.join(doc.get_main_folder(), 'citations.yaml')
Expand Down
5 changes: 5 additions & 0 deletions papis/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import papis.cli
import papis.api
import papis.database
import papis.strings
import logging


Expand Down Expand Up @@ -181,6 +182,10 @@ def cli(
if json and folder or yaml and folder:
logger.warning("Only --folder flag will be considered")

if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)
return

if not all:
document = papis.api.pick_doc(documents)
if not document:
Expand Down
4 changes: 4 additions & 0 deletions papis/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from papis.api import status
import os
import papis.utils
import papis.strings
import papis.config
import papis.database
import papis.downloaders.utils
Expand Down Expand Up @@ -100,6 +101,7 @@ def run(
if library is None:
library = papis.config.get_lib()
config = papis.config.get_configuration()
logger = logging.getLogger('cli:list')
db = papis.database.get(library)
if template is not None:
if not os.path.exists(template):
Expand All @@ -122,6 +124,8 @@ def run(
]

documents = db.query(query)
if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)

if pick:
documents = filter(lambda x: x, [papis.api.pick_doc(documents)])
Expand Down
4 changes: 4 additions & 0 deletions papis/commands/mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
import papis.cli
import papis.api
import papis.strings
import click


Expand Down Expand Up @@ -61,6 +62,9 @@ def cli(query, git):
logger = logging.getLogger('cli:mv')

documents = papis.database.get().query(query)
if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)
return

document = papis.api.pick_doc(documents)
if not document:
Expand Down
5 changes: 3 additions & 2 deletions papis/commands/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import click
import logging
from papis.document import from_folder
import papis.strings


def run(document, opener=None, folder=False, mark=False):
Expand Down Expand Up @@ -170,8 +171,8 @@ def cli(query, doc_folder, tool, folder, all, mark):
documents = [from_folder(doc_folder)]

if not documents:
click.echo("No documents found with that name.")
return 1
logger.warning(papis.strings.no_documents_retrieved_message)
return 0

if not all:
documents = [papis.api.pick_doc(documents)]
Expand Down
5 changes: 5 additions & 0 deletions papis/commands/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import click
import papis.cli
import papis.database
import papis.strings


def run(document, new_name, git=False):
Expand Down Expand Up @@ -52,6 +53,10 @@ def cli(query, git):
"""Rename entry"""

documents = papis.database.get().query(query)
logger = logging.getLogger('cli:rename')

if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)
document = papis.api.pick_doc(documents)
if not document:
return 0
Expand Down
9 changes: 9 additions & 0 deletions papis/commands/rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import papis.config
import papis.document
import papis.cli
import papis.strings
import papis.database
import click
import logging


def run(
Expand Down Expand Up @@ -57,6 +59,12 @@ def cli(
):
"""Delete command for several objects"""
documents = papis.database.get().query(query)
logger = logging.getLogger('cli:rm')

if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)
return 0

document = papis.api.pick_doc(documents)
if not document:
return status.file_not_found
Expand All @@ -80,6 +88,7 @@ def cli(
toolbar = 'The folder {0} would be removed'.format(
document.get_main_folder()
)
logger.warning("This document will be removed, check it")
papis.utils.text_area(
title=toolbar, text=document.dump(), lexer_name='yaml'
)
Expand Down
8 changes: 7 additions & 1 deletion papis/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import urllib.error
import logging
import papis.utils
import papis.strings
import papis.bibtex
import papis.downloaders.utils
import papis.document
Expand Down Expand Up @@ -166,12 +167,17 @@ def cli(
documents = papis.database.get().query(query)
data = dict()
logger = logging.getLogger('cli:update')
if not documents:
logger.warning(papis.strings.no_documents_retrieved_message)

if doc_folder:
documents = [from_folder(doc_folder)]

if not all:
documents = [papis.api.pick_doc(documents)]
documents = filter(
lambda d: d,
[papis.api.pick_doc(documents)]
)

for document in documents:
if all:
Expand Down

0 comments on commit 639df31

Please sign in to comment.