def connect(host, api_script=None, api_key=None, user=None, password=None):
	if host is None:
		raise ValueError("No Host Url Was Supplied For The Connection")
	
	if len([x for x in [user, password] if x != None]) == 2:
		sg = Shotgun(host,login=user,password=password,convert_datetimes_to_utc=True,http_proxy=None,ensure_ascii=True,connect=True,ca_certs=None)
		
		if sg.authenticate_human_user(user, password) == None:
			raise ValueError("The Human User %s Could Not Be Authenticated" % user)
		
	elif len([x for x in [api_script , api_key] if x != None]) == 2:
		sg = Shotgun(host,script_name=api_script, api_key=api_key,convert_datetimes_to_utc=True,http_proxy=None,ensure_ascii=True,connect=True,ca_certs=None)
	else:
		raise ValueError("Encorrect Values We Supplied For The Connection")
	return sg
def get_dam_session(dam_type="strack"):
    if dam_type == "shotgun":
        from shotgun_api3.shotgun import Shotgun
        return Shotgun(SHOTGUN_URL, SHOTGUN_SCRIPT, SHOTGUN_API_KEY)
    else:
        from strack_api.strack import Strack
        return Strack(STACK_SERVER_URL, STACK_USER, STACK_PASSWD)
示例#3
0
def get_shotgun_handler(root_config):
    """Get shotgun handler instance.

    Returns:
        shotgun_api3.shotgun.Shotgun: shotgun instance.
    """
    shotgun_library_path = root_config['library_paths']['shotgun']
    sys.path.append(shotgun_library_path)

    try:
        from shotgun_api3.shotgun import Shotgun

        shotgun_connection_config = root_config['source_generator']['shotgun'][
            'connection']
        shotgun_handler = Shotgun(
            shotgun_connection_config['site'],
            script_name=shotgun_connection_config['script_name'],
            api_key=shotgun_connection_config['api_key'])

        return shotgun_handler

    except Exception as e:
        logger = logging.getLogger(__name__)
        logger.error(e)
        return None
示例#4
0
def _connect():
    conf = config.Configuration()
    conn = connectors.getDBConnection()

    cur = conn.cursor()
    sg = Shotgun(conf.get(config.CONF_SHOTGUN_URL),
                 conf.get(config.CONF_SHOTGUN_SYNC_SKRIPT),
                 conf.get(config.CONF_SHOTGUN_SYNC_KEY))

    return (conn, cur, sg)
def main():
    """
    to be called
    """
    sg_url = "https://devilfant.shotgunstudio.com"
    sg_test1 = {"name": "test1",
                "key": "e398654c5ec1c6f7c8f71ead33349c58bbf4a058"}

    sg1 = Shotgun( sg_url,
                  sg_test1["name"],
                  sg_test1["key"] )


    entities = sg1.schema_entity_read()

    pprint( entities )

    moduleString = """# -*- coding: utf-8 -*-

\"""@package shotgun_replica.entities
Shotgun Entities

THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

from shotgun_replica._entity_mgmt import _ShotgunEntity
from shotgun_replica import %s

""" % FIELDDEFINITIONSMODULE

    fieldDefModuleString = """# -*- coding: utf-8 -*-

\""" 
THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

"""

    classes = entities.keys()
    classes.sort()

    for entitycode in classes:

        print "processing %s\n" % entitycode
        fieldDefs = sg1.schema_field_read( entitycode )

        try:
            theclass = connectors.getClassOfType( entitycode )
            localFieldDefs = theclass.shotgun_fields
        except ImportError:
            localFieldDefs = None
        except AttributeError:
            localFieldDefs = None

        if fieldDefs != localFieldDefs:
            debug.error( "%s fielddefs differ from shotgun to local" % entitycode )

        entityname = cleanSysName( entities[entitycode]["name"]["value"] )
        if entitycode.endswith( "Connection" ):
            entityname = entitycode

        ( classCode, fieldDefCode ) = _createClassCode( entities, entitycode, fieldDefs, entityname )
        moduleString += classCode
        fieldDefModuleString += fieldDefCode

        _createDBFields( entitycode, fieldDefs, entityname )

    packageDir = os.path.dirname( __file__ )
    entityFilename = os.path.join( packageDir,
                                   'entities.py' )
    entity_file = open( entityFilename, 'w' )
    entity_file.write( moduleString )
    entity_file.close()

    fieldDefFilename = os.path.join( packageDir,
                                   '%s.py' % FIELDDEFINITIONSMODULE )
    fieldDef_file = open( fieldDefFilename, 'w' )
    fieldDef_file.write( fieldDefModuleString )
    fieldDef_file.close()
示例#6
0
def main():
    """
    to be called
    """
    sg_url = "https://devilfant.shotgunstudio.com"
    sg_test1 = {
        "name": "test1",
        "key": "e398654c5ec1c6f7c8f71ead33349c58bbf4a058"
    }

    sg1 = Shotgun(sg_url, sg_test1["name"], sg_test1["key"])

    entities = sg1.schema_entity_read()

    pprint(entities)

    moduleString = """# -*- coding: utf-8 -*-

\"""@package shotgun_replica.entities
Shotgun Entities

THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

from shotgun_replica._entity_mgmt import _ShotgunEntity
from shotgun_replica import %s

""" % FIELDDEFINITIONSMODULE

    fieldDefModuleString = """# -*- coding: utf-8 -*-

\""" 
THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

"""

    classes = entities.keys()
    classes.sort()

    for entitycode in classes:

        print "processing %s\n" % entitycode
        fieldDefs = sg1.schema_field_read(entitycode)

        try:
            theclass = connectors.getClassOfType(entitycode)
            localFieldDefs = theclass.shotgun_fields
        except ImportError:
            localFieldDefs = None
        except AttributeError:
            localFieldDefs = None

        if fieldDefs != localFieldDefs:
            debug.error("%s fielddefs differ from shotgun to local" %
                        entitycode)

        entityname = cleanSysName(entities[entitycode]["name"]["value"])
        if entitycode.endswith("Connection"):
            entityname = entitycode

        (classCode, fieldDefCode) = _createClassCode(entities, entitycode,
                                                     fieldDefs, entityname)
        moduleString += classCode
        fieldDefModuleString += fieldDefCode

        _createDBFields(entitycode, fieldDefs, entityname)

    packageDir = os.path.dirname(__file__)
    entityFilename = os.path.join(packageDir, 'entities.py')
    entity_file = open(entityFilename, 'w')
    entity_file.write(moduleString)
    entity_file.close()

    fieldDefFilename = os.path.join(packageDir,
                                    '%s.py' % FIELDDEFINITIONSMODULE)
    fieldDef_file = open(fieldDefFilename, 'w')
    fieldDef_file.write(fieldDefModuleString)
    fieldDef_file.close()
示例#7
0
from PIL import Image
from shotgun_api3.shotgun import Shotgun

parser = argparse.ArgumentParser(description='Generate Shotgun project barcode')
parser.add_argument('-o', '--output', help='Output file', required=True)
parser.add_argument('-p', '--projectid', help='Project ID', required=True)
parser.add_argument('-s', '--server', help='Server URL', required=True)
parser.add_argument('--scriptname', help='Script name', required=True)
parser.add_argument('--scriptkey', help='Script key', required=True)

args = vars(parser.parse_args())

BARCODE_SIZE = (2000, 400) # width, height

print("Connecting to Shotgun")
sg = Shotgun(args['server'], args['scriptname'], args['scriptkey'])

versionEntity = 'Version'
project_id = int(args['projectid'])
barcode_path = args['output']

def get_barcode_image(versions, barcode_path):
    if os.path.exists(barcode_path):
        return Image.open(barcode_path)
    barcode = Image.new('RGB', BARCODE_SIZE)
    for i, frameNum in enumerate(numpy.linspace(0, len(versions), BARCODE_SIZE[0])):
        version = versions[int(frameNum)-1]
        try:
            # nb we get the url just prior to the thumbnail so we don't time out and end up with a broken thumb
            versionData = sg.find_one(versionEntity, [['id', "is", version['id']]], ['code', 'image'])
            # http://stackoverflow.com/questions/7391945/how-do-i-read-image-data-from-a-url-in-python