Skip to content

Instantly share code, notes, and snippets.

@meganehouser
Created December 13, 2012 04:49
Show Gist options
  • Save meganehouser/4274087 to your computer and use it in GitHub Desktop.
Save meganehouser/4274087 to your computer and use it in GitHub Desktop.
SubversionのコミットをIPメッセンジャーで通知する(Windows)
#!python 2
#! coding:utf-8
"""
リポジトリのhooksフォルダに置く。
hooksフォルダのpost-commit.batには以下のように記述。
cd C:\Repositorys\exampleProject\hooks
post-commit.py %1 %2
"""
import os
import subprocess
import sys
import codecs
IPMSG_INSTALL_DIR = 'C:/Program Files/IPMsg'
REPOSITORY_URL = "http://example.com/svn/exampleProject/"
USER = 'guest'
PASSWORD = 'password'
sendto = ['222.222.222.222', '111.111.111.111']
def send_message(to_ip, message):
args = [os.path.join(IPMSG_INSTALL_DIR, 'ipmsg.exe'), '/MSG', to_ip, message]
subprocess.call(args)
def create_message(rev):
message = u'コミットされました\n'.encode('shift_jis')
try:
args = ['svn', 'log', REPOSITORY_URL, '-r', rev, '--username', USER, '--password', PASSWORD]
p = subprocess.Popen(args, stdout=subprocess.PIPE, shell=True)
for line in codecs.getreader("mbcs")(p.stdout):
message += line.encode('shift_jis')
except Exception as e:
message += u'==エラー発生==\n'
message += 'type:' + str(type(e))
message += 'message:' + e.message
return message
if __name__ == '__main__':
repo = sys.argv[1]
rev = sys.argv[2]
message = create_message(rev)
for ip in sendto:
send_message(ip, message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment