Updated texnote, not working yet
Add a check_directory in files.py
This commit is contained in:
parent
073d03e2fb
commit
ebff1bb4e4
@ -63,6 +63,17 @@ def name_from_path(fullpdfpath, verbose=False):
|
|||||||
return name, ext
|
return name, ext
|
||||||
|
|
||||||
|
|
||||||
|
def check_directory(path, fail=False):
|
||||||
|
if fail:
|
||||||
|
if not os.path.exists(path):
|
||||||
|
raise IOError("File does not exist: {}.".format(path))
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
raise IOError("{} is not a directory.".format(path))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return os.path.exists(path) and os.path.isdir(path)
|
||||||
|
|
||||||
|
|
||||||
def check_file(path, fail=False):
|
def check_file(path, fail=False):
|
||||||
if fail:
|
if fail:
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import importlib
|
import importlib
|
||||||
from .configs import config
|
|
||||||
|
|
||||||
PLUGIN_NAMESPACE = 'plugs'
|
PLUGIN_NAMESPACE = 'plugs'
|
||||||
|
|
||||||
@ -36,7 +35,6 @@ class PapersPlugin(object):
|
|||||||
This is a basic example
|
This is a basic example
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ui = args.ui
|
|
||||||
strings = args.strings
|
strings = args.strings
|
||||||
|
|
||||||
for s in strings:
|
for s in strings:
|
||||||
@ -58,7 +56,6 @@ def load_plugins(ui, names):
|
|||||||
"""
|
"""
|
||||||
for name in names:
|
for name in names:
|
||||||
modname = '%s.%s.%s.%s' % ('papers', PLUGIN_NAMESPACE, name, name)
|
modname = '%s.%s.%s.%s' % ('papers', PLUGIN_NAMESPACE, name, name)
|
||||||
#try:
|
|
||||||
try:
|
try:
|
||||||
namespace = importlib.import_module(modname)
|
namespace = importlib.import_module(modname)
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
@ -74,9 +71,6 @@ def load_plugins(ui, names):
|
|||||||
_classes.append(obj)
|
_classes.append(obj)
|
||||||
_instances[obj] = obj()
|
_instances[obj] = obj()
|
||||||
|
|
||||||
#except:
|
|
||||||
# ui.warning('error loading plugin {}'.format(name))
|
|
||||||
|
|
||||||
|
|
||||||
def get_plugins():
|
def get_plugins():
|
||||||
return _instances
|
return _instances
|
||||||
|
35
papers/plugs/texnote/template.tex
Normal file
35
papers/plugs/texnote/template.tex
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
\documentclass{article}
|
||||||
|
|
||||||
|
\usepackage{amsmath}
|
||||||
|
\usepackage{amsfonts}
|
||||||
|
\usepackage{amssymb}
|
||||||
|
|
||||||
|
\usepackage{algorithm}
|
||||||
|
\usepackage{algorithmic}
|
||||||
|
|
||||||
|
\usepackage{graphics}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
|
||||||
|
\usepackage{hyperref}
|
||||||
|
\usepackage{verbatim}
|
||||||
|
\usepackage{url}
|
||||||
|
|
||||||
|
\usepackage{caption}
|
||||||
|
\usepackage{subcaption}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\Large{\textbf{TITLE}} \\ [0.2cm]
|
||||||
|
\small{\textsc{AUTHOR}} \\ [0.2cm]
|
||||||
|
\normalsize{\textsc{YEAR}} \\ [1cm]
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
\begin{abstract}
|
||||||
|
ABSTRACT
|
||||||
|
\end{abstract}
|
||||||
|
|
||||||
|
\section{Notes}
|
||||||
|
Write your notes here.
|
||||||
|
|
||||||
|
\end{document}
|
@ -11,57 +11,73 @@ from ...commands.helpers import add_references_argument, parse_reference
|
|||||||
|
|
||||||
from ...events import RemoveEvent
|
from ...events import RemoveEvent
|
||||||
|
|
||||||
TEXNOTE_PARSER_NAME = 'texnote'
|
|
||||||
TEXNOTE_SECTION = 'texnote'
|
TEXNOTE_SECTION = 'texnote'
|
||||||
TEXNOTE_SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'note_sample.tex')
|
TEXNOTE_DIR = os.path.join(config().papers_dir, 'texnote')
|
||||||
TEXNOTE_DIR = 'texnote'
|
TEXNOTE_TEMPLATE = os.path.join(TEXNOTE_DIR, 'template.tex')
|
||||||
|
TEXNOTE_STYLE = os.path.join(TEXNOTE_DIR, 'style.sty')
|
||||||
|
|
||||||
|
TEXNOTE_DEFAULT_TEMPLATE = os.path.join(os.path.dirname(__file__), 'template.tex')
|
||||||
|
TEXNOTE_DEFAULT_STYLE = os.path.join(os.path.dirname(__file__), 'style.sty')
|
||||||
|
|
||||||
|
|
||||||
class TexnotePlugin(PapersPlugin):
|
class TexnotePlugin(PapersPlugin):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = TEXNOTE_PARSER_NAME
|
self.name = TEXNOTE_SECTION
|
||||||
|
if not files.check_directory(TEXNOTE_DIR):
|
||||||
#self.rp = repo.Repository(config())
|
os.mkdir(TEXNOTE_DIR)
|
||||||
|
if not files.check_file(TEXNOTE_TEMPLATE):
|
||||||
|
shutil.copy(TEXNOTE_DEFAULT_TEMPLATE, TEXNOTE_TEMPLATE)
|
||||||
|
if not files.check_file(TEXNOTE_STYLE):
|
||||||
|
shutil.copy(TEXNOTE_DEFAULT_STYLE, TEXNOTE_STYLE)
|
||||||
|
|
||||||
self.texcmds = collections.OrderedDict([
|
self.texcmds = collections.OrderedDict([
|
||||||
('remove', self.remove),
|
('remove', self.remove),
|
||||||
('edit', self.edit),
|
('edit', self.edit),
|
||||||
|
('edit_style', self.edit_style),
|
||||||
|
('edit_template', self.edit_template),
|
||||||
])
|
])
|
||||||
|
|
||||||
def parser(self, subparsers):
|
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")
|
# remove
|
||||||
|
p = sub.add_parser('remove', help='remove a reference')
|
||||||
add_references_argument(p, single=True)
|
add_references_argument(p, single=True)
|
||||||
p = sub.add_parser("edit", help="edit the reference texnote")
|
# edit
|
||||||
|
p = sub.add_parser('edit', help='edit the reference texnote')
|
||||||
|
p.add_argument('-v', '--view', action='store_true',
|
||||||
|
help='open the paper in a pdf viewer', default=None)
|
||||||
add_references_argument(p, single=True)
|
add_references_argument(p, single=True)
|
||||||
#add_references_argument(parser, single=True)
|
# edit_style
|
||||||
p.add_argument('-v', '--view', action='store_true', help='open the paper in a pdf viewer', default=None)
|
p = sub.add_parser('edit_style', help='edit the latex style used by texnote')
|
||||||
|
#edit_template
|
||||||
|
p = sub.add_parser('edit_template', help='edit the latex template used by texnote')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def command(self, args):
|
def command(self, args):
|
||||||
|
|
||||||
texcmd = args.texcmd
|
texcmd = args.texcmd
|
||||||
del args.texcmd
|
del args.texcmd
|
||||||
|
self.texcmds[texcmd](**vars(args))
|
||||||
|
|
||||||
self.texcmds[texcmd](args)
|
def remove(self, ui, reference):
|
||||||
|
rp = repo.Repository(config())
|
||||||
|
key = parse_reference(ui, rp, reference)
|
||||||
|
print('Should remove {}'.format(key))
|
||||||
|
|
||||||
def remove(self, args):
|
def edit(self, ui, reference, view=None):
|
||||||
reference = args.reference
|
print('Should edit {}'.format(reference))
|
||||||
print('Should remove {}'.format(reference))
|
|
||||||
|
|
||||||
|
|
||||||
def edit(self, args):
|
|
||||||
reference = args.reference
|
|
||||||
view = args.view
|
|
||||||
|
|
||||||
print('Should remove {}'.format(reference))
|
|
||||||
if view is not None:
|
if view is not None:
|
||||||
subprocess.Popen(['papers', 'open', reference])
|
subprocess.Popen(['papers', 'open', reference])
|
||||||
|
|
||||||
#open_texnote(ui, reference)
|
#open_texnote(ui, reference)
|
||||||
|
|
||||||
|
def edit_style(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def edit_template(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def toto(self):
|
def toto(self):
|
||||||
print "toto"
|
print "toto"
|
||||||
|
|
||||||
@ -73,7 +89,7 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
@RemoveEvent.listen()
|
@RemoveEvent.listen()
|
||||||
def remove(rmevent):
|
def remove(rmevent):
|
||||||
texplug = TexnotePlugin.get_instance()
|
texplug = TexnotePlugin.get_instance()
|
||||||
texplug.toto()
|
texplug.remove(rmevent.ui, rmevent.citekey)
|
||||||
# HACK : transfer repo via RemoveEvent, do not recreate one
|
# HACK : transfer repo via RemoveEvent, do not recreate one
|
||||||
#rp = repo.Repository(config())
|
#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))
|
||||||
@ -112,7 +128,7 @@ def open_texnote(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
|
||||||
edit_cmd = config(TEXTNOTE_SECTION).get('edit_cmd', config().edit_cmd)
|
edit_cmd = config(TEXNOTE_SECTION).get('edit_cmd', config().edit_cmd)
|
||||||
subprocess.Popen([edit_cmd, texnote_path])
|
subprocess.Popen([edit_cmd, texnote_path])
|
||||||
|
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -10,7 +10,7 @@ setup(name='papers',
|
|||||||
description='research papers manager',
|
description='research papers manager',
|
||||||
requires=['pybtex'],
|
requires=['pybtex'],
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
package_data={'': ['*.tex']},
|
package_data={'': ['*.tex', '*.sty']},
|
||||||
scripts=['papers/papers']
|
scripts=['papers/papers']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user