Merge branch 'develop' of gmimosa:/gitroot/mimosa/papers into develop
This commit is contained in:
commit
bd591bbdc3
@ -29,7 +29,9 @@ def command(args):
|
|||||||
with_command = config().open_cmd
|
with_command = config().open_cmd
|
||||||
try:
|
try:
|
||||||
filepath = paper.get_document_path()
|
filepath = paper.get_document_path()
|
||||||
subprocess.Popen([with_command, filepath])
|
cmd = with_command.split()
|
||||||
|
cmd.append(filepath)
|
||||||
|
subprocess.Popen(cmd)
|
||||||
ui.print_('{} opened.'.format(color.dye(filepath, color.filepath)))
|
ui.print_('{} opened.'.format(color.dye(filepath, color.filepath)))
|
||||||
except NoDocumentFile:
|
except NoDocumentFile:
|
||||||
ui.error('No document associated with the entry {}.'.format(
|
ui.error('No document associated with the entry {}.'.format(
|
||||||
|
@ -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):
|
||||||
@ -151,7 +162,7 @@ def _parse_bibdata_formated_stream(stream, fmt):
|
|||||||
pass
|
pass
|
||||||
raise ValueError('content format is not recognized.')
|
raise ValueError('content format is not recognized.')
|
||||||
|
|
||||||
def parse_bibdata(content, format_ = None):
|
def parse_bibdata(content, format_=None):
|
||||||
"""Parse bib data from string or stream.
|
"""Parse bib data from string or stream.
|
||||||
|
|
||||||
Raise ValueError if no bibdata is present.
|
Raise ValueError if no bibdata is present.
|
||||||
@ -188,7 +199,9 @@ def editor_input(editor, initial="", suffix=None):
|
|||||||
tfile_name = temp_file.name
|
tfile_name = temp_file.name
|
||||||
temp_file.write(initial)
|
temp_file.write(initial)
|
||||||
temp_file.flush()
|
temp_file.flush()
|
||||||
subprocess.call([editor, tfile_name])
|
cmd = editor.split() # this enable editor command with option, e.g. gvim -f
|
||||||
|
cmd.append(tfile_name)
|
||||||
|
subprocess.call(cmd)
|
||||||
with open(tfile_name) as temp_file:
|
with open(tfile_name) as temp_file:
|
||||||
content = temp_file.read()
|
content = temp_file.read()
|
||||||
os.remove(tfile_name)
|
os.remove(tfile_name)
|
||||||
|
@ -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}
|
@ -1,46 +1,82 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import collections
|
||||||
|
|
||||||
from ... import repo
|
from ... import repo
|
||||||
from ...configs import config
|
|
||||||
from ... import files
|
from ... import files
|
||||||
|
from ...configs import config
|
||||||
from ...plugins import PapersPlugin
|
from ...plugins import PapersPlugin
|
||||||
from ...commands.helpers import add_references_argument, parse_reference
|
from ...commands.helpers import add_references_argument, parse_reference
|
||||||
|
|
||||||
from ...events import RemoveEvent
|
from ...events import RemoveEvent
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
|
self.name = TEXNOTE_SECTION
|
||||||
|
if not files.check_directory(TEXNOTE_DIR):
|
||||||
|
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([
|
||||||
|
('remove', self.remove),
|
||||||
|
('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
|
||||||
parser.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):
|
||||||
|
|
||||||
ui = args.ui
|
|
||||||
texcmd = args.texcmd
|
texcmd = args.texcmd
|
||||||
reference = args.reference
|
del args.texcmd
|
||||||
view = args.view
|
self.texcmds[texcmd](**vars(args))
|
||||||
|
|
||||||
|
def remove(self, ui, reference):
|
||||||
|
rp = repo.Repository(config())
|
||||||
|
key = parse_reference(ui, rp, reference)
|
||||||
|
print('Should remove {}'.format(key))
|
||||||
|
|
||||||
|
def edit(self, ui, reference, view=None):
|
||||||
|
print('Should edit {}'.format(reference))
|
||||||
if view is not None:
|
if view is not None:
|
||||||
subprocess.Popen(['papers', 'open', reference])
|
subprocess.Popen(['papers', 'open', reference])
|
||||||
if texcmd == 'edit':
|
|
||||||
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"
|
||||||
@ -53,18 +89,18 @@ 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))
|
||||||
if 'texnote' in paper.metadata:
|
#if 'texnote' in paper.metadata:
|
||||||
try:
|
# try:
|
||||||
os.remove(paper.metadata['texnote'])
|
# os.remove(paper.metadata['texnote'])
|
||||||
except OSError:
|
# except OSError:
|
||||||
pass # For some reason, the texnote file didn't exist
|
# pass # For some reason, the texnote file didn't exist
|
||||||
paper.metadata.pop('texnote')
|
# paper.metadata.pop('texnote')
|
||||||
metapath = rp.path_to_paper_file(paper.citekey, 'meta')
|
# metapath = rp.path_to_paper_file(paper.citekey, 'meta')
|
||||||
files.save_meta(paper.metadata, metapath)
|
# files.save_meta(paper.metadata, metapath)
|
||||||
|
|
||||||
|
|
||||||
def open_texnote(ui, ref):
|
def open_texnote(ui, ref):
|
||||||
@ -92,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