From 7f1d8395684b83cedc044bd0ff4d3fe82015563e Mon Sep 17 00:00:00 2001 From: "Amlesh Sivanantham (zamlz)" Date: Thu, 24 Jan 2019 18:13:49 -0800 Subject: [PATCH] Added placeholders for more events. Updated repo.py to use some of the new events. --- pubs/events.py | 22 ++++++++++++++++++++++ pubs/plugs/git/git.py | 37 ++++++++++++++++++++++++++++++++----- pubs/repo.py | 10 ++++++---- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/pubs/events.py b/pubs/events.py index 2c805e0..24666e0 100644 --- a/pubs/events.py +++ b/pubs/events.py @@ -39,3 +39,25 @@ class RenameEvent(Event): class AddEvent(Event): def __init__(self, citekey): self.citekey = citekey + + +class EditEvent(Event): + def __init__(self, citekey): + self.citekey = citekey + + +class TagEvent(Event): + def __init__(self, citekey): + self.citekey = citekey + + +class DocEvent(Event): + """possible actions: add, remove""" + def __init__(self, citekey, action): + self.citekey + self.action = action + + +class NoteEvent(Event): + def __init__(self, citekey, action): + self.citekey diff --git a/pubs/plugs/git/git.py b/pubs/plugs/git/git.py index 0fbf035..9c84c68 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 RemoveEvent, RenameEvent, AddEvent +from ...events import * class GitPlugin(PapersPlugin): @@ -45,16 +45,16 @@ def git_rename(RenameEventInstance): # Stage the changes and commit GitPlugin.shell("add \*/{}.\*".format(old_key)) GitPlugin.shell("add \*/{}.\*".format(new_key)) - GitPlugin.shell('commit -m "Renamed {} to {}"'.format(old_key, new_key)) + GitPlugin.shell('commit -m "Renamed citekey {} to {}"'.format(old_key, new_key)) @RemoveEvent.listen() def git_remove(RemoveEventInstance): - citekey = RemoveEventInstance.old_citekey + citekey = RemoveEventInstance.citekey # Stage the changes and commit GitPlugin.shell("add \*/{}.\*".format(citekey)) - GitPlugin.shell('commit -m "Removed {}"'.format(citekey)) + GitPlugin.shell('commit -m "Removed files for {}"'.format(citekey)) @AddEvent.listen() @@ -63,5 +63,32 @@ def git_add(AddEventInstance): # Stage the changes and commit GitPlugin.shell("add \*/{}.\*".format(citekey)) - GitPlugin.shell('commit -m "Added {}"'.format(citekey)) + GitPlugin.shell('commit -m "Added files for {}"'.format(citekey)) + + +@EditEvent.listen() +def git_edit(EditEventInstance): + pass + + +@TagEvent.listen() +def git_tag(TagEventInstance): + pass + + +@DocEvent.listen() +def git_doc(DocEventInstance): + citekey = DocEventInstance.citekey + + # Stage the changes and commit + GitPlugin.shell("add \*/{}.\*".format(citekey)) + if DocEventInstance.action == 'add': + GitPlugin.shell('commit -m "Added document for {}"'.format(citekey)) + elif DocEventInstance.action == 'remove': + GitPlugin.shell('commit -m "Removed document for {}"'.format(citekey)) + + +@NoteEvent.listen() +def git_note(NoteEventInstance): + pass diff --git a/pubs/repo.py b/pubs/repo.py index 51cd666..eedfff4 100644 --- a/pubs/repo.py +++ b/pubs/repo.py @@ -102,10 +102,8 @@ class Repository(object): def remove_paper(self, citekey, remove_doc=True, event=True): """ Remove a paper. Is silent if nothing needs to be done.""" - if event: - events.RemoveEvent(citekey).send() if remove_doc: - self.remove_doc(citekey, detach_only=True) + self.remove_doc(citekey, detach_only=True, event=False) try: self.databroker.remove_note(citekey, self.conf['main']['note_extension'], silent=True) @@ -115,8 +113,10 @@ class Repository(object): pass self.citekeys.remove(citekey) self.databroker.remove(citekey) + if event: + events.RemoveEvent(citekey).send() - def remove_doc(self, citekey, detach_only=False): + def remove_doc(self, citekey, detach_only=False, event=True): """ Remove a doc. Is silent if nothing needs to be done.""" try: metadata = self.databroker.pull_metadata(citekey) @@ -126,6 +126,8 @@ class Repository(object): p = self.pull_paper(citekey) p.docpath = None self.push_paper(p, overwrite=True, event=False) + if event: + events.DocEvent(citekey, 'remove').send() except IOError: # FIXME: if IOError is about being unable to # remove the file, we need to issue an error.I