pubs/papers/commands/open_cmd.py
Olivier Mangin 2d700073a8 Improves document handling.
- configuration is now referenced in repo object,
- introduces new class PaperInRepo,
- simplifies storage of documents in metadata,
- changes a few names.
2013-02-21 16:48:32 +01:00

27 lines
865 B
Python

import subprocess
from ..color import colored
from .. import repo
from ..paper import NoDocumentFile
def parser(subparsers, config):
parser = subparsers.add_parser('open',
help=colored('open the paper in a pdf viewer', 'normal'))
parser.add_argument('citekey',
help=colored('the paper associated citekey', 'normal'))
return parser
def command(config, ui, citekey):
rp = repo.Repository.from_directory()
paper = rp.paper_from_ref(citekey, fatal=True)
try:
filepath = paper.get_document_path()
subprocess.Popen([config.get('papers', 'open-cmd'), filepath])
print("%s opened." % colored(filepath, 'filepath'))
except NoDocumentFile:
print("%s: No document associated to this entry %s."
% (colored('error', 'error'), colored(citekey, 'citekey')))
exit(-1)