updated core. almost all tests are passing
This commit is contained in:
parent
e4f7017fdb
commit
f528aa8a67
@ -28,7 +28,6 @@ class Event(object):
|
|||||||
|
|
||||||
|
|
||||||
class RemoveEvent(Event):
|
class RemoveEvent(Event):
|
||||||
def __init__(self, config, ui, citekey):
|
def __init__(self, ui, citekey):
|
||||||
self.config = config
|
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.citekey = citekey
|
self.citekey = citekey
|
||||||
|
@ -28,11 +28,15 @@ cmds = collections.OrderedDict([
|
|||||||
|
|
||||||
|
|
||||||
def execute(raw_args = sys.argv):
|
def execute(raw_args = sys.argv):
|
||||||
config = configs.read_config()
|
# loading config
|
||||||
|
config = configs.Config()
|
||||||
|
config.load()
|
||||||
|
config.as_global()
|
||||||
|
|
||||||
ui = UI(config)
|
ui = UI(config)
|
||||||
|
|
||||||
# Extend with plugin commands
|
# Extend with plugin commands
|
||||||
plugin.load_plugins(config, ui, configs.get_plugins(config))
|
plugin.load_plugins(ui, config.plugins.split())
|
||||||
for p in plugin.get_plugins().values():
|
for p in plugin.get_plugins().values():
|
||||||
cmds.update(collections.OrderedDict([(p.name, p)]))
|
cmds.update(collections.OrderedDict([(p.name, p)]))
|
||||||
|
|
||||||
@ -40,10 +44,9 @@ def execute(raw_args = sys.argv):
|
|||||||
subparsers = parser.add_subparsers(title="valid commands", dest="command")
|
subparsers = parser.add_subparsers(title="valid commands", dest="command")
|
||||||
|
|
||||||
for cmd_mod in cmds.values():
|
for cmd_mod in cmds.values():
|
||||||
subparser = cmd_mod.parser(subparsers, config) # why do we return the subparser ?
|
subparser = cmd_mod.parser(subparsers) # why do we return the subparser ?
|
||||||
|
|
||||||
args = parser.parse_args(raw_args[1:])
|
args = parser.parse_args(raw_args[1:])
|
||||||
args.config = config
|
|
||||||
|
|
||||||
args.ui = ui
|
args.ui = ui
|
||||||
cmd = args.command
|
cmd = args.command
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import importlib
|
import importlib
|
||||||
|
from .configs import config
|
||||||
|
|
||||||
PLUGIN_NAMESPACE = 'plugs'
|
PLUGIN_NAMESPACE = 'plugs'
|
||||||
|
|
||||||
@ -11,20 +12,19 @@ class PapersPlugin(object):
|
|||||||
functionality by defining a subclass of PapersPlugin and overriding
|
functionality by defining a subclass of PapersPlugin and overriding
|
||||||
the abstract methods defined here.
|
the abstract methods defined here.
|
||||||
"""
|
"""
|
||||||
def __init__(self, config, ui):
|
def __init__(self, ui):
|
||||||
"""Perform one-time plugin setup.
|
"""Perform one-time plugin setup.
|
||||||
"""
|
"""
|
||||||
self.name = self.__module__.split('.')[-1]
|
self.name = self.__module__.split('.')[-1]
|
||||||
self.config = config
|
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
|
|
||||||
#config and ui and given again to stay consistent with the core papers cmd.
|
#ui and given again to stay consistent with the core papers cmd.
|
||||||
#two options:
|
#two options:
|
||||||
#- create specific cases in script papers/papers
|
#- create specific cases in script papers/papers
|
||||||
#- do not store self.config and self.ui and use them if needed when command is called
|
#- do not store self.ui and use them if needed when command is called
|
||||||
#this may end up with a lot of function with config/ui in argument
|
#this may end up with a lot of function with config/ui in argument
|
||||||
#or just keep it that way...
|
#or just keep it that way...
|
||||||
def parser(self, subparsers, config):
|
def parser(self, subparsers):
|
||||||
""" Should retrun the parser with plugins specific command.
|
""" Should retrun the parser with plugins specific command.
|
||||||
This is a basic example
|
This is a basic example
|
||||||
"""
|
"""
|
||||||
@ -32,7 +32,7 @@ class PapersPlugin(object):
|
|||||||
parser.add_argument('strings', nargs='*', help='the strings')
|
parser.add_argument('strings', nargs='*', help='the strings')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def command(self, config, ui, strings):
|
def command(self, ui, strings):
|
||||||
"""This function will be called with argument defined in the parser above
|
"""This function will be called with argument defined in the parser above
|
||||||
This is a basic example
|
This is a basic example
|
||||||
"""
|
"""
|
||||||
@ -47,7 +47,7 @@ class PapersPlugin(object):
|
|||||||
raise RuntimeError("{} instance not created".format(cls.__name__))
|
raise RuntimeError("{} instance not created".format(cls.__name__))
|
||||||
|
|
||||||
|
|
||||||
def load_plugins(config, ui, names):
|
def load_plugins(ui, names):
|
||||||
"""Imports the modules for a sequence of plugin names. Each name
|
"""Imports the modules for a sequence of plugin names. Each name
|
||||||
must be the name of a Python module under the "PLUGIN_NAMESPACE" namespace
|
must be the name of a Python module under the "PLUGIN_NAMESPACE" namespace
|
||||||
package in sys.path; the module indicated should contain the
|
package in sys.path; the module indicated should contain the
|
||||||
@ -69,7 +69,7 @@ def load_plugins(config, ui, names):
|
|||||||
if isinstance(obj, type) and issubclass(obj, PapersPlugin) \
|
if isinstance(obj, type) and issubclass(obj, PapersPlugin) \
|
||||||
and obj != PapersPlugin:
|
and obj != PapersPlugin:
|
||||||
_classes.append(obj)
|
_classes.append(obj)
|
||||||
_instances[obj] = obj(config, ui)
|
_instances[obj] = obj(ui)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
ui.warning('error loading plugin {}'.format(name))
|
ui.warning('error loading plugin {}'.format(name))
|
||||||
|
@ -3,7 +3,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from ... import repo
|
from ... import repo
|
||||||
from ... import configs
|
from ...configs import config
|
||||||
from ... import files
|
from ... import files
|
||||||
from ...plugin import PapersPlugin
|
from ...plugin import PapersPlugin
|
||||||
from ...commands.helpers import add_references_argument, parse_reference
|
from ...commands.helpers import add_references_argument, parse_reference
|
||||||
@ -18,7 +18,7 @@ TEXNOTE_DIR = 'texnote'
|
|||||||
|
|
||||||
class TexnotePlugin(PapersPlugin):
|
class TexnotePlugin(PapersPlugin):
|
||||||
|
|
||||||
def parser(self, subparsers, config):
|
def parser(self, subparsers):
|
||||||
parser = subparsers.add_parser(self.name, help="edit advance note in latex")
|
parser = subparsers.add_parser(self.name, help="edit advance note in latex")
|
||||||
sub = parser.add_subparsers(title="valid texnote commands", dest="texcmd")
|
sub = parser.add_subparsers(title="valid texnote commands", dest="texcmd")
|
||||||
p = sub.add_parser("remove", help="remove a reference")
|
p = sub.add_parser("remove", help="remove a reference")
|
||||||
@ -29,11 +29,11 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
parser.add_argument('-v', '--view', action='store_true', help='open the paper in a pdf viewer', default=None)
|
parser.add_argument('-v', '--view', action='store_true', help='open the paper in a pdf viewer', default=None)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def command(self, config, ui, texcmd, reference, view):
|
def command(self, ui, texcmd, reference, view):
|
||||||
if view is not None:
|
if view is not None:
|
||||||
subprocess.Popen(['papers', 'open', reference])
|
subprocess.Popen(['papers', 'open', reference])
|
||||||
if texcmd == 'edit':
|
if texcmd == 'edit':
|
||||||
open_texnote(config, ui, reference)
|
open_texnote(ui, reference)
|
||||||
|
|
||||||
def toto(self):
|
def toto(self):
|
||||||
print "toto"
|
print "toto"
|
||||||
@ -47,7 +47,8 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
def remove(rmevent):
|
def remove(rmevent):
|
||||||
texplug = TexnotePlugin.get_instance()
|
texplug = TexnotePlugin.get_instance()
|
||||||
texplug.toto()
|
texplug.toto()
|
||||||
rp = repo.Repository.from_directory(rmevent.config)
|
# HACK : transfer repo via RemoveEvent, do not recreate one
|
||||||
|
rp = repo.Repository(config())
|
||||||
paper = rp.get_paper(parse_reference(rmevent.ui, rp, rmevent.citekey))
|
paper = rp.get_paper(parse_reference(rmevent.ui, rp, rmevent.citekey))
|
||||||
if 'texnote' in paper.metadata:
|
if 'texnote' in paper.metadata:
|
||||||
try:
|
try:
|
||||||
@ -59,8 +60,9 @@ def remove(rmevent):
|
|||||||
files.save_meta(paper.metadata, metapath)
|
files.save_meta(paper.metadata, metapath)
|
||||||
|
|
||||||
|
|
||||||
def open_texnote(config, ui, ref):
|
def open_texnote(ui, ref):
|
||||||
rp = repo.Repository.from_directory(config)
|
# HACK : transfer repo via arguments, do not recreate one
|
||||||
|
rp = repo.Repository(config())
|
||||||
paper = rp.get_paper(parse_reference(ui, rp, ref))
|
paper = rp.get_paper(parse_reference(ui, rp, ref))
|
||||||
|
|
||||||
#ugly to recode like for the doc field
|
#ugly to recode like for the doc field
|
||||||
@ -83,12 +85,8 @@ def open_texnote(config, ui, ref):
|
|||||||
autofill_texnote(texnote_path, paper.bibentry)
|
autofill_texnote(texnote_path, paper.bibentry)
|
||||||
|
|
||||||
#open the file using the config editor
|
#open the file using the config editor
|
||||||
if config.has_option(TEXNOTE_SECTION, 'edit-cmd'):
|
edit_cmd = config(TEXTNOTE_SECTION).get('edit_cmd', config().edit_cmd)
|
||||||
#os.system(config.get(TEXNOTE_SECTION, 'edit-cmd') + ' ' + texnote_path + " &")
|
subprocess.Popen([edit_cmd, texnote_path])
|
||||||
subprocess.Popen([config.get(TEXNOTE_SECTION, 'edit-cmd'), texnote_path])
|
|
||||||
else:
|
|
||||||
#os.system(config.get(configs.MAIN_SECTION, 'edit-cmd') + ' ' + texnote_path + " &")
|
|
||||||
subprocess.Popen([config.get(configs.MAIN_SECTION, 'edit-cmd'), texnote_path])
|
|
||||||
|
|
||||||
|
|
||||||
##### ugly replace by proper #####
|
##### ugly replace by proper #####
|
||||||
|
@ -3,8 +3,6 @@ import sys
|
|||||||
from .beets_ui import _encoding, input_
|
from .beets_ui import _encoding, input_
|
||||||
|
|
||||||
from . import color
|
from . import color
|
||||||
from . import configs
|
|
||||||
|
|
||||||
|
|
||||||
class UI:
|
class UI:
|
||||||
"""UI class. Stores configuration parameters and system information.
|
"""UI class. Stores configuration parameters and system information.
|
||||||
@ -12,8 +10,7 @@ class UI:
|
|||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.encoding = _encoding(config)
|
self.encoding = _encoding(config)
|
||||||
color_enable = configs.get_boolean(config.get('papers', 'color'))
|
color.setup(config.color)
|
||||||
color.setup(color_enable)
|
|
||||||
|
|
||||||
def print_(self, *strings):
|
def print_(self, *strings):
|
||||||
"""Like print, but rather than raising an error when a character
|
"""Like print, but rather than raising an error when a character
|
||||||
|
Loading…
x
Reference in New Issue
Block a user