Created a doc add/rm event
This commit is contained in:
parent
b411bd16d8
commit
4a61f91cb5
@ -37,13 +37,21 @@ class PaperEvent(Event):
|
||||
|
||||
|
||||
class AddEvent(PaperEvent):
|
||||
_format = "Added paper {citekey}."
|
||||
_format = "Adds paper {citekey}."
|
||||
|
||||
|
||||
class DocAddEvent(PaperEvent):
|
||||
_format = "Adds document {citekey}."
|
||||
|
||||
|
||||
class RemoveEvent(PaperEvent):
|
||||
_format = "Removes paper {citekey}."
|
||||
|
||||
|
||||
class DocRemoveEvent(PaperEvent):
|
||||
_format = "Removes document {citekey}."
|
||||
|
||||
|
||||
class ModifyEvent(PaperEvent):
|
||||
_format = "Modifies paper {citekey}."
|
||||
|
||||
|
@ -3,7 +3,7 @@ import subprocess
|
||||
from pipes import quote as shell_quote
|
||||
|
||||
from ...plugins import PapersPlugin
|
||||
from ...events import *
|
||||
from ...events import PaperEvent, RenameEvent
|
||||
|
||||
|
||||
class GitPlugin(PapersPlugin):
|
||||
@ -29,16 +29,9 @@ class GitPlugin(PapersPlugin):
|
||||
|
||||
@PaperEvent.listen()
|
||||
def git_commit_event(PaperEventInstance):
|
||||
citekey = PaperEventInstance.citekey
|
||||
|
||||
if isinstance(PaperEventInstance, RenameEvent):
|
||||
old_citekey = RenameEventInstance.old_citekey
|
||||
else:
|
||||
old_citekey = None
|
||||
|
||||
# Stage the changes and commit
|
||||
git = GitPlugin.get_instance()
|
||||
if old_citekey:
|
||||
git.shell("add \*/{}.\*".format(old_citekey))
|
||||
git.shell("add \*/{}.\*".format(citekey))
|
||||
if isinstance(PaperEventInstance, RenameEvent):
|
||||
git.shell("add \*/{}.\*".format(PaperEventInstance.old_citekey))
|
||||
git.shell("add \*/{}.\*".format(PaperEventInstance.citekey))
|
||||
git.shell('commit -m "{}"'.format(PaperEventInstance.description))
|
||||
|
@ -126,6 +126,7 @@ class Repository(object):
|
||||
p = self.pull_paper(citekey)
|
||||
p.docpath = None
|
||||
self.push_paper(p, overwrite=True, event=False)
|
||||
events.DocRemoveEvent(citekey).send()
|
||||
except IOError:
|
||||
# FIXME: if IOError is about being unable to
|
||||
# remove the file, we need to issue an error.I
|
||||
@ -191,6 +192,7 @@ class Repository(object):
|
||||
docfile = system_path(docfile)
|
||||
p.docpath = docfile
|
||||
self.push_paper(p, overwrite=True, event=False)
|
||||
events.DocAddEvent(citekey).send()
|
||||
|
||||
def unique_citekey(self, base_key, bibentry):
|
||||
"""Create a unique citekey for a given base key.
|
||||
|
Loading…
x
Reference in New Issue
Block a user