diff --git a/papers/commands/__init__.py b/papers/commands/__init__.py index f20dd9d..179e7ca 100644 --- a/papers/commands/__init__.py +++ b/papers/commands/__init__.py @@ -1,12 +1,12 @@ import init_cmd import add_cmd import list_cmd +import open_cmd +import websearch_cmd # import import_cmd # import export_cmd # import edit_cmd # import remove_cmd -# import open_cmd -# import websearch_cmd # import tag_cmd # import attach_cmd # import update_cmd diff --git a/papers/commands/open_cmd.py b/papers/commands/open_cmd.py index 670899e..3807cb2 100644 --- a/papers/commands/open_cmd.py +++ b/papers/commands/open_cmd.py @@ -1,11 +1,10 @@ import subprocess from .. import repo -from ..paper import NoDocumentFile from ..configs import config from ..uis import get_ui from .. import color -from .helpers import add_references_argument, parse_reference +#from .helpers import add_references_argument, parse_reference def parser(subparsers): @@ -13,7 +12,8 @@ def parser(subparsers): help='open the paper in a pdf viewer') parser.add_argument('-w', '--with', dest='with_command', default=None, help='command to use to open the document file') - add_references_argument(parser, single=True) + parser.add_argument('citekey', + help='citekey of the paper') return parser @@ -21,23 +21,24 @@ def command(args): ui = get_ui() with_command = args.with_command - reference = args.reference + citekey = args.citekey rp = repo.Repository(config()) - key = parse_reference(rp, reference) - paper = rp.get_paper(key) + paper = rp.pull_paper(citekey) if with_command is None: with_command = config().open_cmd + + if paper.docpath is None: + ui.error('No document associated with the entry {}.'.format( + color.dye(citekey, color.citekey))) + ui.exit() + try: - filepath = paper.get_document_path() + docpath = rp.databroker.real_docpath(paper.docpath) cmd = with_command.split() - cmd.append(filepath) + cmd.append(docpath) subprocess.Popen(cmd) - ui.print_('{} opened.'.format(color.dye(filepath, color.filepath))) - except NoDocumentFile: - ui.error('No document associated with the entry {}.'.format( - color.dye(key, color.citekey))) - ui.exit() + ui.print_('{} opened.'.format(color.dye(docpath, color.filepath))) except OSError: ui.error("Command does not exist: %s." % with_command) ui.exit(127) diff --git a/papers/papers_cmd.py b/papers/papers_cmd.py index ea0c67b..58e0f6c 100644 --- a/papers/papers_cmd.py +++ b/papers/papers_cmd.py @@ -16,12 +16,12 @@ CORE_CMDS = collections.OrderedDict([ ('init', commands.init_cmd), ('add', commands.add_cmd), ('list', commands.list_cmd), + ('open', commands.open_cmd), + ('websearch', commands.websearch_cmd), # ('import', commands.import_cmd), # ('export', commands.export_cmd), # ('edit', commands.edit_cmd), # ('remove', commands.remove_cmd), - # ('open', commands.open_cmd), - # ('websearch', commands.websearch_cmd), # ('tag', commands.tag_cmd), # ('attach', commands.attach_cmd), # ('update', commands.update_cmd),