updated open and websearch commands
This commit is contained in:
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
|
||||||
try:
|
|
||||||
filepath = paper.get_document_path()
|
if paper.docpath is None:
|
||||||
cmd = with_command.split()
|
|
||||||
cmd.append(filepath)
|
|
||||||
subprocess.Popen(cmd)
|
|
||||||
ui.print_('{} opened.'.format(color.dye(filepath, color.filepath)))
|
|
||||||
except NoDocumentFile:
|
|
||||||
ui.error('No document associated with the entry {}.'.format(
|
ui.error('No document associated with the entry {}.'.format(
|
||||||
color.dye(key, color.citekey)))
|
color.dye(citekey, color.citekey)))
|
||||||
ui.exit()
|
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:
|
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…
x
Reference in New Issue
Block a user