Esempio n. 1
0
    def calc_hash(self, verify=False):
        """Calculate the MD5 digest of the application's preparable attribute(s), and store
        that value in the application schema. The value is recalculated (and compared against
        the initial value) every time the application is written to the Ganga repository. This
        allows warnings to be generated should an application's locked attributes be changed 
        post-preparation.
        Args:
            verify (bool) : If the hash is to be verified in the future True save it to the hash schema attribute
        """
        from Ganga.GPIDev.Base.Proxy import runProxyMethod
        import cStringIO
        try:
            import hashlib
            digest = hashlib.new('md5')
        except Exception as err:
            logger.debug("Err: %s" % err)
            import md5
            digest = md5.new()

        sio = cStringIO.StringIO()
        runProxyMethod(self, 'printPrepTree', sio)
        digest.update(str(sio.getvalue()))
        tmp = sio.getvalue()
        if verify == False:
            self.hash = digest.hexdigest()
        else:
            # we return true if this is called with verify=True and the current hash is the same as that stored in the schema.
            # this is checked immediately prior to (re)writing the object to
            # the repository
            return digest.hexdigest() == self.hash
Esempio n. 2
0
 def calc_hash(self, verify=False):
     """Calculate the MD5 digest of the application's preparable attribute(s), and store
     that value in the application schema. The value is recalculated (and compared against
     the initial value) every time the application is written to the Ganga repository. This
     allows warnings to be generated should an application's locked attributes be changed 
     post-preparation.
     """
     from Ganga.GPIDev.Base.Proxy import runProxyMethod
     import StringIO
     try:
         import hashlib 
         digest = hashlib.new('md5')
     except:
         import md5
         digest = md5.new()
     
     sio = StringIO.StringIO()
     runProxyMethod(self,'printPrepTree',sio)
     digest.update(str(sio.getvalue()))
     tmp=sio.getvalue()
     if verify == False:
         self.hash = digest.hexdigest()
     else:
         #we return true if this is called with verify=True and the current hash is the same as that stored in the schema.
         #this is checked immediately prior to (re)writing the object to the repository
         return digest.hexdigest() == self.hash
Esempio n. 3
0
 def _CallPrintSummaryTree(self, obj):
     import StringIO
     sio = StringIO.StringIO()
     runProxyMethod(obj, 'printSummaryTree',self.level, self.verbosity_level, self.indent(), sio, self.selection)
     result = sio.getvalue()
     if result.endswith('\n'):
         result = result[0:-1]
     print >>self.out, result,
Esempio n. 4
0
 def _CallPrintSummaryTree(self, obj):
     sio = StringIO()
     if not hasattr(stripProxy(obj), 'printSummaryTree'):
         print("%s" % str(obj), file=self.out)
     else:
         runProxyMethod(obj, 'printSummaryTree', self.level, self.verbosity_level, self.indent(), sio, self.selection, self._interactive)
     result = sio.getvalue()
     if result.endswith('\n'):
         result = result[0:-1]
     print(result, end=' ', file=self.out)
Esempio n. 5
0
 def _CallPrintSummaryTree(self, obj):
     sio = StringIO()
     if not hasattr(stripProxy(obj), 'printSummaryTree'):
         print("%s" % str(obj), file=self.out)
     else:
         runProxyMethod(obj, 'printSummaryTree', self.level,
                        self.verbosity_level, self.indent(), sio,
                        self.selection, self._interactive)
     result = sio.getvalue()
     if result.endswith('\n'):
         result = result[0:-1]
     print(result, end=' ', file=self.out)
Esempio n. 6
0
def full_print(obj, out=None):
    """Print the full contents of a GPI object without abbreviation."""
    import sys
    if out == None:
        out = sys.stdout

    from Ganga.GPIDev.Lib.GangaList import GangaList

    from Ganga.GPIDev.Base.Proxy import stripProxy
    obj = stripProxy(obj)

    if isType(obj, GangaList.GangaList):
        obj_len = len(obj)
        if obj_len == 0:
            print('[]', end=' ', file=out)
        else:
            import cStringIO
            from Ganga.GPIDev.Base.Objects import GangaObject
            outString = '['
            count = 0
            for x in obj:
                if isType(x, GangaObject):
                    sio = cStringIO.StringIO()
                    x.printTree(sio)
                    result = sio.getvalue()
                    # remove trailing whitespace and newlines
                    outString += result.rstrip()
                else:
                    result = str(x)
                    # remove trailing whitespace and newlines
                    outString += result.rstrip()
                count += 1
                if count != obj_len:
                    outString += ', '
            outString += ']'
            print(outString, end=' ', file=out)
        return

    if isProxy(obj):
        import cStringIO
        sio = cStringIO.StringIO()
        runProxyMethod(obj, 'printTree', sio)
        print(sio.getvalue(), end=' ', file=out)
    else:
        print(str(obj), end=' ', file=out)
Esempio n. 7
0
def full_print(obj, out=None, interactive=False):
    """Print the full contents of a GPI object without abbreviation."""
    import sys
    if out == None:
        out = sys.stdout

    from Ganga.GPIDev.Lib.GangaList import GangaList

    obj = stripProxy(obj)

    if isType(obj, GangaList.GangaList):
        obj_len = len(obj)
        if obj_len == 0:
            print('[]', end=' ', file=out)
        else:
            import cStringIO
            from Ganga.GPIDev.Base.Objects import GangaObject
            outString = '['
            count = 0
            for x in obj:
                if isType(x, GangaObject):
                    sio = cStringIO.StringIO()
                    x.printTree(sio, interactive)
                    result = sio.getvalue()
                    # remove trailing whitespace and newlines
                    outString += result.rstrip()
                else:
                    result = str(x)
                    # remove trailing whitespace and newlines
                    outString += result.rstrip()
                count += 1
                if count != obj_len:
                    outString += ', '
            outString += ']'
            print(outString, end=' ', file=out)
        return

    if isProxy(obj):
        import cStringIO
        sio = cStringIO.StringIO()
        runProxyMethod(obj, 'printTree', sio, interactive)
        print(sio.getvalue(), end=' ', file=out)
    else:
        print(str(obj), end=' ', file=out)
Esempio n. 8
0
def summary_print(obj, out=None, interactive=False):
    """Print the summary contents of a GPI object with abbreviation."""
    import sys
    if out == None:
        out = sys.stdout

    _obj = stripProxy(obj)

    from Ganga.GPIDev.Lib.GangaList.GangaList import GangaList
    if isType(_obj, GangaList):
        obj_len = len(_obj)
        if obj_len == 0:
            print('[]', end=' ', file=out)
        else:
            outString = '['
            count = 0
            for x in _obj:
                if isType(x, GangaObject):
                    sio = StringIO()
                    stripProxy(x).printSummaryTree(0, 0, '', out=sio)
                    result = sio.getvalue()
                    # remove trailing whitespace and newlines
                    outString += result.rstrip()
                else:
                    result = str(x)
                    # remove trailing whitespace and newlines
                    outString += result.rstrip()
                count += 1
                if count != obj_len:
                    outString += ', '
            outString += ']'
            print(outString, end=' ', file=out)
        return

    if isProxy(obj) and isType(_obj, GangaObject):
        sio = StringIO()
        runProxyMethod(obj, 'printSummaryTree', 0, 0, '', sio, interactive)
        print(sio.getvalue(), end=' ', file=out)
    else:
        print(str(_obj), end=' ', file=out)
Esempio n. 9
0
def full_print(obj, out=None, interactive=False):
    """Print the full contents of a GPI object without abbreviation."""
    import sys
    if out == None:
        out = sys.stdout

    from Ganga.GPIDev.Lib.GangaList.GangaList import GangaList

    _obj = stripProxy(obj)

    if isType(_obj, GangaList):
        obj_len = len(_obj)
        if obj_len == 0:
            print('[]', end=' ', file=out)
        else:
            outString = '['
            outStringList = []
            for x in _obj:
                if isType(x, GangaObject):
                    sio = StringIO()
                    stripProxy(x).printTree(sio, interactive)
                    result = sio.getvalue()
                    # remove trailing whitespace and newlines
                    outStringList.append(result.rstrip())
                else:
                    # remove trailing whitespace and newlines
                    outStringList.append(str(x).rstrip())
            outString += ', '.join(outStringList)
            outString += ']'
            print(outString, end=' ', file=out)
        return

    if isProxy(obj) and isinstance(_obj, GangaObject):
        sio = StringIO()
        runProxyMethod(obj, 'printTree', sio, interactive)
        print(sio.getvalue(), end=' ', file=out)
    else:
        print(str(_obj), end=' ', file=out)
Esempio n. 10
0
def full_print(obj, out=None, interactive=False):
    """Print the full contents of a GPI object without abbreviation."""
    import sys
    if out == None:
        out = sys.stdout

    from Ganga.GPIDev.Lib.GangaList.GangaList import GangaList

    _obj = stripProxy(obj)

    if isType(_obj, GangaList):
        obj_len = len(_obj)
        if obj_len == 0:
            print('[]', end=' ', file=out)
        else:
            outString = '['
            outStringList = []
            for x in _obj:
                if isType(x, GangaObject):
                    sio = StringIO()
                    stripProxy(x).printTree(sio, interactive)
                    result = sio.getvalue()
                    # remove trailing whitespace and newlines
                    outStringList.append(result.rstrip())
                else:
                    # remove trailing whitespace and newlines
                    outStringList.append(str(x).rstrip())
            outString += ', '.join(outStringList)
            outString += ']'
            print(outString, end=' ', file=out)
        return

    if isProxy(obj) and isinstance(_obj, GangaObject):
        sio = StringIO()
        runProxyMethod(obj, 'printTree', sio, interactive)
        print(sio.getvalue(), end=' ', file=out)
    else:
        print(str(_obj), end=' ', file=out)
Esempio n. 11
0
 def acceptOptional(self, s):
     if s is None:
         print(None, end=' ', file=self.out)
     else:
         runProxyMethod(s, 'accept', self)
Esempio n. 12
0
 def acceptOptional(self,s):
     if s is None:
         print >> self.out, None,
     else:
         runProxyMethod(s,'accept',self)
Esempio n. 13
0
 def acceptOptional(self, s):
     if s is None:
         print(None, end=' ', file=self.out)
     else:
         runProxyMethod(s, 'accept', self)