You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.0 KiB

import subprocess
from .. import color
from .. import repo
from ..paper import NoDocumentFile
12 years ago
def parser(subparsers, config):
parser = subparsers.add_parser('open', help='{}open the paper in a pdf viewer{}'.format(color.normal, color.end))
parser.add_argument('citekey', help='{}the paper associated citekey{}'.format(color.normal, color.end))
return parser
12 years ago
def command(config, citekey):
rp = repo.Repository.from_directory()
paper = rp.paper_from_any(citekey, fatal=True)
try:
if paper.check_file():
filepath = paper.get_file_path()
12 years ago
subprocess.Popen([config.get('papers', 'open-cmd'),
filepath])
print('{}{}{} opened.{}'.format(
color.filepath, filepath, color.normal, color.end))
else:
raise NoDocumentFile
except NoDocumentFile:
print('{}error{}: No document associated to this entry {}{}{}'.format(
color.error, color.normal, color.citekey, citekey, color.end))
exit(-1)