Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Analyze Unison log, and send email of changed files
unison.log.old
unison.log
git+git://github.com/kennethreitz/envoy.git@36b307956b84c78e74ddd4b212a02fde004f5f59
#!/usr/bin/env python
import shutil
import os
import smtplib
from email.mime.text import MIMEText
import envoy
CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(CURRENT_DIRECTORY, '..')
UNISON_ARGUMENTS = [
'/Volumes/Gallery Data/',
'ssh://canada@canada.dyndns-blog.com//Volumes/Clone of Gallery Data/gallery clone/',
'-sortbysize',
'-ignore "Path .*"',
'-ignore "Name *."',
'-ignore "Name .DS_Store"',
'-mountpoint "KB.TIF"',
'-silent',
'-batch',
'-perms 0',
'-contactquietly',
'-logfile "{}/unison.log"'.format(LOG_DIRECTORY),
]
TO = ['s.shanabrook@gmail.com',]
FROM = 'canada.sync.log@gmail.com'
USERNAME = 'canada.sync.log'
PASSWORD = 'canadacanada'
unison = envoy.run('unison ' + ' '.join(UNISON_ARGUMENTS))
if unison.status_code != 0:
msg = '''
Standard Error:
{std_error}
Standard Out:
{std_out}'''.format(**unison.__dict__)
subject = 'Sync Error'
else:
subject = 'Sync Completed'
msg = open('unison.log').read()
shutil.move('unison.log', 'unison.log.old')
msg = MIMEText(msg)
msg['Subject'] = subject
msg['From'] = FROM
msg['To'] = ', '.join(TO)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(USERNAME, PASSWORD)
server.sendmail(msg['From'], TO, msg.as_string())
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.