def session(self): # Set the session, building it from a generic Shotgun if nothing was # given. This requires a `shotgun_api3_registry.connect()` function. if not self._shotgun and not self._session: import shotgun_api3_registry self._shotgun = shotgun_api3_registry.connect(auto_name_stack_depth=1) return self._session or Session(self._shotgun)
def shotgun_api3_connect(*args, **kwargs): eps = [] for ep in pkg_resources.iter_entry_points('shotgun_api3_connect'): eps.append((ep, True)) for ep in pkg_resources.iter_entry_points('shotgun_api3_kwargs'): eps.append((ep, False)) eps.sort(key=lambda (ep, _): ep.name) for ep, is_direct in eps: func = ep.load() res = func(*args, **kwargs) if not res: continue if is_direct: return res import shotgun_api3 return shotgun_api3.Shotgun(**res) # Fall back onto the shotgun_api3_registry module. try: import shotgun_api3_registry as m except ImportError: pass else: return m.connect(*args, **kwargs) raise ValueError( "No shotgun_api3_connect/shotgun_api3_kwargs entry point or shotgun_api3_registry module found." )
def session(self): # Set the session, building it from a generic Shotgun if nothing was # given. This requires a `shotgun_api3_registry.connect()` function. if not self._shotgun and not self._session: import shotgun_api3_registry self._shotgun = shotgun_api3_registry.connect( auto_name_stack_depth=1) return self._session or Session(self._shotgun)
def shotgun(self): # Automatically generate Shotgun when we need one. # We use False to track that there should be nothing set here. if self._shotgun is None: import shotgun_api3_registry self._shotgun = ShotgunPool.wrap(shotgun_api3_registry.connect( *self._shotgun_args, **self._shotgun_kwargs )) return self._shotgun or None
def shotgun(self): # Automatically generate Shotgun when we need one. # We use False to track that there should be nothing set here. if self._shotgun is None: import shotgun_api3_registry self._shotgun = ShotgunPool.wrap( shotgun_api3_registry.connect(*self._shotgun_args, **self._shotgun_kwargs)) return self._shotgun or None
def __init__(self, shotgun=None, *args, **kwargs): # Lookup strings in the script registry. if isinstance(shotgun, basestring): import shotgun_api3_registry shotgun = shotgun_api3_registry.connect(shotgun, *args, **kwargs) # Wrap basic shotgun instances in our threader. if isinstance(shotgun, _BaseShotgun): shotgun = ShotgunPool(shotgun) self.shotgun = shotgun self._cache = {}
def __init__(self, shotgun=None, schema=None, *args, **kwargs): # Lookup strings in the script registry. if isinstance(shotgun, basestring): import shotgun_api3_registry shotgun = shotgun_api3_registry.connect(shotgun, *args, **kwargs) # Wrap basic shotgun instances in our threader. self._shotgun = ShotgunPool.wrap(shotgun) self._shotgun_args = None if shotgun else args self._shotgun_kwargs = None if shotgun else kwargs self._schema = schema self._cache = {} self._thread_pool = None
def get_shotgun(*args, **kwargs): if ('SHOTGUN_SERVER' in os.environ and 'SHOTGUN_SCRIPT_NAME' in os.environ and 'SHOTGUN_SCRIPT_KEY' in os.environ): return shotgun_api3.Shotgun( os.environ['SHOTGUN_SERVER'], os.environ['SHOTGUN_SCRIPT_NAME'], os.environ['SHOTGUN_SCRIPT_KEY'], ) try: import shotgun_api3_registry except ImportError: raise RuntimeError("Set $SHOTGUN_{SERVER,SCRIPT_NAME,SCRIPT_KEY} or provide shotgun_api3_registry.connect()") else: return shotgun_api3_registry.connect(*args, **kwargs)
def get_shotgun(*args, **kwargs): if ('SHOTGUN_SERVER' in os.environ and 'SHOTGUN_SCRIPT_NAME' in os.environ and 'SHOTGUN_SCRIPT_KEY' in os.environ): return shotgun_api3.Shotgun( os.environ['SHOTGUN_SERVER'], os.environ['SHOTGUN_SCRIPT_NAME'], os.environ['SHOTGUN_SCRIPT_KEY'], ) try: import shotgun_api3_registry except ImportError: raise RuntimeError("Set $SHOTGUN_API3_ARGS or provide shotgun_api3_registry.connect()") else: return shotgun_api3_registry.connect(*args, **kwargs)
def callback(event): # Must be setting it to a non-zero version. # NOTE: We MUST check the meta for this, otherwise we are liable to # schedule this job multiple times as the `entity` field is always # up to date. version = event.meta.get('new_value') if not version: log.info('Publish is still being created; skipping') return sg = Session(connect()) entity = sg.merge(event)['entity'] if not entity: log.info('Publish appeares to have been retired; skipping') return entity.fetch(('sg_link', 'sg_link.Task.step.Step.short_name', 'sg_type')) # For now, we only run for the Testing Sandbox. #if event['project']['id'] != 66: # log.info('Project %r in not Testing Sandbox; skipping' % (event['project'].get('name') or event['project']['id'])) # return # Our first job, is to create camera and geocache publishes from generic maya scenes. pub_type = entity.get('sg_type') if pub_type != 'maya_scene': log.info('sg_type %r is not maya_scene; skipping' % pub_type) return step_code = entity.get('sg_link.Task.step.Step.short_name') if step_code not in ('Anim', 'Roto', 'Rotomation'): log.info('sg_link.step.short_code %s is not Anim or Roto; skipping' % step_code) return # TODO: Make sure they don't already exist. log.info('Delegating to sgactions') call_in_subprocess('%s:republish' % __file__, [entity['id']])
def Shotgun(): return Session(shotgun_api3_registry.connect("sgviewer"))
def shotgun_api(request_type): sg = shotgun_api3_registry.connect() func = getattr(sg, request_type) print request.content_type return func(**request.json)
def Shotgun(): return shotgun_api3_registry.connect('sgsession.tests', server=_shotgun_server)
from shotgun_api3_registry import get_args, get_kwargs, connect sg = connect()
if __name__ == '__main__': import time from shotgun_api3_registry import connect sg = connect(use_cache=False) schema = Schema() if False: schema.read(sg) schema.dump('sandbox/raw.json', raw=True) else: schema.load_raw('sandbox/raw.json') schema.dump('sandbox/reduced.json') schema.dump('/tmp/reduced.json') t = time.time() schema = Schema() schema.load('/tmp/reduced.json')
def Shotgun(): return Session(shotgun_api3_registry.connect('sgviewer'))
import sgschema parser = argparse.ArgumentParser() parser.add_argument('-n', '--name') parser.add_argument('-r', '--registry-name') parser.add_argument('base_url', nargs='?') parser.add_argument('script_name', nargs='?') parser.add_argument('api_key', nargs='?') args = parser.parse_args() if args.registry_name or not (args.base_url or args.script_name or args.api_key): import shotgun_api3_registry shotgun = shotgun_api3_registry.connect(args.registry_name) else: shotgun = shotgun_api3.Shotgun(args.base_url, args.script_name, args.api_key) schema = sgschema.Schema() schema.read(shotgun) if not args.name: parsed = urlparse.urlparse(shotgun.base_url) args.name = parsed.netloc.split('.')[0] here = os.path.dirname(__file__) schema._dump_raw(os.path.join(here, args.name + '.')) schema.dump(os.path.join(here, args.name + '.json'))
new[field] = value else: for k, v in x.iteritems(): new[k] = self.resolve_structure(v, None, _memo, **kwargs) return new else: return x if __name__ == '__main__': import time from shotgun_api3_registry import connect sg = connect(use_cache=False) schema = Schema() if False: schema.read(sg) schema.dump('sandbox/raw.json', raw=True) else: schema.load_raw('sandbox/raw.json') schema.dump('sandbox/reduced.json') schema.dump('/tmp/reduced.json') t = time.time() schema = Schema() schema.load('/tmp/reduced.json')