# -*- coding: utf-8 -*-

# Copyright (c) 2002, 2003 Detlev Offenbach <detlev@die-offenbachs.de>
#

import os
import sys
import string
import distutils.sysconfig

debugger = None
__scriptname = None

modDir = distutils.sysconfig.get_python_lib()
ericpath = os.getenv('ERICDIR', os.path.join(modDir, 'eric3'))

if not ericpath in sys.path:
    sys.path.insert(-1, ericpath)
    
def initDebugger(kind="standard"):
    """
    Module function to initialize a debugger for remote debugging.
    
    Arguments
    
        kind -- type of debugger ("standard", "noqt" or "threads")
        
    Returns
    
        flag indicating success (boolean)
    """
    global debugger
    res = 1
    try:
        if kind == "standard":
            import DebugClient
            debugger = DebugClient.DebugClient()
        elif kind == "noqt":
            import DebugClientNoQt
            debugger = DebugClientNoQt.DebugClientNoQt()
        elif kind == "threads":
            import DebugClientThreads
            debugger = DebugClientThreads.DebugClientThreads()
        else:
            raise ValueError
    except:
        debugger = None
        res = 0
        
    return res

def runcall(func, *args):
    """
    Module function mimicing the Pdb interface.
    
    Arguments
    
        func -- function to be called (function object)
        
        *args -- arguments being passed to func
        
    Returns
    
        the function result
    """
    global debugger, __scriptname
    return debugger.run_call(__scriptname, func, *args)
    
def setScriptname(name):
    """
    Module function to set the scriptname to be reported bach to the IDE.
    
    Arguments
    
        name -- absolute pathname of the script (string)
    """
    global __scriptname
    __scriptname = name
