diff --git a/.gitignore b/.gitignore index e8372979..e132bfa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.idea/ +src/logs docs/_build/doctrees shotgunEventDaemon.conf +plugins *.pyc 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..14517382 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') @@ -360,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)) @@ -446,13 +456,14 @@ 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: 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: @@ -850,6 +861,21 @@ 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 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 + if not self._matchEvents: return True