updated open and websearch commands
This commit is contained in:
parent
017a31460d
commit
da3e70649b
@ -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
|
||||
|
@ -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
|
||||
try:
|
||||
filepath = paper.get_document_path()
|
||||
cmd = with_command.split()
|
||||
cmd.append(filepath)
|
||||
subprocess.Popen(cmd)
|
||||
ui.print_('{} opened.'.format(color.dye(filepath, color.filepath)))
|
||||
except NoDocumentFile:
|
||||
|
||||
if paper.docpath is None:
|
||||
ui.error('No document associated with the entry {}.'.format(
|
||||
color.dye(key, color.citekey)))
|
||||
color.dye(citekey, color.citekey)))
|
||||
ui.exit()
|
||||
|
||||
try:
|
||||
docpath = rp.databroker.real_docpath(paper.docpath)
|
||||
cmd = with_command.split()
|
||||
cmd.append(docpath)
|
||||
subprocess.Popen(cmd)
|
||||
ui.print_('{} opened.'.format(color.dye(docpath, color.filepath)))
|
||||
except OSError:
|
||||
ui.error("Command does not exist: %s." % with_command)
|
||||
ui.exit(127)
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user