def interactivePythonMode(self, fileName = None, *args, **kwargs):
    """
    Run an interactive Python interpreter that can be used to manipulate the loaded traces.
    
    @param fileName:    Optional Python source file to run
    @param args:        Optional arguments for the source file
    @param kwargs:      Optional keyword arguments for the source file
    """
    
    # Refresh the analyzer environment module
    import AnalyzerEnvironment as env
    
    env.analyzer  = self.analyzer
    env.project   = self.analyzer.project
    env.args      = args
    env.kwargs    = kwargs
    env.cmd       = Collections.DictProxy(self.analyzer.commands)
    env.traces    = Collections.DictProxy(self.analyzer.traces)

    try:
      env.library   = self.analyzer.project.targets["code"].library
      env.constants = Collections.DictProxy(env.library.constants)
    except KeyError:
      env.library   = None
      env.constants = None

    try:
      if fileName:
        path       = os.path.dirname(fileName)
        moduleName = os.path.splitext(os.path.basename(fileName))[0]
        if not path in sys.path:
          sys.path.append(path)
        if not moduleName in sys.modules:
          __import__(moduleName)
        else:
          reload(sys.modules[moduleName])
      else:
        console = code.InteractiveConsole(locals = env.__dict__)
        console.interact(banner = "Entering Python mode.")
    except SystemExit:
      pass
dataset/ETHPy150Open skyostil/tracy/src/analyzer/plugins/core/CorePlugin.py/CoreInteractivePlugin.interactivePythonMode/original