8 FROM_MAIL
= "lethalman88@gmail.com"
9 TO_MAIL
= "syx-commit@googlegroups.com"
15 LASTCOMMIT
= '.announcer.lastcommit'
17 def git (command
, stripped
=True):
20 return map (lambda x
: x
[:-1], os
.popen("git "+command
).readlines ())
22 def git_exit (command
):
25 return os
.system("git %s &>/dev/null" % command
)
28 return os
.popen(SENDMAIL
, "w").write (mail
)
31 sys
.stderr
.write ("ERROR: "+message
+"\n")
35 def __init__ (self
, name
, verify
=True):
41 assert not git_exit ("rev-list -n 1 %s --" % self
.name
)
45 assert not git_exit ("checkout "+self
.name
)
48 return "Branch: %s" % (self
.name
)
54 email_tmpl
= string
.Template ("""From: $fromail
56 Content-type: text/plain
57 Subject: $branch $hash
64 def __init__ (self
, name
, branch
, verify
=True):
65 Rev
.__init
__ (self
, name
, verify
)
68 def email_report (self
):
69 whatchanged
= self
.whatchanged ()
70 diff
= self
.diff (self
.ancestor ())
71 return self
.email_tmpl
.substitute (fromail
=FROM_MAIL
, tomail
=TO_MAIL
,
72 branch
=self
.branch
.name
, hash=self
.name
,
73 whatchanged
=whatchanged
,
76 def whatchanged (self
):
77 out
= git ("whatchanged -n 1 %s" % self
)
78 return '\n'.join (out
)
80 def diff (self
, commit
):
81 out
= git ("diff %s %s" % (commit
, self
))
82 return '\n'.join (out
)
85 out
= git ("rev-list -n 1 %s^" % self
.name
)
86 return Commit (out
[0], self
.branch
, False)
88 def xnew_commits (self
):
89 out
= git ("rev-list %s..%s" % (self
.name
, self
.branch
.name
))
91 yield Commit (hash, self
.branch
)
94 return "%s %s" % (self
.branch
, self
.name
)
99 def fetch_last_commits ():
101 f
= file (LASTCOMMIT
)
102 for line
in f
.xreadlines ():
103 s
= filter (lambda x
: x
.strip(), line
.split (' '))
104 branch
= Branch (s
[0].strip ())
105 last_commits
.append (Commit (s
[1].strip(), branch
))
109 def write_last_commits (commits
):
110 f
= file (LASTCOMMIT
, "w")
111 for commit
in commits
:
112 f
.write (repr (commit
) + "\n")
117 if len(sys
.argv
) > 1:
123 error ("Use -n to not pull. Use -d to dry run")
126 assert not git_exit ("pull")
128 last_commits
= fetch_last_commits ()
129 new_last_commits
= []
130 for last_commit
in last_commits
:
131 new_commits
= list (reversed (list (last_commit
.xnew_commits ())))
132 last_commit
.branch
.checkout ()
133 for commit
in new_commits
:
134 print "* Sendmail %r" % commit
136 sendmail (commit
.email_report ())
138 new_last_commits
.append (new_commits
[-1])
140 new_last_commits
.append (last_commit
)
143 write_last_commits (new_last_commits
)