def entityEventCB(sg, logger, event, args): """ A callback that treat plugins entities changes @param sg: Shotgun instance. @param logger: A preconfigured Python logging.Logger object @param event: A Shotgun event. @param args: The args passed in at the registerCallback call. """ logger.debug("%s" % str(event)) etype = event['event_type'] attribute = event['attribute_name'] meta = event['meta'] if re.search('Retirement$', etype): # Unload the plugin p = sg.find_one(meta['entity_type'], [['id', 'is', meta['entity_id']]], ['sg_script_path'], retired_only=True) if p['sg_script_path'] and p['sg_script_path']['local_path']: logger.info('Unloading %s', p['sg_script_path']['name']) args['engine'].unloadPlugin(p['sg_script_path']['local_path']) elif re.search('Revival$', etype) or re.search( 'New$', etype): #Should reload the plugin p = sg.find_one( meta['entity_type'], [['id', 'is', meta['entity_id']]], ['sg_script_path', 'sg_status_list', 'sg_ignore_projects']) if p['sg_script_path'] and p['sg_script_path']['local_path'] and p[ 'sg_status_list'] == 'act' and os.path.isfile( p['sg_script_path']['local_path']): logger.info('Loading %s', p['sg_script_path']['name']) pl = args['engine'].loadPlugin(p['sg_script_path']['local_path'], autoDiscover=False) pl._pm_ignore_projects = p['sg_ignore_projects']
def changeEventCB(sg, logger, event, args): """ A callback that treats plugins attributes changes. @param sg: Shotgun instance. @param logger: A preconfigured Python logging.Logger object @param event: A Shotgun event. @param args: The args passed in at the registerCallback call. """ logger.debug("%s" % str(event)) etype = event['event_type'] attribute = event['attribute_name'] entity = event['entity'] if attribute == 'sg_status_list' : logger.info( "Status changed for %s", entity['name'] ) # We need some details to know what to do p = sg.find_one( entity['type'], [[ 'id', 'is', entity['id']]], ['sg_script_path', 'sg_ignore_projects'] ) if p['sg_script_path'] and p['sg_script_path']['local_path'] and os.path.isfile( p['sg_script_path']['local_path'] ) : if event['meta']['new_value'] == 'act' : logger.info('Loading %s', p['sg_script_path']['name']) pl = args['engine'].loadPlugin( p['sg_script_path']['local_path'], autoDiscover=False) pl._pm_ignore_projects = p['sg_ignore_projects'] else : #Disable the plugin logger.info('Unloading %s', p['sg_script_path']['name']) args['engine'].unloadPlugin( p['sg_script_path']['local_path']) elif attribute == 'sg_script_path' : # Should unload and reload the plugin logger.info( "Script path changed for %s", entity['name'] ) # We need some details to know what to do p = sg.find_one( entity['type'], [[ 'id', 'is', entity['id']]], ['sg_status_list', 'sg_script_path', 'sg_ignore_projects'] ) old_val = event['meta']['old_value'] # Unload the plugin if loaded if old_val and 'file_path' in old_val : # Couldn't be loaded if empty or None file_path = old_val['file_path'] # This is not the full path, it is local to the storage # We need to rebuild the old path local_path = { 'darwin' : 'mac_path', 'win32' : 'windows_path', 'linux' : 'linux_path', 'linux2' : 'linux_path' }[ sys.platform] st = sg.find_one( 'LocalStorage', [[ 'id', 'is', old_val['local_storage_id'] ]], [local_path ] ) path = os.path.join( st[ local_path], file_path ) logger.info('Unloading %s', os.path.basename( path )) args['engine'].unloadPlugin( path ) # Reload the plugin if possible if p['sg_script_path'] and p['sg_script_path']['local_path'] and p['sg_status_list'] == 'act' and os.path.isfile( p['sg_script_path']['local_path'] ) : logger.info('Loading %s', p['sg_script_path']['name']) pl = args['engine'].loadPlugin( p['sg_script_path']['local_path'], autoDiscover=False) pl._pm_ignore_projects = p['sg_ignore_projects'] elif attribute == 'sg_ignore_projects' : logger.info( "'Ignore projects' changed for %s", entity['name'] ) p = sg.find_one( entity['type'], [[ 'id', 'is', entity['id']]], ['sg_status_list', 'sg_script_path', 'sg_ignore_projects'] ) if p['sg_script_path'] and p['sg_script_path']['local_path'] : pl = args['engine'].getPlugin( p['sg_script_path']['local_path'] ) if pl : pl._pm_ignore_projects = p['sg_ignore_projects']
def entityEventCB(sg, logger, event, args): """ A callback that treat plugins entities changes @param sg: Shotgun instance. @param logger: A preconfigured Python logging.Logger object @param event: A Shotgun event. @param args: The args passed in at the registerCallback call. """ logger.debug("%s" % str(event)) etype = event['event_type'] attribute = event['attribute_name'] meta = event['meta'] if re.search( 'Retirement$', etype ) : # Unload the plugin p = sg.find_one( meta['entity_type'], [[ 'id', 'is', meta['entity_id']]], ['sg_script_path'], retired_only=True ) if p['sg_script_path'] and p['sg_script_path']['local_path'] : logger.info('Unloading %s', p['sg_script_path']['name']) args['engine'].unloadPlugin( p['sg_script_path']['local_path']) elif re.search( 'Revival$', etype ) or re.search( 'New$', etype ): #Should reload the plugin p = sg.find_one( meta['entity_type'], [[ 'id', 'is', meta['entity_id']]], ['sg_script_path', 'sg_status_list', 'sg_ignore_projects'] ) if p['sg_script_path'] and p['sg_script_path']['local_path'] and p['sg_status_list'] == 'act' and os.path.isfile( p['sg_script_path']['local_path'] ) : logger.info('Loading %s', p['sg_script_path']['name']) pl = args['engine'].loadPlugin( p['sg_script_path']['local_path'], autoDiscover=False) pl._pm_ignore_projects = p['sg_ignore_projects']
def changeEventCB(sg, logger, event, args): """ A callback that treats plugins attributes changes. @param sg: Shotgun instance. @param logger: A preconfigured Python logging.Logger object @param event: A Shotgun event. @param args: The args passed in at the registerCallback call. """ logger.debug("%s" % str(event)) etype = event['event_type'] attribute = event['attribute_name'] entity = event['entity'] if attribute == 'sg_status_list': logger.info("Status changed for %s", entity['name']) # We need some details to know what to do p = sg.find_one(entity['type'], [['id', 'is', entity['id']]], ['sg_script_path', 'sg_ignore_projects']) if p['sg_script_path'] and p['sg_script_path'][ 'local_path'] and os.path.isfile( p['sg_script_path']['local_path']): if event['meta']['new_value'] == 'act': logger.info('Loading %s', p['sg_script_path']['name']) pl = args['engine'].loadPlugin( p['sg_script_path']['local_path'], autoDiscover=False) pl._pm_ignore_projects = p['sg_ignore_projects'] else: #Disable the plugin logger.info('Unloading %s', p['sg_script_path']['name']) args['engine'].unloadPlugin(p['sg_script_path']['local_path']) elif attribute == 'sg_script_path': # Should unload and reload the plugin logger.info("Script path changed for %s", entity['name']) # We need some details to know what to do p = sg.find_one( entity['type'], [['id', 'is', entity['id']]], ['sg_status_list', 'sg_script_path', 'sg_ignore_projects']) old_val = event['meta']['old_value'] # Unload the plugin if loaded if old_val and 'file_path' in old_val: # Couldn't be loaded if empty or None file_path = old_val[ 'file_path'] # This is not the full path, it is local to the storage # We need to rebuild the old path local_path = { 'darwin': 'mac_path', 'win32': 'windows_path', 'linux': 'linux_path', 'linux2': 'linux_path' }[sys.platform] st = sg.find_one('LocalStorage', [['id', 'is', old_val['local_storage_id']]], [local_path]) path = os.path.join(st[local_path], file_path) logger.info('Unloading %s', os.path.basename(path)) args['engine'].unloadPlugin(path) # Reload the plugin if possible if p['sg_script_path'] and p['sg_script_path']['local_path'] and p[ 'sg_status_list'] == 'act' and os.path.isfile( p['sg_script_path']['local_path']): logger.info('Loading %s', p['sg_script_path']['name']) pl = args['engine'].loadPlugin(p['sg_script_path']['local_path'], autoDiscover=False) pl._pm_ignore_projects = p['sg_ignore_projects'] elif attribute == 'sg_ignore_projects': logger.info("'Ignore projects' changed for %s", entity['name']) p = sg.find_one( entity['type'], [['id', 'is', entity['id']]], ['sg_status_list', 'sg_script_path', 'sg_ignore_projects']) if p['sg_script_path'] and p['sg_script_path']['local_path']: pl = args['engine'].getPlugin(p['sg_script_path']['local_path']) if pl: pl._pm_ignore_projects = p['sg_ignore_projects']