Revision d915a659
Added by David Sorber over 7 years ago
| software/hbkcd/hbkcd/daemon.py | ||
|---|---|---|
|
#!/usr/bin/python3
|
||
|
import datetime
|
||
|
from email.mime.text import MIMEText
|
||
|
import logging
|
||
|
import os
|
||
|
from smtplib import SMTP_SSL
|
||
|
import subprocess
|
||
|
import sys
|
||
|
import threading
|
||
| ... | ... | |
|
from hbkcd.command_server import StoppableHTTPServer, CommandHandler
|
||
|
from hbkcd.queue import ENCODE_QUEUE
|
||
|
|
||
|
# These should probably be protected...
|
||
|
RELAY_EMAIL = 'dsorber.phalanx@gmail.com'
|
||
|
RELAY_PASSWD = "You'reNotMySupervisor"
|
||
|
TO_EMAIL = 'baranovich@gmail.com'
|
||
|
|
||
|
#
|
||
|
# HbkCD - Handbrake Control Daemon
|
||
|
#
|
||
|
|
||
|
def send_email(subject, msg_text):
|
||
|
""" Simple helper function to send an email
|
||
|
"""
|
||
|
msg = MIMEText(msg_text, 'plain')
|
||
|
msg['Subject'] = subject
|
||
|
msg['To'] = TO_EMAIL
|
||
|
try:
|
||
|
conn = SMTP_SSL('smtp.gmail.com')
|
||
|
conn.set_debuglevel(True)
|
||
|
conn.login(RELAY_EMAIL, RELAY_PASSWD)
|
||
|
try:
|
||
|
conn.sendmail(RELAY_EMAIL, TO_EMAIL, msg.as_string())
|
||
|
finally:
|
||
|
conn.close()
|
||
|
except Exception as exp:
|
||
|
error = '{:s}: {!r}'.format(type(exp).__name__, exp.args)
|
||
|
logging.error(error)
|
||
|
|
||
|
def __test_executable(exe_name, exe_path):
|
||
|
""" Helper function to cut down on code duplication.
|
||
|
"""
|
||
| ... | ... | |
|
|
||
|
# Print success or failure message to the log depending on the
|
||
|
# HandBrake process's return code
|
||
|
status = ''
|
||
|
if hbk_proc.returncode == 0:
|
||
|
status = 'COMPLETED SUCCESSFULLY'
|
||
|
fmt_str = 'Encode of {:s} completed in {:s} (queued for: {:s})'
|
||
|
logging.info(fmt_str.format(item.path, elapsed_str, queued_str))
|
||
|
else:
|
||
|
status = 'ERROR'
|
||
|
fmt_str = 'Error while encoding {:s} (queued for: {:s})'
|
||
|
logging.error(fmt_str.format(item.path, queued_str))
|
||
|
|
||
|
# If configured send encode complete email
|
||
|
if ENABLE_ENCODE_COMPLETE_EMAILS:
|
||
|
subject = 'hbkcd Encode Complete'
|
||
|
msg = '{:s}\n\nEncoded: {:s}\nDuration: {:s}\n'\
|
||
|
'Queued time: {:s}\nEncode log: {:s}\n'
|
||
|
|
||
|
send_email(subject, msg.format(status, item.path, elapsed_str,
|
||
|
queued_str, log_path))
|
||
|
logging.debug('Sent encode complete email')
|
||
|
|
||
|
# Remove the item from the queue
|
||
|
ENCODE_QUEUE.remove(0)
|
||
|
|
||
Adding hbkcd_status script to get status of current encode. Also added
feature to (optionally) send email once an encode is completed.