Add email on upload to lookaside cache
Also cleaned up small whitespace issues
This commit is contained in:
parent
8092476297
commit
bf991365a5
1 changed files with 18 additions and 2 deletions
|
@ -11,6 +11,8 @@ import sys
|
||||||
import cgi
|
import cgi
|
||||||
import tempfile
|
import tempfile
|
||||||
import grp
|
import grp
|
||||||
|
import smtplib
|
||||||
|
from email.mine.text import MIMEText
|
||||||
try:
|
try:
|
||||||
import hashlib
|
import hashlib
|
||||||
md5_constructor = hashlib.md5
|
md5_constructor = hashlib.md5
|
||||||
|
@ -51,6 +53,19 @@ def check_auth(username):
|
||||||
pass
|
pass
|
||||||
return authenticated
|
return authenticated
|
||||||
|
|
||||||
|
def send_email(name, md5, filename):
|
||||||
|
text='File %s has been uploaded to the lookaside cache with md5sum %s' % \
|
||||||
|
(filename, md5)
|
||||||
|
msg = MIMEText(text)
|
||||||
|
sender = 'nobody@fedoraproject.org'
|
||||||
|
recepients = [ '%s-owner@fedoraproject.org' % name, \
|
||||||
|
'fedora-extras-commits@redhat.com' ]
|
||||||
|
msg['Subject'] = 'File %s uploaded to lookaside cache' % filename
|
||||||
|
msg['From'] = sender
|
||||||
|
msg['To'] = recepients
|
||||||
|
s = smtplib.SMTP(host='bastion.fedoraproject.org')
|
||||||
|
s.sendmail(sender, recepients, msg.as_string())
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
os.umask(002)
|
os.umask(002)
|
||||||
|
|
||||||
|
@ -80,7 +95,7 @@ def main():
|
||||||
# In a submission, we don;t get a filename, just the file.
|
# In a submission, we don;t get a filename, just the file.
|
||||||
if form.has_key('filename'):
|
if form.has_key('filename'):
|
||||||
action = 'check'
|
action = 'check'
|
||||||
filename = check_form(form, 'filename')
|
filename = check_form(form, 'filename')
|
||||||
filename = os.path.basename(filename)
|
filename = os.path.basename(filename)
|
||||||
print >> sys.stderr, '[username=%s] Checking file status: NAME=%s FILENAME=%s MD5SUM=%s' % (username, name, filename, md5sum)
|
print >> sys.stderr, '[username=%s] Checking file status: NAME=%s FILENAME=%s MD5SUM=%s' % (username, name, filename, md5sum)
|
||||||
else:
|
else:
|
||||||
|
@ -102,7 +117,7 @@ def main():
|
||||||
if not os.path.isdir(cvs_dir):
|
if not os.path.isdir(cvs_dir):
|
||||||
print >> sys.stderr, '[username=%s] Unknown module: %s' % (username, name)
|
print >> sys.stderr, '[username=%s] Unknown module: %s' % (username, name)
|
||||||
send_error('Module "%s" does not exist!' % name)
|
send_error('Module "%s" does not exist!' % name)
|
||||||
|
|
||||||
# try to see if we already have this file...
|
# try to see if we already have this file...
|
||||||
dest_file = os.path.join(md5_dir, filename)
|
dest_file = os.path.join(md5_dir, filename)
|
||||||
if os.path.exists(dest_file):
|
if os.path.exists(dest_file):
|
||||||
|
@ -152,6 +167,7 @@ def main():
|
||||||
os.rename(tmpfile, dest_file)
|
os.rename(tmpfile, dest_file)
|
||||||
print >> sys.stderr, '[username=%s] Stored %s (%d bytes)' % (username, dest_file, filesize)
|
print >> sys.stderr, '[username=%s] Stored %s (%d bytes)' % (username, dest_file, filesize)
|
||||||
print 'File %s size %d MD5 %s stored OK' % (filename, filesize, md5sum)
|
print 'File %s size %d MD5 %s stored OK' % (filename, filesize, md5sum)
|
||||||
|
send_email(name, md5sum, filename)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue