def getSgObj( dataObj ):
    if type( dataObj ) == dict:
        if dataObj.has_key( "type" ) and dataObj.has_key( "id" ):
            if dataObj["id"] == UNKNOWN_SHOTGUN_ID and dataObj.has_key( "__local_id" ) and dataObj["__local_id"] != UNKNOWN_SHOTGUN_ID:
                remoteID = connectors.getRemoteID( dataObj["type"], dataObj["__local_id"] )
                return { "type": dataObj["type"],
                         "id": remoteID }
            else:
                return { "type": dataObj["type"],
                         "id": dataObj["id"] }
        return None
    elif isinstance( dataObj, base_entity.ShotgunBaseEntity ) or type( dataObj ) == connectors.PostgresEntityType:
        return dataObj.getSgObj()
示例#2
0
def getSgObj(dataObj):
    if type(dataObj) == dict:
        if dataObj.has_key("type") and dataObj.has_key("id"):
            if dataObj["id"] == UNKNOWN_SHOTGUN_ID and dataObj.has_key(
                    "__local_id"
            ) and dataObj["__local_id"] != UNKNOWN_SHOTGUN_ID:
                remoteID = connectors.getRemoteID(dataObj["type"],
                                                  dataObj["__local_id"])
                return {"type": dataObj["type"], "id": remoteID}
            else:
                return {"type": dataObj["type"], "id": dataObj["id"]}
        return None
    elif isinstance(dataObj, base_entity.ShotgunBaseEntity) or type(
            dataObj) == connectors.PostgresEntityType:
        return dataObj.getSgObj()
示例#3
0
    def getSgObj(self):
        """
        get minimal dict for use with shotgun (jsonable) 
        
        @return: returns None if not yet in shotgun
        """

        remote_id = self.getRemoteID()

        if remote_id == None or remote_id == shotgun_replica.UNKNOWN_SHOTGUN_ID:
            remote_id = connectors.getRemoteID(self.getType(), self.getLocalID())

        if remote_id == None or remote_id == shotgun_replica.UNKNOWN_SHOTGUN_ID:
            return None
        else:
            return {"type": self.getType(), "id": remote_id}
示例#4
0
    def getSgObj( self ):
        """
        get minimal dict for use with shotgun (jsonable) 
        
        @return: returns None if not yet in shotgun
        """

        remote_id = self.getRemoteID()

        if remote_id == None or remote_id == shotgun_replica.UNKNOWN_SHOTGUN_ID:
            remote_id = connectors.getRemoteID( self.getType(), self.getLocalID() )

        if remote_id == None or remote_id == shotgun_replica.UNKNOWN_SHOTGUN_ID:
            return None
        else:
            return {'type': self.getType(),
                    'id': remote_id
                    }
示例#5
0
    def _changeEntity(self, event):
        """ process a change entity event
        """

        entity = event["corr_entity"]
        entityObj = getObject(entity.type,
                              remote_id=entity.remote_id,
                              local_id=entity.local_id,
                              includeRetireds=True)

        if entityObj == None:
            exception = "Object not available %s local:%s remote:%s\n\n" % (
                str(entity.type), str(entity.local_id), str(entity.remote_id))

            self._setProcessed(event, exception=exception)
            return False

        data = event["changed_values"]

        fieldDefs = connectors.getClassOfType(entity.type).shotgun_fields

        hasFields = True
        for attribute in data.keys():
            if not fieldDefs.has_key(attribute):
                hasFields = False

        if not hasFields:
            exception = "some fields not available %s local:%s remote:%s" % (
                str(entity.type), str(entity.local_id), str(entity.remote_id))
            self._setProcessed(event, exception=exception)
            return False
        else:
            for attribute in data.keys():
                dataType = fieldDefs[attribute]["data_type"]["value"]
                value = data[attribute]

                if value == None:
                    continue

                if dataType == "float":
                    data[attribute] = float(value)
                elif dataType == "entity":
                    data[attribute] = getSgObj(value)
                elif dataType == "multi_entity":
                    newvalue = []
                    for sgObj in value:
                        newvalue.append(getSgObj(sgObj))
                    data[attribute] = newvalue
                elif dataType == "date_time":
                    if type(value) == unicode or type(value) == str:
                        data[attribute] = datetime.datetime.strptime(
                            value, "%Y-%m-%d %H:%M:%S")
                    if value.tzinfo == None:
                        from pytz import timezone
                        zurich = timezone("Europe/Zurich")
                        value = zurich.localize(value)
                elif dataType == "date":
                    if type(value) == unicode or type(value) == str:
                        data[attribute] = datetime.datetime.strptime(
                            value, "%Y-%m-%d").date()
                elif dataType == "duration":
                    if type(value) == float:
                        data[attribute] = int(value * 60)

            if fieldDefs.has_key(
                    "sg_remotely_updated_by") and event["updated_by"] != None:
                data["sg_remotely_updated_by"] = event["updated_by"].getSgObj()

            try:
                debug.debug(data)

                if entityObj.getType().endswith(
                        "Connection") and entityObj.getRemoteID(
                        ) == UNKNOWN_SHOTGUN_ID:
                    remoteID = connectors.getRemoteID(entityObj.getType(),
                                                      entityObj.getLocalID())
                    if remoteID == None or remoteID == UNKNOWN_SHOTGUN_ID:
                        # Connection-Entities need first the corresponding remote-id
                        # they get that by the shotgun-event triggered by the event that causes this connection-entity to be created
                        # so we simply have to wait and do nothing (hopefully ;)
                        debug.info(
                            "waiting for a connection-entitiy to appear %s" %
                            (str(entityObj), ))
                        return True

                self.sg.update(entityObj.getType(), entityObj.getRemoteID(),
                               data)
                self._setProcessed(event)
                return True
            except shotgun_api3.Fault, fault:
                #event["type"] = "CouchdbChangeEvents"
                exception = "Error %s" % (str(fault))
                self._setProcessed(event, exception=exception)
                return False
    def _changeEntity( self, event ):
        """ process a change entity event
        """

        entity = event["corr_entity"]
        entityObj = getObject( entity.type,
                               remote_id = entity.remote_id,
                               local_id = entity.local_id,
                               includeRetireds = True )

        if entityObj == None:
            exception = "Object not available %s local:%s remote:%s\n\n" % ( str( entity.type ),
                                                                             str( entity.local_id ),
                                                                             str( entity.remote_id ) )

            self._setProcessed( event, exception = exception )
            return False

        data = event["changed_values"]

        fieldDefs = connectors.getClassOfType( entity.type ).shotgun_fields

        hasFields = True
        for attribute in data.keys():
            if not fieldDefs.has_key( attribute ):
                hasFields = False

        if not hasFields:
            exception = "some fields not available %s local:%s remote:%s" % ( str( entity.type ),
                                                                              str( entity.local_id ),
                                                                              str( entity.remote_id ) )
            self._setProcessed( event, exception = exception )
            return False
        else:
            for attribute in data.keys():
                dataType = fieldDefs[attribute]["data_type"]["value"]
                value = data[attribute]

                if dataType == "float":
                    data[attribute] = float( value )
                elif dataType == "entity":
                    data[attribute] = getSgObj( value )
                elif dataType == "multi_entity":
                    newvalue = []
                    for sgObj in value:
                        newvalue.append( getSgObj( sgObj ) )
                    data[attribute] = newvalue
                elif dataType == "date_time":
                    if type( value ) == type( u"" ):
                        data[attribute] = datetime.datetime.strptime( value, "%Y-%m-%d %H:%M:%S" )
                elif dataType == "date":
                    if type( value ) == type( u"" ):
                        data[attribute] = datetime.datetime.strptime( value, "%Y-%m-%d" ).date()
                elif dataType == "duration":
                    if type( value ) == float:
                        data[attribute] = int( value * 60 )

            if fieldDefs.has_key( "sg_remotely_updated_by" ):
                data["sg_remotely_updated_by"] = event["updated_by"].getSgObj()

            try:
                debug.debug( data )

                if entityObj.getType().endswith( "Connection" ) and entityObj.getRemoteID() == UNKNOWN_SHOTGUN_ID:
                    remoteID = connectors.getRemoteID( entityObj.getType(), entityObj.getLocalID() )
                    if remoteID == None or remoteID == UNKNOWN_SHOTGUN_ID:
                        # Connection-Entities need first the corresponding remote-id
                        # they get that by the shotgun-event triggered by the event that causes this connection-entity to be created
                        # so we simply have to wait and do nothing (hopefully ;)
                        debug.info( "waiting for a connection-entitiy to appear %s" % ( str( entityObj ),  ) )
                        return True

                self.sg.update( entityObj.getType(), entityObj.getRemoteID(), data )
                self._setProcessed( event )
                return True
            except shotgun_api3.Fault, fault:
                #event["type"] = "CouchdbChangeEvents"
                exception = "Error %s" % ( str( fault ) )
                self._setProcessed( event, exception = exception )
                return False