Created
August 21, 2015 14:58
-
-
Save Dyrcona/a6de1cff655ecc4ca76c to your computer and use it in GitHub Desktop.
A little fun with git, LibreOffice, and Python3....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- Mode: python; coding: utf-8 -*- | |
# --------------------------------------------------------------- | |
# Copyright © 2015 Jason J.A. Stephenson <jason@sigio.com> | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# --------------------------------------------------------------- | |
import re, subprocess, sys, time, uno | |
from com.sun.star.connection import NoConnectException | |
def soffice_desktop(): | |
localContext = uno.getComponentContext() | |
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext) | |
try: | |
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext") | |
except NoConnectException: | |
# The below works even if soffice is already running! | |
subprocess.Popen(['soffice', '--accept=socket,host=localhost,port=2002;urp;']) | |
time.sleep(1) # Give it a chance to setup the port. | |
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext") | |
smgr = ctx.ServiceManager | |
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx) | |
return desktop | |
def gather_args(): | |
args = { "upstream": None, "head": None, "limit": None } | |
if len(sys.argv) > 1: | |
args["upstream"] = sys.argv[1] | |
if len(sys.argv) > 2: | |
args["head"] = sys.argv[2] | |
if len(sys.argv) > 3: | |
args["limit"] = sys.argv[3] | |
return args | |
def gather_commits(upstream=None, head=None, limit=None): | |
args = ["git", "cherry", "-v"] | |
if upstream: | |
args.append(upstream) | |
if head: | |
args.append(head) | |
if limit: | |
args.append(limit) | |
with subprocess.Popen(args, stdout=subprocess.PIPE) as git: | |
commits = git.stdout.read().decode('utf8').splitlines() | |
return commits | |
def get_log(commit): | |
with subprocess.Popen(["git", "log", "-n 1", "--pretty=fuller", commit], stdout=subprocess.PIPE) as git: | |
log = git.stdout.read().decode('utf8') | |
return log | |
def main(): | |
ignore = re.compile(r"\b(?:stamp(?:ing)?|doc(?:s|ument(?:ation)?)|release notes?)\b", re.IGNORECASE) | |
desktop = soffice_desktop() | |
logDoc = desktop.loadComponentFromURL("private:factory/swriter", "_default", 0, ()) | |
logText = logDoc.Text | |
logCursor = logText.createTextCursor() | |
cherryArgs = gather_args() | |
for cherry in gather_commits(**cherryArgs): | |
if cherry.startswith('+ '): | |
commit = cherry[2:42] | |
firstLine = cherry[43:] | |
if not re.search(ignore, firstLine): | |
logText.insertString(logCursor, get_log(commit) + "\r", 0) | |
else: | |
print(cherry) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment