How to use the ganga.GangaCore.GPIDev.Base.Proxy.ProxyDataDescriptor function in ganga

To help you get started, we’ve selected a few ganga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
logger.debug("ObjectMetaClass Error: %s" % err)
                    raise

                # If this is a method make sure we wrap the method so it's not exposed to GPI objects
                if not isinstance(method, types.FunctionType):
                    continue

                # Wrap the method so that arguments are stripped before the method runs and a proxied object is returned
                f = ProxyMethodDescriptor(k, internal_name)
                f.__doc__ = method.__doc__
                d[k] = f

    # export visible properties... do not export hidden properties
    for attr, item in pluginclass._schema.allItems():
        if not item['hidden']:
            d[attr] = ProxyDataDescriptor(attr)

    return type(name, (GPIProxyObject,), d)
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
def _process_set_value(raw_obj, _val, attr_name, check_read_only=True):
        """
        Process an incoming attribute value.

        Args:fdef _init
            raw_obj: the object the value is being assigned to
            _val: the value being assigned
            attr_name: the name of the attribute being assigned
            check_read_only: enforce the checks of read-only objects. This makes sense to be disabled during object construction.

        Returns:
            The processed value
        """

        val = ProxyDataDescriptor.__recursive_strip(_val)

        new_val = None

        if not raw_obj._schema.hasAttribute(attr_name):
            raise GangaAttributeError("Cannot assign %s, as it is NOT an attribute in the schema for class: %s" % (attr_name, getName(obj))) 

        #logger.debug("__set__")
        item = raw_obj._schema[attr_name]
        if item['protected']:
            raise ProtectedAttributeError('"%s" attribute is protected and cannot be modified' % (attr_name,))
        if raw_obj._readonly():

            if not item.getProperties()['changable_at_resubmit']:
                raise ReadOnlyObjectError('object %s is read-only and attribute "%s" cannot be modified now' % (repr(addProxy(raw_obj)), attr_name))

        if check_read_only:
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
instance.setSchemaAttribute(key, instance._attribute_filter__set__(key, val))

        instance._auto__init__()

        ## THIRD ALLOW FOR APPLICATION AND IS_PREPARED etc TO TRIGGER RELAVENT CODE AND SET THE KEYWORDS FROM THE SCHEMA AGAIN
        ## THIS IS MAINLY FOR THE FIRST EXAMPLE ABOVE

        ## THIS CORRECTLY APPLIES A PROXY TO ALL OBJECT ATTRIBUTES OF AN OBJECT CREATED WITHIN THE GPI

        # initialize all properties from keywords of the constructor
        for k in kwds:
            if instance._schema.hasAttribute(k):
                # This calls the same logic when assigning a named attribute as when we're assigning it to the object
                # There is logic here which we 'could' duplicate but it is over 100 lines of code which then is duplicating funtionality written elsewhere
                try:
                    val = ProxyDataDescriptor._process_set_value(instance, kwds[k], k, False)
                except Exception as err:
                    logger.warning('Error assigning following value to attribute: \'%s\'' % k)
                    logger.warning('value: \'%s\'' % str(kwds[k]))
                    logger.warning('Error: \'%s\'' % str(err))
                    raise GangaValueError('Error constructing object of type: \'%s\'' % getName(instance))
                if isinstance(val, GangaObject):
                    val._auto__init__()
                setattr(instance, k, val)
            else:
                logger.warning('keyword argument in the %s constructor ignored: %s=%s (not defined in the schema)', name, k, kwds[k])

        ## end of _init
        return
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
raise GangaAttributeError("Cannot assign %s, as it is NOT an attribute in the schema for class: %s" % (attr_name, getName(obj))) 

        #logger.debug("__set__")
        item = raw_obj._schema[attr_name]
        if item['protected']:
            raise ProtectedAttributeError('"%s" attribute is protected and cannot be modified' % (attr_name,))
        if raw_obj._readonly():

            if not item.getProperties()['changable_at_resubmit']:
                raise ReadOnlyObjectError('object %s is read-only and attribute "%s" cannot be modified now' % (repr(addProxy(raw_obj)), attr_name))

        if check_read_only:
            # mechanism for locking of preparable attributes
            if item['preparable']:
                ## Does not modify val
                ProxyDataDescriptor.__preparable_set__(raw_obj, val, attr_name)

        # if we set is_prepared to None in the GPI, that should effectively
        # unprepare the application
        if attr_name == 'is_prepared':
            # Replace is_prepared on an application for another ShareDir object
            ## Does not modify val
            ProxyDataDescriptor.__prep_set__(raw_obj, val)

        # catch assignment of 'something'  to a preparable application
        if attr_name == 'application':
            ## Does not modify val
            ProxyDataDescriptor.__app_set__(raw_obj, val)

        # unwrap proxy
        if item.isA(ComponentItem):
            from .Filters import allComponentFilters
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
# catch assignment of 'something'  to a preparable application
        if attr_name == 'application':
            ## Does not modify val
            ProxyDataDescriptor.__app_set__(raw_obj, val)

        # unwrap proxy
        if item.isA(ComponentItem):
            from .Filters import allComponentFilters
            cfilter = allComponentFilters[item['category']]
            stripper = lambda v: stripComponentObject(v, cfilter, item)
        else:
            stripper = None

        if item['sequence']:
            ## Does not modify val
            new_val = ProxyDataDescriptor.__sequence_set__(stripper, raw_obj, val, attr_name)
        else:
            if stripper is not None:
                ## Shouldn't modify val
                new_val = stripper(val)
            else:
                ## Does not modify val
                new_val = ProxyDataDescriptor._stripAttribute(raw_obj, val, attr_name)

        if new_val is None and val is not None:
            new_val = val

        final_val = None
        # apply attribute filter to component items
        if item.isA(ComponentItem):
            ## Does not modify val
            final_val = ProxyDataDescriptor._stripAttribute(raw_obj, new_val, attr_name)
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
if new_val is None and val is not None:
            new_val = val

        final_val = None
        # apply attribute filter to component items
        if item.isA(ComponentItem):
            ## Does not modify val
            final_val = ProxyDataDescriptor._stripAttribute(raw_obj, new_val, attr_name)
        else:
            final_val = new_val

        if final_val is None and val is not None:
            final_val = val

        ## Does not modify val?
        ProxyDataDescriptor._check_type(raw_obj, final_val, attr_name)

        return final_val
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
if not item.getProperties()['changable_at_resubmit']:
                raise ReadOnlyObjectError('object %s is read-only and attribute "%s" cannot be modified now' % (repr(addProxy(raw_obj)), attr_name))

        if check_read_only:
            # mechanism for locking of preparable attributes
            if item['preparable']:
                ## Does not modify val
                ProxyDataDescriptor.__preparable_set__(raw_obj, val, attr_name)

        # if we set is_prepared to None in the GPI, that should effectively
        # unprepare the application
        if attr_name == 'is_prepared':
            # Replace is_prepared on an application for another ShareDir object
            ## Does not modify val
            ProxyDataDescriptor.__prep_set__(raw_obj, val)

        # catch assignment of 'something'  to a preparable application
        if attr_name == 'application':
            ## Does not modify val
            ProxyDataDescriptor.__app_set__(raw_obj, val)

        # unwrap proxy
        if item.isA(ComponentItem):
            from .Filters import allComponentFilters
            cfilter = allComponentFilters[item['category']]
            stripper = lambda v: stripComponentObject(v, cfilter, item)
        else:
            stripper = None

        if item['sequence']:
            ## Does not modify val
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
def __subitems_read_only(obj):
        can_be_modified = []
        for name, item in obj._schema.allItems():
            ## This object inherits from Node therefore likely has a schema too.
            obj_attr = getattr(obj, name)
            if isType(obj_attr, Node):
                can_be_modified.append( ProxyDataDescriptor.__subitems_read_only(obj_attr) )
            else:

                ## This object doesn't inherit from Node and therefore needs to be evaluated
                if item.getProperties()['changable_at_resubmit']:
                    can_be_modified.append( True )
                else:
                    can_be_modified.append( False )
        
        can_modify = False
        for i in can_be_modified:
            can_modify = can_modify or i

        return can_modify
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Proxy.py View on Github external
# mechanism for locking of preparable attributes
            if item['preparable']:
                ## Does not modify val
                ProxyDataDescriptor.__preparable_set__(raw_obj, val, attr_name)

        # if we set is_prepared to None in the GPI, that should effectively
        # unprepare the application
        if attr_name == 'is_prepared':
            # Replace is_prepared on an application for another ShareDir object
            ## Does not modify val
            ProxyDataDescriptor.__prep_set__(raw_obj, val)

        # catch assignment of 'something'  to a preparable application
        if attr_name == 'application':
            ## Does not modify val
            ProxyDataDescriptor.__app_set__(raw_obj, val)

        # unwrap proxy
        if item.isA(ComponentItem):
            from .Filters import allComponentFilters
            cfilter = allComponentFilters[item['category']]
            stripper = lambda v: stripComponentObject(v, cfilter, item)
        else:
            stripper = None

        if item['sequence']:
            ## Does not modify val
            new_val = ProxyDataDescriptor.__sequence_set__(stripper, raw_obj, val, attr_name)
        else:
            if stripper is not None:
                ## Shouldn't modify val
                new_val = stripper(val)