Skip to content

Commit

Permalink
For #45533, addressed PR comments (moved plugins to examples folder).
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Matto committed Jan 3, 2018
1 parent 2725875 commit b8c14f7
Show file tree
Hide file tree
Showing 78 changed files with 198 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import shotgun_api3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

from __future__ import division
import os
import shotgun_api3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

from __future__ import division
import os
import shotgun_api3
Expand Down
41 changes: 0 additions & 41 deletions src/examplePlugins/calculateCutDuration.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import math
import shotgun_api3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import shotgun_api3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import shotgun_api3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import shotgun_api3
import pytz
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions src/examplePlugins/docs/logArgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# logArgs.py

This is an EXAMPLE PLUGIN.

Use this plugin to determin if the Shotgun Event Daemon has been successfully
installed. It will log all events in Shotgun by spitting out the event
dictionary.

## Args

No settings.
17 changes: 17 additions & 0 deletions src/examplePlugins/docs/sharedStateA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# sharedStateA.py

This is an EXAMPLE PLUGIN.

Global variable shared state.

This plugin demoes how three callbacks can share state through a global variable.

The shared state stores two counters one (sequential) will be incremented
sequentially by each callback and will keep incrementing across event ids.

The second counter (rotating) will be incremented by each successive callback
but will be reset at each new event.

## Args

No settings.
18 changes: 18 additions & 0 deletions src/examplePlugins/docs/sharedStateB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# sharedStateB.py

This is an EXAMPLE PLUGIN.

Args based shared state.

This plugin demoes how three callbacks can share state through the args argument
to registerCallback.

The shared state stores two counters one (sequential) will be incremented
sequentially by each callback and will keep incrementing across event ids.

The second counter (rotating) will be incremented by each successive callback
but will be reset at each new event.

## Args

No settings.
17 changes: 17 additions & 0 deletions src/examplePlugins/docs/sharedStateC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# sharedStateC.py

This is an EXAMPLE PLUGIN.

Object based shared state.

This example aims to show that you can store state in callable object instances.

The shared state stores two counters one (sequential) will be incremented
sequentially by each callback and will keep incrementing across event ids.

The second counter (rotating) will be incremented by each successive callback
but will be reset at each new event.

## Args

No settings.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import shotgun_api3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os
import shotgun_api3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

import os


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# this software in either electronic or hard copy form.
#

# See docs folder for detailed usage info.

"""
Required fields
Shot entity:
Expand Down
51 changes: 32 additions & 19 deletions src/examplePlugins/logArgs.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,64 @@
"""
For detailed information please see
# Copyright 2018 Autodesk, Inc. All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk license agreement
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#

http://shotgunsoftware.github.com/shotgunEvents/api.html
"""
# See docs folder for detailed usage info.

import os
import logging


def registerCallbacks(reg):
"""Register all necessary or appropriate callbacks for this plugin."""
"""
Register all necessary or appropriate callbacks for this plugin.
"""

# Specify who should recieve email notifications when they are sent out.
#
#reg.setEmails('me@mydomain.com')
# reg.setEmails('me@mydomain.com')

# Use a preconfigured logging.Logger object to report info to log file or
# Use a preconfigured logging.Logger object to report info to a log file or
# email. By default error and critical messages will be reported via email
# and logged to file, all other levels are logged to file.
# and logged to file, all other levels are logged to a file.
#
#reg.logger.debug('Loading logArgs plugin.')
# reg.logger.debug('Loading logArgs plugin.')

# Register a callback to into the event processing system.
#
# Arguments:
# - Shotgun script name
# - Shotgun script key
# - Callable
# - Argument to pass through to the callable
# - A filter to match events to so the callable is only invoked when
# appropriate
# - Argument to pass through to the callable
#
#eventFilter = {'Shotgun_Task_Change': ['sg_status_list']}
# eventFilter = {'Shotgun_Task_Change': ['sg_status_list']}
eventFilter = None
reg.registerCallback('$DEMO_SCRIPT_NAME$', '$DEMO_API_KEY$', logArgs, eventFilter, None)
reg.registerCallback(
os.environ["SGDAEMON_LOGARGS_NAME"],
os.environ["SGDAEMON_LOGARGS_KEY"],
logArgs,
eventFilter,
None,
)

# Set the logging level for this particular plugin. Let error and above
# messages through but block info and lower. This is particularly usefull
# Set the logging level for this particular plugin. Let debug and above
# messages through (don't block info, etc). This is particularly usefull
# for enabling and disabling debugging on a per plugin basis.
reg.logger.setLevel(logging.ERROR)
reg.logger.setLevel(logging.DEBUG)


def logArgs(sg, logger, event, args):
"""
A callback that logs its arguments.
@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.
:param sg: Shotgun API handle.
:param logger: Logger instance.
:param event: A Shotgun EventLogEntry entity dictionary.
:param args: Any additional misc arguments passed through this plugin.
"""
logger.info("%s" % str(event))
46 changes: 20 additions & 26 deletions src/examplePlugins/sharedStateA.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
"""
For detailed information please see
# Copyright 2018 Autodesk, Inc. All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk license agreement
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#

http://shotgunsoftware.github.com/shotgunEvents/api.html
# See docs folder for detailed usage info.

Global variable shared state
----------------------------
This plugin demoes how three callbacks can share state through a global variable.
The shared state stores two counters one (sequential) will be incremented
sequentially by each callback and will keep incrementing across event ids.
The second counter (rotating) will be incremented by each successive callback
but will be reset at each new event.
Try me
------
To try the plugin, make sure you copy it into a path mentioned in your .conf's
"paths" ([plugin] section) and change $DEMO_SCRIPT_NAME$ and $DEMO_API_KEY$ for
sane values.
"""
import os

_state = {
'sequential': -1,
Expand All @@ -31,10 +16,12 @@


def registerCallbacks(reg):
"""Register all necessary or appropriate callbacks for this plugin."""
"""
Register all necessary or appropriate callbacks for this plugin.
"""

scriptName = '$DEMO_SCRIPT_NAME$'
scriptKey = '$DEMO_API_KEY$'
scriptName = os.environ["SGDAEMON_SHAREDSTATEA_NAME"]
scriptKey = os.environ["SGDAEMON_SHAREDSTATEA_KEY"]

# Callbacks are called in registration order. So callbackA will be called
# before callbackB and callbackC
Expand All @@ -44,6 +31,13 @@ def registerCallbacks(reg):


def callbackA(sg, logger, event, args):
"""
:param sg: Shotgun API handle.
:param logger: Logger instance.
:param event: A Shotgun EventLogEntry entity dictionary.
:param args: Any additional misc arguments passed through this plugin.
"""

# We know callbackA will be called first because we registered it first.
# As the first thing to run on each event, we can reinizialize the rotating
# counter.
Expand Down
Loading

0 comments on commit b8c14f7

Please sign in to comment.