updated open and websearch commands

main
Fabien Benureau 11 years ago
parent 017a31460d
commit da3e70649b

@ -1,12 +1,12 @@
import init_cmd import init_cmd
import add_cmd import add_cmd
import list_cmd import list_cmd
import open_cmd
import websearch_cmd
# import import_cmd # import import_cmd
# import export_cmd # import export_cmd
# import edit_cmd # import edit_cmd
# import remove_cmd # import remove_cmd
# import open_cmd
# import websearch_cmd
# import tag_cmd # import tag_cmd
# import attach_cmd # import attach_cmd
# import update_cmd # import update_cmd

@ -1,11 +1,10 @@
import subprocess import subprocess
from .. import repo from .. import repo
from ..paper import NoDocumentFile
from ..configs import config from ..configs import config
from ..uis import get_ui from ..uis import get_ui
from .. import color from .. import color
from .helpers import add_references_argument, parse_reference #from .helpers import add_references_argument, parse_reference
def parser(subparsers): def parser(subparsers):
@ -13,7 +12,8 @@ def parser(subparsers):
help='open the paper in a pdf viewer') help='open the paper in a pdf viewer')
parser.add_argument('-w', '--with', dest='with_command', default=None, parser.add_argument('-w', '--with', dest='with_command', default=None,
help='command to use to open the document file') 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 return parser
@ -21,23 +21,24 @@ def command(args):
ui = get_ui() ui = get_ui()
with_command = args.with_command with_command = args.with_command
reference = args.reference citekey = args.citekey
rp = repo.Repository(config()) rp = repo.Repository(config())
key = parse_reference(rp, reference) paper = rp.pull_paper(citekey)
paper = rp.get_paper(key)
if with_command is None: if with_command is None:
with_command = config().open_cmd 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: try:
filepath = paper.get_document_path() docpath = rp.databroker.real_docpath(paper.docpath)
cmd = with_command.split() cmd = with_command.split()
cmd.append(filepath) cmd.append(docpath)
subprocess.Popen(cmd) subprocess.Popen(cmd)
ui.print_('{} opened.'.format(color.dye(filepath, color.filepath))) ui.print_('{} opened.'.format(color.dye(docpath, color.filepath)))
except NoDocumentFile:
ui.error('No document associated with the entry {}.'.format(
color.dye(key, color.citekey)))
ui.exit()
except OSError: except OSError:
ui.error("Command does not exist: %s." % with_command) ui.error("Command does not exist: %s." % with_command)
ui.exit(127) ui.exit(127)

@ -16,12 +16,12 @@ CORE_CMDS = collections.OrderedDict([
('init', commands.init_cmd), ('init', commands.init_cmd),
('add', commands.add_cmd), ('add', commands.add_cmd),
('list', commands.list_cmd), ('list', commands.list_cmd),
('open', commands.open_cmd),
('websearch', commands.websearch_cmd),
# ('import', commands.import_cmd), # ('import', commands.import_cmd),
# ('export', commands.export_cmd), # ('export', commands.export_cmd),
# ('edit', commands.edit_cmd), # ('edit', commands.edit_cmd),
# ('remove', commands.remove_cmd), # ('remove', commands.remove_cmd),
# ('open', commands.open_cmd),
# ('websearch', commands.websearch_cmd),
# ('tag', commands.tag_cmd), # ('tag', commands.tag_cmd),
# ('attach', commands.attach_cmd), # ('attach', commands.attach_cmd),
# ('update', commands.update_cmd), # ('update', commands.update_cmd),

Loading…
Cancel
Save