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):
|
class AddEvent(PaperEvent):
|
||||||
_format = "Added paper {citekey}."
|
_format = "Adds paper {citekey}."
|
||||||
|
|
||||||
|
|
||||||
|
class DocAddEvent(PaperEvent):
|
||||||
|
_format = "Adds document {citekey}."
|
||||||
|
|
||||||
|
|
||||||
class RemoveEvent(PaperEvent):
|
class RemoveEvent(PaperEvent):
|
||||||
_format = "Removes paper {citekey}."
|
_format = "Removes paper {citekey}."
|
||||||
|
|
||||||
|
|
||||||
|
class DocRemoveEvent(PaperEvent):
|
||||||
|
_format = "Removes document {citekey}."
|
||||||
|
|
||||||
|
|
||||||
class ModifyEvent(PaperEvent):
|
class ModifyEvent(PaperEvent):
|
||||||
_format = "Modifies paper {citekey}."
|
_format = "Modifies paper {citekey}."
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import subprocess
|
|||||||
from pipes import quote as shell_quote
|
from pipes import quote as shell_quote
|
||||||
|
|
||||||
from ...plugins import PapersPlugin
|
from ...plugins import PapersPlugin
|
||||||
from ...events import *
|
from ...events import PaperEvent, RenameEvent
|
||||||
|
|
||||||
|
|
||||||
class GitPlugin(PapersPlugin):
|
class GitPlugin(PapersPlugin):
|
||||||
@ -29,16 +29,9 @@ class GitPlugin(PapersPlugin):
|
|||||||
|
|
||||||
@PaperEvent.listen()
|
@PaperEvent.listen()
|
||||||
def git_commit_event(PaperEventInstance):
|
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
|
# Stage the changes and commit
|
||||||
git = GitPlugin.get_instance()
|
git = GitPlugin.get_instance()
|
||||||
if old_citekey:
|
if isinstance(PaperEventInstance, RenameEvent):
|
||||||
git.shell("add \*/{}.\*".format(old_citekey))
|
git.shell("add \*/{}.\*".format(PaperEventInstance.old_citekey))
|
||||||
git.shell("add \*/{}.\*".format(citekey))
|
git.shell("add \*/{}.\*".format(PaperEventInstance.citekey))
|
||||||
git.shell('commit -m "{}"'.format(PaperEventInstance.description))
|
git.shell('commit -m "{}"'.format(PaperEventInstance.description))
|
||||||
|
@ -126,6 +126,7 @@ class Repository(object):
|
|||||||
p = self.pull_paper(citekey)
|
p = self.pull_paper(citekey)
|
||||||
p.docpath = None
|
p.docpath = None
|
||||||
self.push_paper(p, overwrite=True, event=False)
|
self.push_paper(p, overwrite=True, event=False)
|
||||||
|
events.DocRemoveEvent(citekey).send()
|
||||||
except IOError:
|
except IOError:
|
||||||
# FIXME: if IOError is about being unable to
|
# FIXME: if IOError is about being unable to
|
||||||
# remove the file, we need to issue an error.I
|
# remove the file, we need to issue an error.I
|
||||||
@ -191,6 +192,7 @@ class Repository(object):
|
|||||||
docfile = system_path(docfile)
|
docfile = system_path(docfile)
|
||||||
p.docpath = docfile
|
p.docpath = docfile
|
||||||
self.push_paper(p, overwrite=True, event=False)
|
self.push_paper(p, overwrite=True, event=False)
|
||||||
|
events.DocAddEvent(citekey).send()
|
||||||
|
|
||||||
def unique_citekey(self, base_key, bibentry):
|
def unique_citekey(self, base_key, bibentry):
|
||||||
"""Create a unique citekey for a given base key.
|
"""Create a unique citekey for a given base key.
|
||||||
|
@ -130,3 +130,4 @@ You can access the self-documented configuration by using `pubs conf`, and all t
|
|||||||
- [Dennis Wilson](https://github.com/d9w)
|
- [Dennis Wilson](https://github.com/d9w)
|
||||||
- [Bill Flynn](https://github.com/wflynny)
|
- [Bill Flynn](https://github.com/wflynny)
|
||||||
- [ksunden](https://github.com/ksunden)
|
- [ksunden](https://github.com/ksunden)
|
||||||
|
- [Amlesh Sivanantham](http://zamlz.org)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user