# CommitBot # An interface for audibly broadcasting commit messages # Tested on OSX # Created by the friendly team at Hunch.com (sharing is caring!) # # Installation # 1. replace USERNAME, PASSWORD, and HOSTNAME below # 2. ... # 3. profit! import time import re import os import random _rev_rx = re.compile('r(\d+)\s\|\s(\w+)\s\|\s.*\s\|(.*)\s\s(.*)') MALE = { 'alex': 'Alex', 'bruce': 'Bruce', 'fred': 'Fred', 'junior': 'Junior', 'ralph': 'Ralph', } FEMALE = { 'agnes': 'Agnes', 'kathy': 'Kathy', 'princess': 'Princess', 'vicki': 'Vicki', 'victoria': 'Victoria', } NOVELTY = { 'albert': 'Albert', 'badnews': 'Bad News', 'bahh': 'Bahh', 'bells': 'Bells', 'boing': 'Boing', 'bubbles': 'Bubbles', 'cellos': 'Cellos', 'deranged': 'Deranged', 'goodnews': 'Good News', 'hysterical': 'Hysterical', 'pipeorgan': 'Pipe Organ', 'trinoids': 'Trinoids', 'whisper': 'Whisper', 'zarvox': 'Zarvox', } VOICES = {}; VOICES.update(MALE); VOICES.update(FEMALE); VOICES.update(NOVELTY); def get_voice(text): options = [x[1:] for x in text.split() if x.startswith('#')] if options: option = options[-1].lower() if option in VOICES: return VOICES[option] elif option == 'male': return random.choice(MALE.values()) elif option == 'female': return random.choice(FEMALE.values()) elif option == 'novelty': return random.choice(NOVELTY.values()) elif option == 'random': return random.choice(VOICES.values()) return '' def remove_hashes(text): return re.sub('((^| )#[^ ]+)', '', text) def clean(x): return remove_hashes(x.replace('"', "'").replace('\n', ' ')) def speak_commits(): revision = 0 try: commit_obj = open("/tmp/commit", "r") local_rev = commit_obj.read().strip() if local_rev: revision = int(local_rev) commit_obj.close() except: pass while(True): try: result = os.popen("svn log --username USERNAME --password PASSWORD HOSTNAME --limit 1").read() cur_rev, username, lines, msg = _rev_rx.findall(result)[0] # Insert nicknames if username == 'volkan': username = 'Steve' # muh-hahaha! if username == 'pcoles': username = 'cobra kai' # muh-hahahahahahaha! if username == 'tp': username = 'barbeque' # muh-hahaha! if username == 'hcooper': username = 'h prod' # hm. if int(cur_rev) > int(revision) and '#silent' not in msg: voice = get_voice(msg) if voice: voice = '-v "%s" ' % voice else: voice = '-v "Vicki" ' string = 'say %s"%s, %s"' % (voice, username, clean(msg)[:250]) # prevent extremely long messages! mute_spotify = """osascript<