Adds handling of the case where no document file is defined.
This commit is contained in:
parent
443329d7cf
commit
2d57a2080c
@ -2,6 +2,7 @@ import subprocess
|
|||||||
|
|
||||||
from .. import color
|
from .. import color
|
||||||
from .. import repo
|
from .. import repo
|
||||||
|
from ..paper import NoDocumentFile
|
||||||
|
|
||||||
def parser(subparsers, config):
|
def parser(subparsers, config):
|
||||||
parser = subparsers.add_parser('open', help='{}open the paper in a pdf viewer{}'.format(color.normal, color.end))
|
parser = subparsers.add_parser('open', help='{}open the paper in a pdf viewer{}'.format(color.normal, color.end))
|
||||||
@ -11,7 +12,15 @@ def parser(subparsers, config):
|
|||||||
def command(config, citekey):
|
def command(config, citekey):
|
||||||
rp = repo.Repository()
|
rp = repo.Repository()
|
||||||
paper = rp.paper_from_any(citekey, fatal = True)
|
paper = rp.paper_from_any(citekey, fatal = True)
|
||||||
filepath = paper.metadata['path']
|
try:
|
||||||
|
if paper.check_file():
|
||||||
|
filepath = paper.get_file_path()
|
||||||
|
|
||||||
p = subprocess.Popen(['open', filepath])
|
p = subprocess.Popen(['open', filepath])
|
||||||
print('{}{}{} opened.{}'.format(color.filepath, filepath, color.normal, color.end))
|
print('{}{}{} opened.{}'.format(
|
||||||
|
color.filepath, filepath, color.normal, color.end))
|
||||||
|
except NoDocumentFile:
|
||||||
|
print('{}error{}: No document associated to this entry {}{}{}'.format(
|
||||||
|
color.error, color.normal, color.citekey, citekey, color.end))
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user