|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import collections
|
|
|
|
|
|
|
|
from papers.ui import UI
|
|
|
|
from papers import configs
|
|
|
|
from papers import commands
|
|
|
|
|
|
|
|
cmds = collections.OrderedDict([
|
|
|
|
('init', commands.init_cmd),
|
|
|
|
('add', commands.add_cmd),
|
|
|
|
('add_library', commands.add_library_cmd),
|
|
|
|
('import', commands.import_cmd),
|
|
|
|
('export', commands.export_cmd),
|
|
|
|
('list', commands.list_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),
|
|
|
|
])
|
|
|
|
|
|
|
|
config = configs.read_config()
|
|
|
|
ui = UI(config)
|
|
|
|
|
|
|
|
# Extend with plugin commands
|
|
|
|
plugs = configs.get_plugins(config)
|
|
|
|
for plugname in plugs:
|
|
|
|
module_name = 'papers.plugins.' + plugname + '.' + plugname + '_cmd'
|
|
|
|
plug = __import__(module_name, globals(), locals(),
|
|
|
|
['parser', 'command'], -1)
|
|
|
|
cmds.update(collections.OrderedDict([(plugname, plug)]))
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="research papers repository")
|
|
|
|
subparsers = parser.add_subparsers(title="valid commands", dest="command")
|
|
|
|
|
|
|
|
for cmd_mod in cmds.values():
|
|
|
|
subparser = cmd_mod.parser(subparsers, config)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
args.config = config
|
|
|
|
args.ui = ui
|
|
|
|
cmd = args.command
|
|
|
|
del args.command
|
|
|
|
|
|
|
|
cmds[cmd].command(**vars(args))
|