From 4a61f91cb5bfc06c62ddba4e6ebcdb6f8f72e0dc Mon Sep 17 00:00:00 2001 From: "Amlesh Sivanantham (zamlz)" Date: Tue, 5 Mar 2019 11:33:35 -0800 Subject: [PATCH] Created a doc add/rm event --- pubs/events.py | 10 +++++++++- pubs/plugs/git/git.py | 15 ++++----------- pubs/repo.py | 2 ++ readme.md | 1 + 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pubs/events.py b/pubs/events.py index 3dfbc75..e498954 100644 --- a/pubs/events.py +++ b/pubs/events.py @@ -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}." diff --git a/pubs/plugs/git/git.py b/pubs/plugs/git/git.py index 82692c4..64642c7 100644 --- a/pubs/plugs/git/git.py +++ b/pubs/plugs/git/git.py @@ -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)) diff --git a/pubs/repo.py b/pubs/repo.py index 69ca1d7..4f67f3d 100644 --- a/pubs/repo.py +++ b/pubs/repo.py @@ -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. diff --git a/readme.md b/readme.md index 5b43e56..a66ffc1 100644 --- a/readme.md +++ b/readme.md @@ -130,3 +130,4 @@ You can access the self-documented configuration by using `pubs conf`, and all t - [Dennis Wilson](https://github.com/d9w) - [Bill Flynn](https://github.com/wflynny) - [ksunden](https://github.com/ksunden) +- [Amlesh Sivanantham](http://zamlz.org)