From 85339b992bc38596db50a9e534aa167a9f7d6164 Mon Sep 17 00:00:00 2001 From: Rene Calles Date: Thu, 8 Jan 2015 18:06:42 +0100 Subject: [PATCH 1/5] adding plugins folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e8372979..4e12653b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ docs/_build/doctrees shotgunEventDaemon.conf +plugins *.pyc From 43a7428a5106f6a8ec24962af3e6d4a1e7f9e450 Mon Sep 17 00:00:00 2001 From: Rene Calles Date: Fri, 9 Jan 2015 13:21:55 +0100 Subject: [PATCH 2/5] adding limit_to_projects and ignore_projects features with configuration changes --- src/shotgunEventDaemon.conf.example | 9 ++++++ src/shotgunEventDaemon.py | 44 +++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/shotgunEventDaemon.conf.example b/src/shotgunEventDaemon.conf.example index 68ae2c8b..0254d47b 100644 --- a/src/shotgunEventDaemon.conf.example +++ b/src/shotgunEventDaemon.conf.example @@ -66,6 +66,15 @@ name: shotgunEventDaemon # this random useless key with the one corresponding to the script you've setup. key: 841c9a51bf45e1872c3e5f2435dade67458bc858 +# Limits the events receiving by this event daemon to the comma delimited list +# defined in limit_to_projects. Should not used together with 'ignore_projects'. +limit_to_projects: + +# Ignores events for projects defined in the comma delimited list ignore_projects. +# Should not be used together with 'limit_to_projects'. +ignore_projects: + + # Sets the session_uuid from every event in the Shotgun instance to propagate in # any events generated by plugins. This will allow the Shotgun UI to display # updates that occur as a result of a plugin. diff --git a/src/shotgunEventDaemon.py b/src/shotgunEventDaemon.py index 34d79a2a..ac5724f8 100755 --- a/src/shotgunEventDaemon.py +++ b/src/shotgunEventDaemon.py @@ -143,6 +143,14 @@ def getEngineScriptName(self): def getEngineScriptKey(self): return self.get('shotgun', 'key') + def getEngineLimitToProjects(self): + project_list = [s.strip() for s in self.get('shotgun', 'limit_to_projects').split(',')] + return project_list if project_list[0] != '' else [] + + def getEngineIgnoreProjects(self): + project_list = [s.strip() for s in self.get('shotgun', 'ignore_projects').split(',')] + return project_list if project_list[0] != '' else [] + def getEventIdFile(self): return self.get('daemon', 'eventIdFile') @@ -444,15 +452,45 @@ def _getNewEvents(self): if nextEventId is not None: filters = [['id', 'greater_than', nextEventId - 1]] + limit_to_projects = self.config.getEngineLimitToProjects() + projects = [] + for project_name in limit_to_projects: + project = self._sg.find('Project', [['name', 'is', project_name]], ['id']) + if len(project) > 1: + self.log.warning(("Multiple Projects with same name '{0}' " + "found and added to the list.").format(project_name)) + if len(project) < 1: + self.log.error("No Project with name '{0}' found. Not added.".format(project_name)) + + [projects.append(['project', 'is', {'type': 'Project', 'id': p['id']}]) for p in project] + + ignore_projects = self.config.getEngineIgnoreProjects() + for project_name in ignore_projects: + project = self._sg.find('Project', [['name', 'is', project_name]], ['id']) + if len(project) > 1: + self.log.warning(("Multiple Projects with same name '{0}' " + "found and added to the list.").format(project_name)) + if len(project) < 1: + self.log.error("No Project with name '{0}' found. Not added.".format(project_name)) + + [projects.append(['project', 'is_not', {'type': 'Project', 'id': p['id']}]) for p in project] + + + if projects: + project_filters = {'filter_operator': 'any', + 'filters': projects} + filters.append(project_filters) + fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity', 'user', 'project', 'session_uuid'] order = [{'column':'id', 'direction':'asc'}] - + conn_attempts = 0 while True: try: return self._sg.find("EventLogEntry", filters, fields, order, limit=self.config.getMaxEventBatchSize()) - if events: - self.log.debug('Got %d events: %d to %d.', len(events), events[0]['id'], events[-1]['id']) + # This gets never fired as the function returns previously + # if events: + # self.log.debug('Got %d events: %d to %d.', len(events), events[0]['id'], events[-1]['id']) except (sg.ProtocolError, sg.ResponseError, socket.error), err: conn_attempts = self._checkConnectionAttempts(conn_attempts, str(err)) except Exception, err: From d628632757bc5b4cf612be60cf3ab8890b6bdcc5 Mon Sep 17 00:00:00 2001 From: Rene Calles Date: Wed, 14 Jan 2015 12:35:33 +0100 Subject: [PATCH 3/5] fixed project limitation feature to keep the benefits from backlog --- src/shotgunEventDaemon.py | 42 ++++++++++++--------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/shotgunEventDaemon.py b/src/shotgunEventDaemon.py index ac5724f8..d18d3dcd 100755 --- a/src/shotgunEventDaemon.py +++ b/src/shotgunEventDaemon.py @@ -368,6 +368,8 @@ def _loadEventIdData(self): self.log.debug('Read last event id (%d) from file.', lastEventId) for collection in self._pluginCollections: collection.setState(lastEventId) + except EOFError: + print "EOFERROR in pickle.load occured", fh.read() fh.close() except OSError, err: raise EventDaemonError('Could not load event id from file.\n\n%s' % traceback.format_exc(err)) @@ -452,35 +454,6 @@ def _getNewEvents(self): if nextEventId is not None: filters = [['id', 'greater_than', nextEventId - 1]] - limit_to_projects = self.config.getEngineLimitToProjects() - projects = [] - for project_name in limit_to_projects: - project = self._sg.find('Project', [['name', 'is', project_name]], ['id']) - if len(project) > 1: - self.log.warning(("Multiple Projects with same name '{0}' " - "found and added to the list.").format(project_name)) - if len(project) < 1: - self.log.error("No Project with name '{0}' found. Not added.".format(project_name)) - - [projects.append(['project', 'is', {'type': 'Project', 'id': p['id']}]) for p in project] - - ignore_projects = self.config.getEngineIgnoreProjects() - for project_name in ignore_projects: - project = self._sg.find('Project', [['name', 'is', project_name]], ['id']) - if len(project) > 1: - self.log.warning(("Multiple Projects with same name '{0}' " - "found and added to the list.").format(project_name)) - if len(project) < 1: - self.log.error("No Project with name '{0}' found. Not added.".format(project_name)) - - [projects.append(['project', 'is_not', {'type': 'Project', 'id': p['id']}]) for p in project] - - - if projects: - project_filters = {'filter_operator': 'any', - 'filters': projects} - filters.append(project_filters) - fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity', 'user', 'project', 'session_uuid'] order = [{'column':'id', 'direction':'asc'}] @@ -888,6 +861,17 @@ def __init__(self, callback, plugin, engine, shotgun, matchEvents=None, args=Non self._logger.config = self._engine.config def canProcess(self, event): + + limit_to_projects = self._engine.config.getEngineLimitToProjects() + ignore_projects = self._engine.config.getEngineIgnoreProjects() + + if 'project' in event and event['project'] is not None: + project_name = event['project'].get('name') + if project_name not in limit_to_projects or project_name in ignore_projects: + msg = 'Skipping event {0}. Excluded by engine configuration for project: {1}' + self._logger.debug(msg.format(event['id'], project_name)) + return False + if not self._matchEvents: return True From af8b82ea2d30f5c28620094fa129ea34ccb3a861 Mon Sep 17 00:00:00 2001 From: Rene Calles Date: Wed, 14 Jan 2015 13:02:37 +0100 Subject: [PATCH 4/5] fixing project limitation feature --- src/shotgunEventDaemon.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shotgunEventDaemon.py b/src/shotgunEventDaemon.py index d18d3dcd..14517382 100755 --- a/src/shotgunEventDaemon.py +++ b/src/shotgunEventDaemon.py @@ -867,8 +867,12 @@ def canProcess(self, event): if 'project' in event and event['project'] is not None: project_name = event['project'].get('name') - if project_name not in limit_to_projects or project_name in ignore_projects: - msg = 'Skipping event {0}. Excluded by engine configuration for project: {1}' + if limit_to_projects and project_name not in limit_to_projects: + msg = "Skipping event {0}. Ignored by engine configuration 'limit_to_projects' for project: {1}" + self._logger.debug(msg.format(event['id'], project_name)) + return False + if project_name in ignore_projects: + msg = "Skipping event {0}. Ignored by engine configuration 'ignore_projects' for project: {1}" self._logger.debug(msg.format(event['id'], project_name)) return False From d8ce1a8a9126048022ec230402ee39403a879197 Mon Sep 17 00:00:00 2001 From: "Calles, Rene" Date: Wed, 27 May 2015 12:58:43 +0200 Subject: [PATCH 5/5] cleaning up --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4e12653b..e132bfa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.idea/ +src/logs docs/_build/doctrees shotgunEventDaemon.conf plugins