#!/usr/bin/env python # # Create a template file that I can write my initial message for doing a # batch send of git-send-email # # Copyright (C) 2008 Red Hat, Inc. # Author: David Cantrell # License: GPLv2+ # import math import os import string import sys import time def getTimeZoneOffset(): if time.daylight: offset = time.altzone else: offset = time.timezone if offset == '0': return '-0000' absoffset = abs(offset) hours = int(math.floor(absoffset / 3600.0)) mins = int(math.floor((absoffset - (hours * 3600)) / 60.0)) if offset > 0: direction = '-' else: direction = '+' return "%s%s%s" % (direction, string.zfill(hours, 2), string.zfill(mins, 2)) if __name__ == "__main__": pid = os.popen('git-config user.name') name = pid.read().strip() pid.close() pid = os.popen('git-config user.email') email = pid.read().strip() pid.close() if name == '' or name is None: print "ERROR: Missing user.name in .gitconfig" sys.exit(1) if email == '' or email is None: print "ERROR: Missing user.email in .gitconfig" sys.exit(1) if os.path.exists('_msg'): answered = False while not answered: ans = raw_input('_msg file exists, overwrite? (Y/N) ').strip().lower() if ans == 'n' or ans == 'y': answered = True else: print "ERROR: You must answer Y or N." if ans == 'n': sys.exit(0) zone = getTimeZoneOffset() now = "%s %s" % (time.strftime('%a, %d %b %Y %H:%M:%S'), zone,) out = open('_msg', 'w') out.write('From %s %s\n' % (email, now,)) out.write('From: %s <%s>\n' % (name, email,)) out.write('Date: %s\n' % (now,)) out.write('Subject: WRITEME\n\n') out.write('WRITEME\n\n') if os.path.isfile(os.environ.get('HOME') + '/.signature'): out.write('-- \n') sig = open(os.environ.get('HOME') + '/.signature', 'r') lines = sig.readlines() sig.close() for line in lines: out.write(line) out.close()