示例#1
0
文件: Objects.py 项目: milliams/ganga
 def cloneVal(v):
     if isType(v, list()):
         new_v = GangaList()
         for elem in v:
             new_v.append(self.__cloneVal(elem, obj))
         return new_v
     else:
         return self.__cloneVal(v, obj)
示例#2
0
    def testPrintingGPIObjectList(self):
        from Ganga.GPI import GangaList, TFile

        g = GangaList()
        for _ in range(10):
            g.append(self._makeRandomTFile())

        g_string = str(g)
        assert eval(g_string) == g, 'String should correctly eval'
示例#3
0
    def testPrintingGPIObjectList(self):
        from Ganga.GPI import GangaList, TFile

        g = GangaList()
        for _ in range(10):
            g.append(self._makeRandomTFile())

        g_string = str(g)
        assert eval(g_string) == g, 'String should correctly eval'
示例#4
0
文件: Objects.py 项目: milliams/ganga
    def __atomic_set__(self, _obj, _val):

        obj = stripProxy(_obj)
        val = stripProxy(_val)

        from Ganga.GPIDev.Lib.GangaList.GangaList import makeGangaList, GangaList

        checkSet = self._bind_method(obj, self._checkset_name)
        if checkSet is not None:
            checkSet(val)
        this_filter = self._bind_method(obj, self._filter_name)
        if this_filter:
            val = this_filter(val)

        # LOCKING
        obj._getWriteAccess()

        # self._check_getter()

        item = stripProxy(obj._schema[getName(self)])

        def cloneVal(v):
            if isType(v, list()):
                new_v = GangaList()
                for elem in v:
                    new_v.append(self.__cloneVal(elem, obj))
                return new_v
            else:
                return self.__cloneVal(v, obj)

        if item['sequence']:
            _preparable = True if item['preparable'] else False
            if len(val) == 0:
                val = GangaList()
            else:
                if isType(item, Schema.ComponentItem):
                    val = makeGangaList(val, cloneVal, parent=obj, preparable=_preparable)
                else:
                    val = makeGangaList(val, parent=obj, preparable=_preparable)
        else:
            if isType(item, Schema.ComponentItem):
                newListObj = []
                if isinstance(val, list):
                    for elem in val:
                        newListObj.append(cloneVal(elem))
                    val = newListObj
                else:
                    val = cloneVal(val)

        if hasattr(val, '_setParent'):
            val._setParent(obj)
        
        obj.setNodeAttribute(getName(self), val)

        obj._setDirty()
示例#5
0
    def testFullPrintingGPIObjectList(self):

        from Ganga.GPI import full_print, GangaList

        g = GangaList()
        for _ in range(10):
            g.append(self._makeRandomTFile())
        g_string = str(g)

        import StringIO
        sio = StringIO.StringIO()
        full_print(g, sio)
        assert g_string == str(sio.getvalue()).rstrip(), 'Orphaned lists should full_print'
示例#6
0
    def testFullPrintingGPIObjectList(self):

        from Ganga.GPI import full_print, GangaList

        g = GangaList()
        for _ in range(10):
            g.append(self._makeRandomTFile())
        g_string = str(g)

        import StringIO
        sio = StringIO.StringIO()
        full_print(g, sio)
        assert g_string == str(sio.getvalue()).rstrip(), 'Orphaned lists should full_print'
示例#7
0
    def testPrintingPlainList(self):
        from Ganga.GPI import GangaList

        g = GangaList()
        l = []
        print('"'+str(g)+'"')
        print('"'+str(l)+'"')
        print(l == g)
        assert str(l) == str(g), 'Empty lists should print the same'

        for i in xrange(100):
            g.append(i)
            l.append(i)
        assert str(l) == str(g), 'Normal Python objects should print the same'
示例#8
0
    def testPrintingPlainList(self):
        from Ganga.GPI import GangaList

        g = GangaList()
        l = []
        print('"' + str(g) + '"')
        print('"' + str(l) + '"')
        print(l == g)
        assert str(l) == str(g), 'Empty lists should print the same'

        for i in xrange(100):
            g.append(i)
            l.append(i)
        assert str(l) == str(g), 'Normal Python objects should print the same'
示例#9
0
文件: Objects.py 项目: milliams/ganga
    def __cloneVal(self, v, obj):

        item = obj._schema[getName(self)]

        if v is None:
            if item.hasProperty('category'):
                assertion = item['optional'] and (item['category'] != 'internal')
            else:
                assertion = item['optional']
            assert(assertion)
            return None
        elif isinstance(v, str):
            return str(v)
        elif isinstance(v, int):
            return int(v)
        else:
            if not isType(v, Node) and isType(v, (list, type(())) ):
                try:
                    from Ganga.GPI import GangaList
                    new_v = GangaList()
                except ImportError:
                    new_v = []
                for elem in v:
                    new_v.append(self.__cloneVal(elem, obj))
                v = new_v
            if not isType(v, Node):
                raise GangaException("Error: found Object: %s of type: %s expected an object inheriting from Node!" % (str(v), str(type(v))))

            bare_v = stripProxy(v)
            from Ganga.GPIDev.Lib.GangaList.GangaList import GangaList
            if isType(v, GangaList):
                categories = v.getCategory()
                len_cat = len(categories)
                if (len_cat > 1) or ((len_cat == 1) and (categories[0] != item['category'])) and item['category'] != 'internal':
                    # we pass on empty lists, as the catagory is yet to be defined
                    from Ganga.GPIDev.Base.Proxy import GangaAttributeError
                    raise GangaAttributeError('%s: attempt to assign a list containing incompatible objects %s to the property in category "%s"' % (getName(self), v, item['category']))
            else:
                if bare_v._category != item['category'] and item['category'] != 'internal':
                    from Ganga.GPIDev.Base.Proxy import GangaAttributeError
                    raise GangaAttributeError('%s: attempt to assign an incompatible object %s to the property in category "%s"' % (getName(self), v, item['category']))
            if hasattr(bare_v, 'clone'):
                v = bare_v.clone()
            else:
                import copy
                v = copy.deepcopy(bare_v)
            v._setParent(obj)
            return v
示例#10
0
def getNestedList():
    from Ganga.GPI import LocalFile, GangaList
    gl = GangaList()
    gl2 = GangaList()
    for i in range(5):
        gl.append(LocalFile())
    for i in range(5):
        gl2.append(gl)
    return gl2