예제 #1
0
 def to_rtype(self, v):
     if isinstance(v, unicode):
         v = v.encode('utf-8')
     return rtype(v)
예제 #2
0
 def testConversionMethod(self):
     assert None == rtype(None)
     assert rlong(1) == rtype(rlong(1))  # Returns self
     assert rbool(True) == rtype(True)
     # Unsupported
     # assert rdouble(0) == rtype(Double.valueOf(0))
     assert rfloat(0) == rtype(float(0))
     assert rlong(0) == rtype(int(0))
     assert rint(0) == rtype(int(0))
     assert rstring("string") == rtype("string")
     # Unsupported
     # assert rtime(time) == rtype(new Timestamp(time))
     rtype(omero.model.ImageI())
     rtype(omero.grid.JobParams())
     rtype(set([rlong(1)]))
     rtype(list([rlong(2)]))
     rtype({})
     # Unsupported
     # rtype(array)
     try:
         rtype(())
         assert False, "Shouldn't be able to handle this yet"
     except omero.ClientError:
         pass
예제 #3
0
    def __init__(self,
                 name,
                 optional=True,
                 out=False,
                 description=None,
                 default=None,
                 **kwargs):

        # Non-Param attributes
        omero.grid.Param.__init__(self)

        # Non-Param attributes
        self._name = name
        self._in = True
        self._out = out

        # Other values will be filled in by the kwargs
        # Mostly leaving these for backwards compatibility
        self.description = description
        self.optional = optional

        # Assign all the kwargs
        for k, v in list(kwargs.items()):
            if not hasattr(self, k):
                TYPE_LOG.warn("Unknown property: %s", k)
            setattr(self, k, v)

        _DEF = self.__get(self.PROTOTYPE_DEFAULT, False)
        _FUN = self.__get(self.PROTOTYPE_FUNCTION)
        _MAX = self.__get(self.PROTOTYPE_MAX)
        _MIN = self.__get(self.PROTOTYPE_MIN)
        _VAL = self.__get(self.PROTOTYPE_VALUES)

        # Someone specifically set the prototype, then
        # we assume that useDefault should be True
        # For whatever reason, inheritance isn't working.
        if default is not None:
            newfunc = _FUN
            newdefault = default
            if isinstance(self, List):
                if isinstance(default, (list, tuple)):
                    newdefault = wrap(default).val
                elif isinstance(default, omero.RCollection):
                    newfunc = lambda x: x
                elif isinstance(default, omero.RType):
                    default = [default]
                else:
                    newfunc = lambda x: x
                    newdefault = rlist([rtype(default)])
            self.useDefault = True
            self.prototype = newfunc(newdefault)
        else:
            if not callable(_FUN):
                raise ValueError("Bad prototype function: %s" % _FUN)

            # To prevent weirdness, if the class default is
            # callable, we'll assume its a constructor and
            # create a new one to prevent modification.
            try:
                _def = _DEF()
            except TypeError:
                _def = _DEF
            self.prototype = _FUN(_def)

        # The following use wrap to guarantee that an rtype is present
        if self.min is not None:
            if _MIN is None:
                self.min = _FUN(self.min)
            else:
                self.min = _MIN(self.min)

        if self.max is not None:
            if _MAX is None:
                self.max = _FUN(self.max)
            else:
                self.max = _MAX(self.max)

        if self.values is not None:
            if _VAL is None:
                self.values = wrap(self.values)
            else:
                self.values = _VAL(self.values)

        # Now if useDefault has been set, either manually, or
        # via setting default="..." we check that the default
        # value matches a value if present
        if self.values is not None and self.values and self.useDefault:
            if isinstance(self.prototype, omero.RCollection):
                test = unwrap(self.prototype.val[0])
            else:
                test = unwrap(self.prototype)
            values = unwrap(self.values)
            if test not in values:
                raise ValueError("%s is not in %s" % (test, values))
def run():
    '''
    '''
    client = scripts.client(
        'Edit_Object_Attribute.py',
        'Edit the attributes of an object',

        scripts.String('Data_Type', optional=False, grouping='1',
                       description='The data type you want to work with.'),

        scripts.Long('ID', optional=False, grouping='2',
                     description='Object ID'),

        scripts.String('Attribute', optional=False, grouping='3',
                       description='Attribute to set'),

        scripts.String('Attribute_Type', optional=False, grouping='4',
                       description='Type of the attribute to set',
                       values=[
                           rstring('Bool'), rstring('Double'),
                           rstring('Float'), rstring('Int'),
                           rstring('Long'), rstring('Time'),
                           rstring('String')
                       ], default='String'),

        scripts.String('Value', optional=False, grouping='5',
                       description='Value to set'),

        version='0.1',
        authors=['Chris Allan'],
        institutions=['Glencoe Software Inc.'],
        contact='*****@*****.**',
    )

    try:
        script_params = {}
        for key in client.getInputKeys():
            if client.getInput(key):
                script_params[key] = client.getInput(key, unwrap=True)

        session = client.getSession()
        update_service = session.getUpdateService()
        query_service = session.getQueryService()

        value = script_params['Value']
        if script_params['Attribute_Type'] == 'Bool':
            value = rtype(bool(value))
        elif script_params['Attribute_Type'] == 'Double':
            value = rdouble(float(value))
        elif script_params['Attribute_Type'] == 'Float':
            value = rtype(float(value))
        elif script_params['Attribute_Type'] == 'Int':
            value = rtype(int(value))
        elif script_params['Attribute_Type'] == 'Long':
            value = rtype(long(value))
        elif script_params['Attribute_Type'] == 'Time':
            value = rtime(long(value))
        else:
            value = rtype(value)

        ctx = {'omero.group': '-1'}
        o = query_service.get(
            script_params['Data_Type'], script_params['ID'], ctx)
        setattr(o, script_params['Attribute'], value)
        ctx = None
        try:
            ctx = {'omero.group': str(o.details.group.id.val)}
        except AttributeError:
            pass
        update_service.saveObject(o, ctx)

        client.setOutput('Message', rstring(
            'Setting of attribute successful.'))
    finally:
        client.closeSession()
예제 #5
0
    def __init__(self, name, optional=True, out=False, description=None, default=None, **kwargs):

        # Non-Param attributes
        omero.grid.Param.__init__(self)

        # Non-Param attributes
        self._name = name
        self._in = True
        self._out = out

        # Other values will be filled in by the kwargs
        # Mostly leaving these for backwards compatibility
        self.description = description
        self.optional = optional

        # Assign all the kwargs
        for k, v in kwargs.items():
            if not hasattr(self, k):
                TYPE_LOG.warn("Unknown property: %s", k)
            setattr(self, k, v)

        _DEF = self.__get(self.PROTOTYPE_DEFAULT, False)
        _FUN = self.__get(self.PROTOTYPE_FUNCTION)
        _MAX = self.__get(self.PROTOTYPE_MAX)
        _MIN = self.__get(self.PROTOTYPE_MIN)
        _VAL = self.__get(self.PROTOTYPE_VALUES)

        # Someone specifically set the prototype, then
        # we assume that useDefault should be True
        # For whatever reason, inheritance isn't working.
        if default is not None:
            newfunc = _FUN
            newdefault = default
            if isinstance(self, List):
                if isinstance(default, (list, tuple)):
                    newdefault = wrap(default).val
                elif isinstance(default, omero.RCollection):
                    newfunc = lambda x: x
                elif isinstance(default, omero.RType):
                    default = [default]
                else:
                    newfunc = lambda x: x
                    newdefault = rlist([rtype(default)])
            self.useDefault = True
            self.prototype = newfunc(newdefault)
        else:
            if not callable(_FUN):
                raise ValueError("Bad prototype function: %s" % _FUN)

            # To prevent weirdness, if the class default is
            # callable, we'll assume its a constructor and
            # create a new one to prevent modification.
            try:
                _def = _DEF()
            except TypeError:
                _def = _DEF
            self.prototype = _FUN(_def)

        # The following use wrap to guarantee that an rtype is present
        if self.min is not None:
            if _MIN is None:
                self.min = _FUN(self.min)
            else:
                self.min = _MIN(self.min)

        if self.max is not None:
            if _MAX is None:
                self.max = _FUN(self.max)
            else:
                self.max = _MAX(self.max)

        if self.values is not None:
            if _VAL is None:
                self.values = wrap(self.values)
            else:
                self.values = _VAL(self.values)

        # Now if useDefault has been set, either manually, or
        # via setting default="..." we check that the default
        # value matches a value if present
        if self.values is not None and self.values and self.useDefault:
            if isinstance(self.prototype, omero.RCollection):
                test = unwrap(self.prototype.val[0])
            else:
                test = unwrap(self.prototype)
            values = unwrap(self.values)
            if test not in values:
                raise ValueError("%s is not in %s" % (test, values))
예제 #6
0
 def testConversionMethod(self):
     assert None == rtype(None)
     assert rlong(1) == rtype(rlong(1))  # Returns self
     assert rbool(True) == rtype(True)
     # Unsupported
     # assert rdouble(0) == rtype(Double.valueOf(0))
     assert rfloat(0) == rtype(float(0))
     assert rlong(0) == rtype(long(0))
     assert rint(0) == rtype(int(0))
     assert rstring("string") == rtype("string")
     # Unsupported
     # assert rtime(time) == rtype(new Timestamp(time))
     rtype(omero.model.ImageI())
     rtype(omero.grid.JobParams())
     rtype(set([rlong(1)]))
     rtype(list([rlong(2)]))
     rtype({})
     # Unsupported
     # rtype(array)
     try:
         rtype(())
         assert False, "Shouldn't be able to handle this yet"
     except omero.ClientError:
         pass
예제 #7
0
def run():
    '''
    '''
    client = scripts.client(
        'Edit_Object_Attribute.py',
        'Edit the attributes of an object',
        scripts.String('Data_Type',
                       optional=False,
                       grouping='1',
                       description='The data type you want to work with.'),
        scripts.Long('ID',
                     optional=False,
                     grouping='2',
                     description='Object ID'),
        scripts.String('Attribute',
                       optional=False,
                       grouping='3',
                       description='Attribute to set'),
        scripts.String('Attribute_Type',
                       optional=False,
                       grouping='4',
                       description='Type of the attribute to set',
                       values=[
                           rstring('Bool'),
                           rstring('Double'),
                           rstring('Float'),
                           rstring('Int'),
                           rstring('Long'),
                           rstring('Time'),
                           rstring('String')
                       ],
                       default='String'),
        scripts.String('Value',
                       optional=False,
                       grouping='5',
                       description='Value to set'),
        version='0.1',
        authors=['Chris Allan'],
        institutions=['Glencoe Software Inc.'],
        contact='*****@*****.**',
    )

    try:
        script_params = {}
        for key in client.getInputKeys():
            if client.getInput(key):
                script_params[key] = client.getInput(key, unwrap=True)

        session = client.getSession()
        update_service = session.getUpdateService()
        query_service = session.getQueryService()

        value = script_params['Value']
        if script_params['Attribute_Type'] == 'Bool':
            value = rtype(bool(value))
        elif script_params['Attribute_Type'] == 'Double':
            value = rdouble(float(value))
        elif script_params['Attribute_Type'] == 'Float':
            value = rtype(float(value))
        elif script_params['Attribute_Type'] == 'Int':
            value = rtype(int(value))
        elif script_params['Attribute_Type'] == 'Long':
            value = rtype(int(value))
        elif script_params['Attribute_Type'] == 'Time':
            value = rtime(int(value))
        else:
            value = rtype(value)

        ctx = {'omero.group': '-1'}
        o = query_service.get(script_params['Data_Type'], script_params['ID'],
                              ctx)
        setattr(o, script_params['Attribute'], value)
        ctx = None
        try:
            ctx = {'omero.group': str(o.details.group.id.val)}
        except AttributeError:
            pass
        update_service.saveObject(o, ctx)

        client.setOutput('Message',
                         rstring('Setting of attribute successful.'))
    finally:
        client.closeSession()
def run():
    """
    """
    client = scripts.client(
        "Edit_Object_Attribute.py",
        "Edit the attributes of an object",
        scripts.String("Data_Type", optional=False, grouping="1", description="The data type you want to work with."),
        scripts.Long("ID", optional=False, grouping="2", description="Object ID"),
        scripts.String("Attribute", optional=False, grouping="3", description="Attribute to set"),
        scripts.String(
            "Attribute_Type",
            optional=False,
            grouping="4",
            description="Type of the attribute to set",
            values=[
                rstring("Bool"),
                rstring("Double"),
                rstring("Float"),
                rstring("Int"),
                rstring("Long"),
                rstring("Time"),
                rstring("String"),
            ],
            default="String",
        ),
        scripts.String("Value", optional=False, grouping="5", description="Value to set"),
        version="0.1",
        authors=["Chris Allan"],
        institutions=["Glencoe Software Inc."],
        contact="*****@*****.**",
    )

    try:
        script_params = {}
        for key in client.getInputKeys():
            if client.getInput(key):
                script_params[key] = client.getInput(key, unwrap=True)

        session = client.getSession()
        update_service = session.getUpdateService()
        query_service = session.getQueryService()

        value = script_params["Value"]
        if script_params["Attribute_Type"] == "Bool":
            value = rtype(bool(value))
        elif script_params["Attribute_Type"] == "Double":
            value = rdouble(float(value))
        elif script_params["Attribute_Type"] == "Float":
            value = rtype(float(value))
        elif script_params["Attribute_Type"] == "Int":
            value = rtype(int(value))
        elif script_params["Attribute_Type"] == "Long":
            value = rtype(long(value))
        elif script_params["Attribute_Type"] == "Time":
            value = rtime(long(value))
        else:
            value = rtype(value)

        ctx = {"omero.group": "-1"}
        o = query_service.get(script_params["Data_Type"], script_params["ID"], ctx)
        setattr(o, script_params["Attribute"], value)
        ctx = None
        try:
            ctx = {"omero.group": str(o.details.group.id.val)}
        except AttributeError:
            pass
        update_service.saveObject(o, ctx)

        client.setOutput("Message", rstring("Setting of attribute successful."))
    finally:
        client.closeSession()
예제 #9
-1
 def to_rtype(self, v):
     if isinstance(v, unicode):
         v = v.encode('utf-8')
     return rtype(v)