Issue1109

classification
Title: inspect.stack() not working as intended
Type: Severity: normal
Components: Library Versions: 2.5alpha1
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: fwierzbicki, wesleys, zyasoft
Priority: Keywords:

Created on 2008-08-22.10:31:27 by wesleys, last changed 2008-11-04.15:27:35 by fwierzbicki.

Messages
msg3445 (view) Author: Wesley Schwengle (wesleys) Date: 2008-08-22.10:31:26
I have the following function:

    def _cmd(self, type, *args):
        calling = inspect.stack()[1][3]
        print calling.replace("2", "To")
        #return self.cmd("create" + type + self.cmd_prefix, *args)

Jython 2.2.1:
snapshotTosnaphot

Jython 2.5a1:
Traceback (most recent call last):
  File "./pylogic.py", line 53, in <module>
    test_audit_jobs()
  File "./pylogic.py", line 38, in test_audit_jobs
    k.snapshot2snaphot("test")
  File "./../lib/OSS/bladelogic/AuditJob.py", line 24, in snapshot2snaphot
    return self._cmd("SnapshotToSnapshot", *args)
  File "./../lib/OSS/bladelogic/AuditJob.py", line 19, in _cmd
    calling = inspect.stack()[1][3]
  File "/opt/bladelogic/jython/Lib/inspect.py", line 888, in stack
    return getouterframes(sys._getframe(1), context)
  File "/opt/bladelogic/jython/Lib/inspect.py", line 869, in getouterframes
    framelist.append((frame,) + getframeinfo(frame, context))
  File "/opt/bladelogic/jython/Lib/inspect.py", line 844, in getframeinfo
    lines, lnum = findsource(frame)
  File "/opt/bladelogic/jython/Lib/inspect.py", line 510, in findsource
    if pat.match(lines[lnum]): break
IndexError: index out of range: 138
msg3518 (view) Author: Jim Baker (zyasoft) Date: 2008-09-13.18:19:19
test_inspect.py has tests for inspect.stack, they look comprehensive,
and they pass. Need to have a more comprehensive test submitted for us
to reproduce.
msg3733 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2008-11-03.19:06:30
Hey Jim -- I tried exercising the code snippet, and could not get it to
fail, maybe it was accidentally fixed?  Certainly it isn't enough code
to reproduce the problem.  Since you haven't heard from the original
poster for a while now, do you want to close it?
msg3734 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2008-11-03.19:22:55
oops didn't mean to close -- I'll let Jim decide on that.
msg3747 (view) Author: Wesley Schwengle (wesleys) Date: 2008-11-04.10:41:58
I saw the bug got closed because you haven't received an update from me.
These are the classes which are involved and how I can trigger the bug. 

baseclass.py:

#!/usr/bin/env bljython

import sys
import inspect

class baseclass:
    '''baseclass, abstract class'''

    def __init__(self, jli = None):
        '''Initialize the class'''
        self.debug = 0
        self.jli(jli)
        self.cmd_prefix = self.__module__.split('.')[-1]

    def jli(self, jli = None):
        """Set a jli component so we can call it"""
        if jli != None:
            self.jli = jli

        if self.debug:
            self.debug(self.debug)

        return self.jli

    def _cmd(self, *args):
        '''Executes the JLI command'''
        print "%s %s" % (self.cmd_prefix, " ".join(args));
#        return self.jli.cmd(self.cmd_prefix, *args)

    def debug(self, debug):
        '''Enable debuggin on the jli'''
        self.debug = debug
        if self.jli != None:
            self.jli['debug'] = debug

    def _log_error(self, msg):
        '''Log an error in case we need to log it..'''
        print msg
        sys.exit(4);

    def _unsupported(self):
        '''Function which tells the user the called function is not
        supported..'''
        print "Unsupported function '%s.%s()' called" % (self.cmd_prefix,
                inspect.stack()[1][3])

    def print_me(self):
        '''Function just here for testing.. to be removed'''
        print self.cmd_prefix
        print dir(self)

DepotSoftware.py:

#!/usr/bin/env bljython

import baseclass
import inspect

class DepotSoftware(baseclass.baseclass):
    '''The DepotSoftware name space contains commands to add software to
the Depot.
       The commands in this name space sometimes refer to software
packages. A
       software package is a BLPackage containing one or more software
items.
    '''

    def _add2(self, *args):
        calling = [ k.capitalize() for k in
inspect.stack()[1][3].split('_') ]
        return self._cmd("add" + "".join(calling) +
"ToDepotByGroupName", *args)

    def os_hotfix(self, *args):
        return self._add2(*args)

    def rpm(self, *args):
        return self._add2(*args)

    def service_pack(self, *args):
        return self._add2(*args)

    def solaris_package(self, *args):
        return self._add2(*args)

    def solaris_patch(self, *args):
        return self._add2(*args)

    def solaris_patch_cluster(self, *args):
        return self._add2(*args)

    def aix_package(self, *args):
        return self._add2(*args)

    def aix_patch(self, *args):
        return self._add2(*args)

    def custom_software(self, *args):
        return self._add2(*args)

    def hpux_bundle(self, *args):
        return self._add2(*args)

    def hpux_patch(self, *args):
        return self._add2(*args)

    def hpux_product(self, *args):
        return self._add2(*args)

    def install_shield_package(self, *args):
        return self._add2(*args)

    def msi_package(self, *args):
        return self._add2(*args)


In pylogic.py (testscript) I have the following functions, calling all
the public functions from the class:

def test_depot_software():

    k = DepotSoftware.DepotSoftware()
    k.jli(cli) # cli can be a anything, as long as it is set. You don't
have the Bladelogic cli class I assume :)

    k.aix_package()
    k.aix_patch()
    k.custom_software()
    k.hpux_bundle()
    k.hpux_patch()
    k.hpux_product()
    k.install_shield_package()
    k.msi_package()
    k.os_hotfix()
    k.rpm()
    k.service_pack()
    k.solaris_package()
    k.solaris_patch()
    k.solaris_patch_cluster()

When this code is run with Jython 2.5a1:
Traceback (most recent call last):
  File "./pylogic.py", line 160, in <module>
    test_depot_software()
  File "./pylogic.py", line 109, in test_depot_software
    k.aix_package()
  File "./../lib/OSS/bladelogic/DepotSoftware.py", line 35, in aix_package
    return self._add2(*args)
  File "./../lib/OSS/bladelogic/DepotSoftware.py", line 13, in _add2
    calling = [ k.capitalize() for k in inspect.stack()[1][3].split('_') ]
  File "/opt/bladelogic/jython.2.5a1/Lib/inspect.py", line 888, in stack
    return getouterframes(sys._getframe(1), context)
  File "/opt/bladelogic/jython.2.5a1/Lib/inspect.py", line 869, in
getouterframes
    framelist.append((frame,) + getframeinfo(frame, context))
  File "/opt/bladelogic/jython.2.5a1/Lib/inspect.py", line 844, in
getframeinfo
    lines, lnum = findsource(frame)
  File "/opt/bladelogic/jython.2.5a1/Lib/inspect.py", line 510, in
findsource
    if pat.match(lines[lnum]): break
IndexError: index out of range: 747

Jython 2.2.1:
DepotSoftware addAixPackageToDepotByGroupName
DepotSoftware addAixPatchToDepotByGroupName
DepotSoftware addCustomSoftwareToDepotByGroupName
DepotSoftware addHpuxBundleToDepotByGroupName
DepotSoftware addHpuxPatchToDepotByGroupName
DepotSoftware addHpuxProductToDepotByGroupName
DepotSoftware addInstallShieldPackageToDepotByGroupName
DepotSoftware addMsiPackageToDepotByGroupName
DepotSoftware addOsHotfixToDepotByGroupName
DepotSoftware addRpmToDepotByGroupName
DepotSoftware addServicePackToDepotByGroupName
DepotSoftware addSolarisPackageToDepotByGroupName
DepotSoftware addSolarisPatchToDepotByGroupName
DepotSoftware addSolarisPatchClusterToDepotByGroupName
msg3748 (view) Author: Wesley Schwengle (wesleys) Date: 2008-11-04.10:57:33
I saw an update to 2.5a3, installed that one and the bug is resolved in
that release. So the bug can remain closed.
msg3751 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2008-11-04.15:27:34
Wesley: Excellent!  Thanks for taking the time to test this!
History
Date User Action Args
2008-11-04 15:27:35fwierzbickisetmessages: + msg3751
2008-11-04 10:57:35wesleyssetmessages: + msg3748
2008-11-04 10:42:00wesleyssetmessages: + msg3747
2008-11-03 19:52:39zyasoftsetstatus: open -> closed
resolution: postponed -> works for me
title: inspect.stack() not working as intented -> inspect.stack() not working as intended
2008-11-03 19:22:56fwierzbickisetstatus: closed -> open
resolution: works for me -> postponed
messages: + msg3734
2008-11-03 19:06:30fwierzbickisetstatus: open -> closed
resolution: postponed -> works for me
messages: + msg3733
nosy: + fwierzbicki
2008-09-13 18:19:19zyasoftsetassignee: zyasoft
resolution: postponed
messages: + msg3518
nosy: + zyasoft
2008-08-22 10:31:27wesleyscreate