papers content was mostly moved to papers_cmd.py You can now use papers_cmd.execute('papers tag Page99'.split()) from the codemain
parent
bfa6eb58b7
commit
13bd18cda9
@ -1,50 +1,5 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
import papers_cmd
|
||||||
import argparse
|
papers_cmd.execute()
|
||||||
import collections
|
|
||||||
|
|
||||||
from papers.ui import UI
|
|
||||||
from papers import configs
|
|
||||||
from papers import commands
|
|
||||||
from papers import plugin
|
|
||||||
|
|
||||||
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
|
|
||||||
plugin.load_plugins(config, ui, configs.get_plugins(config))
|
|
||||||
for p in plugin.get_plugins().values():
|
|
||||||
cmds.update(collections.OrderedDict([(p.name, p)]))
|
|
||||||
#
|
|
||||||
|
|
||||||
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) # why do we return the subparser ?
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
args.config = config
|
|
||||||
args.ui = ui
|
|
||||||
cmd = args.command
|
|
||||||
del args.command
|
|
||||||
|
|
||||||
cmds[cmd].command(**vars(args))
|
|
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import collections
|
||||||
|
|
||||||
|
from .ui import UI
|
||||||
|
from . import configs
|
||||||
|
from . import commands
|
||||||
|
from . import plugin
|
||||||
|
|
||||||
|
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
|
||||||
|
plugin.load_plugins(config, ui, configs.get_plugins(config))
|
||||||
|
for p in plugin.get_plugins().values():
|
||||||
|
cmds.update(collections.OrderedDict([(p.name, p)]))
|
||||||
|
#
|
||||||
|
|
||||||
|
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) # why do we return the subparser ?
|
||||||
|
|
||||||
|
def execute(raw_args = sys.argv):
|
||||||
|
args = parser.parse_args(raw_args[1:])
|
||||||
|
args.config = config
|
||||||
|
args.ui = ui
|
||||||
|
cmd = args.command
|
||||||
|
del args.command
|
||||||
|
|
||||||
|
cmds[cmd].command(**vars(args))
|
@ -0,0 +1,36 @@
|
|||||||
|
import sys, os
|
||||||
|
import unittest
|
||||||
|
import pkgutil
|
||||||
|
|
||||||
|
import testenv
|
||||||
|
import fake_filesystem
|
||||||
|
|
||||||
|
import papers
|
||||||
|
from papers import papers_cmd
|
||||||
|
|
||||||
|
def create_fake_fs():
|
||||||
|
fake_fs = fake_filesystem.FakeFilesystem()
|
||||||
|
fake_os = fake_filesystem.FakeOsModule(fake_fs)
|
||||||
|
fake_open = fake_filesystem.FakeFileOpen(fake_fs)
|
||||||
|
fake_fs.CreateFile('/Users/fabien/bla')
|
||||||
|
__builtins__['open'] = fake_open
|
||||||
|
__builtins__['file'] = fake_open
|
||||||
|
|
||||||
|
for importer, modname, ispkg in pkgutil.walk_packages(path=papers.__path__,
|
||||||
|
prefix=papers.__name__+'.',
|
||||||
|
onerror=lambda x: None):
|
||||||
|
md = __import__(modname, fromlist = 'dummy')
|
||||||
|
md.os = fake_os
|
||||||
|
|
||||||
|
|
||||||
|
class TestUseCases(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
create_fake_fs()
|
||||||
|
papers_md.execute_papers('papers init -p paper_test2'.split())
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
create_fake_fs()
|
||||||
|
papers_cmd.execute('papers init -p paper_test2'.split())
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue