Added the git listener functions for the events that were prewritten
This commit is contained in:
parent
2718a2e23a
commit
f12c03f13a
@ -3,14 +3,18 @@ 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 RemoveEvent, RenameEvent, AddEvent
|
||||||
|
|
||||||
|
|
||||||
class GitPlugin(PapersPlugin):
|
class GitPlugin(PapersPlugin):
|
||||||
|
|
||||||
name = 'git'
|
name = 'git'
|
||||||
|
pubsdir = None
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
self.description = "Run git commands in the pubs directory"
|
self.description = "Run git commands in the pubs directory"
|
||||||
|
# Needed for the event listening
|
||||||
|
GitPlugin.pubsdir = conf['main']['pubsdir']
|
||||||
|
|
||||||
def update_parser(self, subparsers, conf):
|
def update_parser(self, subparsers, conf):
|
||||||
git_parser = self.parser(subparsers)
|
git_parser = self.parser(subparsers)
|
||||||
@ -24,9 +28,40 @@ class GitPlugin(PapersPlugin):
|
|||||||
|
|
||||||
def command(self, conf, args):
|
def command(self, conf, args):
|
||||||
"""Runs the git program in a shell"""
|
"""Runs the git program in a shell"""
|
||||||
subprocess.call(
|
for a in args.arguments:
|
||||||
'pubs_git() {{\ngit -C {} $@\n}}\npubs_git {}'.format(
|
print(a)
|
||||||
conf['main']['pubsdir'],
|
GitPlugin.shell(' '.join([shell_quote(a) for a in args.arguments]))
|
||||||
' '.join([shell_quote(a) for a in args.arguments])
|
|
||||||
), shell=True)
|
@classmethod
|
||||||
|
def shell(cls, cmd):
|
||||||
|
subprocess.call('git -C {} {}'.format(cls.pubsdir, cmd), shell=True)
|
||||||
|
|
||||||
|
|
||||||
|
@RenameEvent.listen()
|
||||||
|
def git_rename(RenameEventInstance):
|
||||||
|
new_key = RenameEventInstance.paper.citekey
|
||||||
|
old_key = RenameEventInstance.old_citekey
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
@RemoveEvent.listen()
|
||||||
|
def git_remove(RemoveEventInstance):
|
||||||
|
citekey = RemoveEventInstance.old_citekey
|
||||||
|
|
||||||
|
# Stage the changes and commit
|
||||||
|
GitPlugin.shell("add \*/{}.\*".format(citekey))
|
||||||
|
GitPlugin.shell('commit -m "Removed {}"'.format(citekey))
|
||||||
|
|
||||||
|
|
||||||
|
@AddEvent.listen()
|
||||||
|
def git_add(AddEventInstance):
|
||||||
|
citekey = AddEventInstance.citekey
|
||||||
|
|
||||||
|
# Stage the changes and commit
|
||||||
|
GitPlugin.shell("add \*/{}.\*".format(citekey))
|
||||||
|
GitPlugin.shell('commit -m "Added {}"'.format(citekey))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user