Example #1
0
def node_name(node): # revised 070207
    """
    return the name property of the node, regardless of which
    model tree node interface it's trying to use [slight kluge]
    """
    try:
        node.mt_name # look for (value computed by) ModelTreeNodeInterface method
    except AttributeError:
        pass
    else:
        return node.mt_name

    try:
        node.name # look for legacy Node variable
    except AttributeError:
            pass
    else:
        return node.name

    try:
        return "%s" % node
    except:
        last_resort = safe_repr(node, maxlen = 20) ### FIX: Undefined variable safe_repr, print_compact_traceback
        print_compact_traceback("node_name fails when trying %%s on node %s: " % last_resort )
        return last_resort
    pass
Example #2
0
def debug_make_BorrowerChunk_raw(do_addmol=True):
    win = env.mainwindow()
    atomset = win.assy.selatoms
    if not atomset:
        env.history.message(
            redmsg(
                "Need selected atoms to make a BorrowerChunk (for debugging only)"
            ))
    else:
        atomset = dict(
            atomset
        )  # copy it, since we shouldn't really add singlets to assy.selatoms...
        for atom in atomset.values(
        ):  # not itervalues, we're changing it in the loop!
            # BTW Python is nicer about this than I expected:
            # exceptions.RuntimeError: dictionary changed size during iteration
            for bp in atom.singNeighbors(
            ):  # likely bugs if these are not added into the set!
                atomset[bp.key] = bp
            assy = atom.molecule.assy  # these are all the same, and we do this at least once
        chunk = BorrowerChunk(assy, atomset)
        if do_addmol:
            win.assy.addmol(chunk)
        import __main__
        __main__._bc = chunk
        env.history.message(
            orangemsg("__main__._bc = %s (for debugging only)" %
                      quote_html(safe_repr(chunk))))
    win.win_update()  #k is this done by caller?
    return
Example #3
0
def getattr_debugprint(obj, attr): #070211; tested, though not usually in use
    """a version of getattr which does better debug printing on exceptions
    (use it as a drop-in replacement for 2-arg getattr to help with debugging)
    """
    try:
        return getattr(obj, attr)
    except AttributeError:
        print "getattr_debugprint: %s has no %r (reraising)" % (safe_repr(obj), attr)
        raise
    pass
def getattr_debugprint(obj, attr):  #070211; tested, though not usually in use
    """a version of getattr which does better debug printing on exceptions
    (use it as a drop-in replacement for 2-arg getattr to help with debugging)
    """
    try:
        return getattr(obj, attr)
    except AttributeError:
        print "getattr_debugprint: %s has no %r (reraising)" % (safe_repr(obj),
                                                                attr)
        raise
    pass
Example #5
0
 def _debug_i_instance_retval(self, res):  #070212
     """
     [private]
     res is about to be returned from self._i_instance;
     perform debug checks [#e someday maybe do other things]
     """
     ##        NumericArrayType = type(ORIGIN)
     ##        if isinstance(res, NumericArrayType):
     ##            return res # has no __class__, but legitimate
     try:
         ##            assert res.__class__.__name__ != 'lexenv_ipath_Expr', "should not be returned from _i_instance: %r" % (res,)
         assert not is_pure_expr(
             res
         ), "pure exprs should not be returned from _i_instance: %r" % (
             res, )
     except:
         print "bug: exception in _debug_i_instance_retval for this res (reraising): %s" % safe_repr(
             res)
         raise
     return
Example #6
0
def debug_make_BorrowerChunk_raw(do_addmol = True):
    win = env.mainwindow()
    atomset = win.assy.selatoms
    if not atomset:
        env.history.message(redmsg("Need selected atoms to make a BorrowerChunk (for debugging only)"))
    else:
        atomset = dict(atomset) # copy it, since we shouldn't really add singlets to assy.selatoms...
        for atom in atomset.values(): # not itervalues, we're changing it in the loop!
            # BTW Python is nicer about this than I expected:
            # exceptions.RuntimeError: dictionary changed size during iteration
            for bp in atom.singNeighbors(): # likely bugs if these are not added into the set!
                atomset[bp.key] = bp
            assy = atom.molecule.assy # these are all the same, and we do this at least once
        chunk = BorrowerChunk(assy, atomset)
        if do_addmol:
            win.assy.addmol(chunk)
        import __main__
        __main__._bc = chunk
        env.history.message(orangemsg("__main__._bc = %s (for debugging only)" % quote_html(safe_repr(chunk))))
    win.win_update() #k is this done by caller?
    return
Example #7
0
    def _debug_i_instance_retval(self, res): #070212
        """
        [private]
        res is about to be returned from self._i_instance;
        perform debug checks [#e someday maybe do other things]
        """
##        NumericArrayType = type(ORIGIN)
##        if isinstance(res, NumericArrayType):
##            return res # has no __class__, but legitimate
        try:
##            assert res.__class__.__name__ != 'lexenv_ipath_Expr', "should not be returned from _i_instance: %r" % (res,)
            assert not is_pure_expr(res), "pure exprs should not be returned from _i_instance: %r" % (res,)
        except:
            print "bug: exception in _debug_i_instance_retval for this res (reraising): %s" % safe_repr(res)
            raise
        return