From 9d8d0dc1498706b5323fb06f0d12c8e132dbdb8c Mon Sep 17 00:00:00 2001 From: Andreas Gutsche Date: Tue, 19 Feb 2013 16:44:23 +0100 Subject: [PATCH 1/3] edited script to ignore email server if not provided in config and respect passing of argument emails-flag. Also, if defined in the config, proxy settings are used. --- src/shotgunEventDaemon.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/shotgunEventDaemon.py b/src/shotgunEventDaemon.py index 0c3a9246..c872435a 100755 --- a/src/shotgunEventDaemon.py +++ b/src/shotgunEventDaemon.py @@ -29,14 +29,12 @@ import ConfigParser import datetime import imp -import logging import logging.handlers import os import pprint import socket import sys import time -import types import traceback from distutils.version import StrictVersion @@ -137,6 +135,11 @@ def __init__(self, path): def getShotgunURL(self): return self.get('shotgun', 'server') + def getShotgunProxy(self): + if self.has_option('proxy', 'http_proxy'): + return self.get('proxy', 'http_proxy') + return None + def getEngineScriptName(self): return self.get('shotgun', 'name') @@ -153,7 +156,9 @@ def getPluginPaths(self): return [s.strip() for s in self.get('plugins', 'paths').split(',')] def getSMTPServer(self): - return self.get('emails', 'server') + if self.has_option('emails', 'server'): + return self.get('emails', 'server') + return None def getSMTPPort(self): if self.has_option('emails', 'port'): @@ -237,7 +242,8 @@ def __init__(self, configPath): self._sg = sg.Shotgun( self.config.getShotgunURL(), self.config.getEngineScriptName(), - self.config.getEngineScriptKey() + self.config.getEngineScriptKey(), + http_proxy=self.config.getShotgunProxy() ) self._max_conn_retries = self.config.getint('daemon', 'max_conn_retries') self._conn_retry_sleep = self.config.getint('daemon', 'conn_retry_sleep') @@ -372,7 +378,7 @@ def _loadEventIdData(self): order = [{'column':'id', 'direction':'desc'}] try: result = self._sg.find_one("EventLogEntry", filters=[], fields=['id'], order=order) - except (sg.ProtocolError, sg.ResponseError, socket.err), err: + except (sg.ProtocolError, sg.ResponseError, socket.error), err: conn_attempts = self._checkConnectionAttempts(conn_attempts, str(err)) except Exception, err: msg = "Unknown error: %s" % str(err) @@ -421,7 +427,7 @@ def _mainLoop(self): # Reload plugins for collection in self._pluginCollections: collection.load() - + # Make sure that newly loaded events have proper state. self._loadEventIdData() @@ -446,7 +452,7 @@ def _getNewEvents(self): filters = [['id', 'greater_than', nextEventId - 1]] fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity', 'user', 'project', 'session_uuid'] order = [{'column':'id', 'direction':'asc'}] - + conn_attempts = 0 while True: try: @@ -463,7 +469,7 @@ def _getNewEvents(self): def _saveEventIdData(self): """ - Save an event Id to persistant storage. + Save an event Id to persistent storage. Next time the engine is started it will try to read the event id from this location to know at which event it should start processing. @@ -580,9 +586,9 @@ class Plugin(object): The plugin class represents a file on disk which contains one or more callbacks. """ - def __init__(self, engine, path): + def __init__(self, engine, path, emails=True): """ - @param engine: The engine that instanciated this plugin. + @param engine: The engine that instantiated this plugin. @type engine: L{Engine} @param path: The path of the plugin file to load. @type path: I{str} @@ -605,7 +611,7 @@ def __init__(self, engine, path): # Setup the plugin's logger self.logger = logging.getLogger('plugin.' + self.getName()) self.logger.config = self._engine.config - self._engine.setEmailsOnLogger(self.logger, True) + self._engine.setEmailsOnLogger(self.logger, emails) self.logger.setLevel(self._engine.config.getLogLevel()) if self._engine.config.getLogMode() == 1: _setFilePathOnLogger(self.logger, self._engine.config.getLogFile('plugin.' + self.getName())) @@ -714,7 +720,7 @@ def registerCallback(self, sgScriptName, sgScriptKey, callback, matchEvents=None Register a callback in the plugin. """ global sg - sgConnection = sg.Shotgun(self._engine.config.getShotgunURL(), sgScriptName, sgScriptKey) + sgConnection = sg.Shotgun(self._engine.config.getShotgunURL(), sgScriptName, sgScriptKey, http_proxy=self._engine.config.getShotgunProxy()) self._callbacks.append(Callback(callback, self, self._engine, sgConnection, matchEvents, args, stopOnError)) def process(self, event): @@ -818,7 +824,7 @@ def __init__(self, callback, plugin, engine, shotgun, matchEvents=None, args=Non @type logger: I{logging.Logger} @param matchEvents: The event filter to match events against before invoking callback. @type matchEvents: dict - @param args: Any datastructure you would like to be passed to your + @param args: Any data-structure you would like to be passed to your callback function. Defaults to None. @type args: Any object. @@ -993,8 +999,8 @@ def emit(self, record): smtp.starttls(*self.secure) smtp.ehlo() smtp.login(self.username, self.password) - smtp.sendmail(self.fromaddr, self.toaddrs, msg) - smtp.close() + #smtp.sendmail(self.fromaddr, self.toaddrs, msg) + #smtp.close() except (KeyboardInterrupt, SystemExit): socket.setdefaulttimeout(60) raise From 9968d92374a5bf1aecdb2cb81e0121a88ae53b19 Mon Sep 17 00:00:00 2001 From: Andreas Gutsche Date: Tue, 19 Feb 2013 16:45:56 +0100 Subject: [PATCH 2/3] added a proxy section with an option http_proxy. --- src/shotgunEventDaemon.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shotgunEventDaemon.conf b/src/shotgunEventDaemon.conf index 8a95ca0c..5c05913f 100644 --- a/src/shotgunEventDaemon.conf +++ b/src/shotgunEventDaemon.conf @@ -53,6 +53,10 @@ fetch_interval = 5 max_event_batch_size = 500 +[proxy] +# Proxy settings for reaching the shotgun server. +# http_proxy: $HTTP_PROXY$ + [shotgun] # Shotgun connection options for the daemon From d0e99493c22aab0479fa63ff5de9b1112f3251ab Mon Sep 17 00:00:00 2001 From: Andreas Gutsche Date: Tue, 19 Feb 2013 16:54:09 +0100 Subject: [PATCH 3/3] accidentally overlooked the fact that the sendmail statement was commented out. --- src/shotgunEventDaemon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shotgunEventDaemon.py b/src/shotgunEventDaemon.py index c872435a..07740404 100755 --- a/src/shotgunEventDaemon.py +++ b/src/shotgunEventDaemon.py @@ -999,8 +999,8 @@ def emit(self, record): smtp.starttls(*self.secure) smtp.ehlo() smtp.login(self.username, self.password) - #smtp.sendmail(self.fromaddr, self.toaddrs, msg) - #smtp.close() + smtp.sendmail(self.fromaddr, self.toaddrs, msg) + smtp.close() except (KeyboardInterrupt, SystemExit): socket.setdefaulttimeout(60) raise