コード例 #1
0
    def run(self, file):
        m = save_main_module(file, 'run_profiler')
        globals = m.__dict__
        try:
            globals['__builtins__'] = __builtins__
        except NameError:
            pass  # Not there on Jython...

        self.start_profiling()

        pydev_imports.execfile(file, globals, globals)  # execute the script

        self.stop_profiling()
        self.save_snapshot(0, generate_snapshot_filepath(base_snapshot_path))
コード例 #2
0
    def run(self, file):
        m = save_main_module(file, 'run_profiler')
        globals = m.__dict__
        try:
            globals['__builtins__'] = __builtins__
        except NameError:
            pass  # Not there on Jython...

        self.start_profiling()

        pydev_imports.execfile(file, globals, globals)  # execute the script

        # self.stats_string()

        time.sleep(10)
コード例 #3
0
    def run(self, file):
        m = save_main_module(file, 'run_profiler')
        globals = m.__dict__
        try:
            globals['__builtins__'] = __builtins__
        except NameError:
            pass  # Not there on Jython...

        self.start_profiling()

        pydev_imports.execfile(file, globals, globals)  # execute the script

        self.stop_profiling()
        self.save_snapshot(
            0, generate_snapshot_filepath(base_snapshot_path, remote_run),
            remote_run)
コード例 #4
0
ファイル: pydevd_vars.py プロジェクト: AshishNamdev/Pydev
def customOperation(thread_id, frame_id, scope, attrs, style, code_or_file, operation_fn_name):
    """
    We'll execute the code_or_file and then search in the namespace the operation_fn_name to execute with the given var.

    code_or_file: either some code (i.e.: from pprint import pprint) or a file to be executed.
    operation_fn_name: the name of the operation to execute after the exec (i.e.: pprint)
    """
    expressionValue = getVariable(thread_id, frame_id, scope, attrs)

    try:
        namespace = {'__name__': '<customOperation>'}
        if style == "EXECFILE":
            namespace['__file__'] = code_or_file
            execfile(code_or_file, namespace, namespace)
        else:  # style == EXEC
            namespace['__file__'] = '<customOperationCode>'
            Exec(code_or_file, namespace, namespace)

        return str(namespace[operation_fn_name](expressionValue))
    except:
        traceback.print_exc()
コード例 #5
0
def customOperation(thread_id, frame_id, scope, attrs, style, code_or_file, operation_fn_name):
    """
    We'll execute the code_or_file and then search in the namespace the operation_fn_name to execute with the given var.

    code_or_file: either some code (i.e.: from pprint import pprint) or a file to be executed.
    operation_fn_name: the name of the operation to execute after the exec (i.e.: pprint)
    """
    expressionValue = getVariable(thread_id, frame_id, scope, attrs)

    try:
        namespace = {'__name__': '<customOperation>'}
        if style == "EXECFILE":
            namespace['__file__'] = code_or_file
            execfile(code_or_file, namespace, namespace)
        else:  # style == EXEC
            namespace['__file__'] = '<customOperationCode>'
            Exec(code_or_file, namespace, namespace)

        return str(namespace[operation_fn_name](expressionValue))
    except:
        traceback.print_exc()
コード例 #6
0
def run_file(file, globals=None, locals=None):
    if os.path.isdir(file):
        new_target = os.path.join(file, '__main__.py')
        if os.path.isfile(new_target):
            file = new_target

    if globals is None:
        m = save_main_module(file, 'pydev_run_in_console')

        globals = m.__dict__
        try:
            globals['__builtins__'] = __builtins__
        except NameError:
            pass  # Not there on Jython...

    if locals is None:
        locals = globals

    print('Running %s' % file)
    pydev_imports.execfile(file, globals, locals)  # execute the script

    return globals
コード例 #7
0
def run_file(file, globals=None, locals=None):
    if os.path.isdir(file):
        new_target = os.path.join(file, "__main__.py")
        if os.path.isfile(new_target):
            file = new_target

    if globals is None:
        m = save_main_module(file, "pydev_run_in_console")

        globals = m.__dict__
        try:
            globals["__builtins__"] = __builtins__
        except NameError:
            pass  # Not there on Jython...

    if locals is None:
        locals = globals

    print("Running %s" % file)
    pydev_imports.execfile(file, globals, locals)  # execute the script

    return globals
コード例 #8
0
def run_file(file, globals=None, locals=None):
    if os.path.isdir(file):
        new_target = os.path.join(file, '__main__.py')
        if os.path.isfile(new_target):
            file = new_target

    if globals is None:
        # patch provided by: Scott Schlesier - when script is run, it does not
        # use globals from pydevd:
        # This will prevent the pydevd script from contaminating the namespace for the script to be debugged

        # pretend pydevd is not the main module, and
        # convince the file to be debugged that it was loaded as main
        sys.modules['pydevd'] = sys.modules['__main__']
        sys.modules['pydevd'].__name__ = 'pydevd'

        from imp import new_module
        m = new_module('__main__')
        sys.modules['__main__'] = m
        if hasattr(sys.modules['pydevd'], '__loader__'):
            setattr(m, '__loader__', getattr(sys.modules['pydevd'], '__loader__'))

        m.__file__ = file
        globals = m.__dict__
        try:
            globals['__builtins__'] = __builtins__
        except NameError:
            pass  # Not there on Jython...

    if locals is None:
        locals = globals


    print('Running %s'%file)
    pydev_imports.execfile(file, globals, locals)  # execute the script

    return globals
コード例 #9
0
def run_file(file, globals=None, locals=None):
    if os.path.isdir(file):
        new_target = os.path.join(file, '__main__.py')
        if os.path.isfile(new_target):
            file = new_target

    if globals is None:
        m = save_main_module(file, 'pydev_run_in_console')

        globals = m.__dict__
        try:
            globals['__builtins__'] = __builtins__
        except NameError:
            pass  # Not there on Jython...

    if locals is None:
        locals = globals

    sys.path.insert(0, os.path.split(file)[0])

    print('Running %s'%file)
    pydev_imports.execfile(file, globals, locals)  # execute the script

    return globals
コード例 #10
0
ファイル: pydevd.py プロジェクト: airadier/Pydev_web2py
    def run(self, file, globals=None, locals=None):

        if globals is None:
            #patch provided by: Scott Schlesier - when script is run, it does not
            #use globals from pydevd:
            #This will prevent the pydevd script from contaminating the namespace for the script to be debugged

            #pretend pydevd is not the main module, and
            #convince the file to be debugged that it was loaded as main
            sys.modules['pydevd'] = sys.modules['__main__']
            sys.modules['pydevd'].__name__ = 'pydevd'

            from imp import new_module
            m = new_module('__main__')
            sys.modules['__main__'] = m
            m.__file__ = file
            globals = m.__dict__

        if locals is None:
            locals = globals

        #Predefined (writable) attributes: __name__ is the module's name;
        #__doc__ is the module's documentation string, or None if unavailable;
        #__file__ is the pathname of the file from which the module was loaded,
        #if it was loaded from a file. The __file__ attribute is not present for
        #C modules that are statically linked into the interpreter; for extension modules
        #loaded dynamically from a shared library, it is the pathname of the shared library file.

        #I think this is an ugly hack, bug it works (seems to) for the bug that says that sys.path should be the same in
        #debug and run.
        if m.__file__.startswith(sys.path[0]):
            #print >> sys.stderr, 'Deleting: ', sys.path[0]
            del sys.path[0]

        #now, the local directory has to be added to the pythonpath
        #sys.path.insert(0, os.getcwd())
        #Changed: it's not the local directory, but the directory of the file launched
        #The file being run ust be in the pythonpath (even if it was not before)
        sys.path.insert(0, os.path.split(file)[0])

        # for completness, we'll register the pydevd.reader & pydevd.writer threads
        net = NetCommand(str(CMD_THREAD_CREATE), 0,
                         '<xml><thread name="pydevd.reader" id="-1"/></xml>')
        self.writer.addCommand(net)
        net = NetCommand(str(CMD_THREAD_CREATE), 0,
                         '<xml><thread name="pydevd.writer" id="-1"/></xml>')
        self.writer.addCommand(net)

        pydevd_tracing.SetTrace(self.trace_dispatch)
        try:
            #not available in jython!
            threading.settrace(self.trace_dispatch)  # for all future threads
        except:
            pass

        try:
            thread.start_new_thread = pydev_start_new_thread
            thread.start_new = pydev_start_new_thread
        except:
            pass

        while not self.readyToRun:
            time.sleep(0.1)  # busy wait until we receive run command

        PyDBCommandThread(debugger).start()

        pydev_imports.execfile(file, globals, locals)  #execute the script
コード例 #11
0
ファイル: pydevd.py プロジェクト: jonhairston/yats
    def run(self, file, globals=None, locals=None):

        if globals is None:
            #patch provided by: Scott Schlesier - when script is run, it does not 
            #use globals from pydevd:
            #This will prevent the pydevd script from contaminating the namespace for the script to be debugged
            
            #pretend pydevd is not the main module, and
            #convince the file to be debugged that it was loaded as main
            sys.modules['pydevd'] = sys.modules['__main__']
            sys.modules['pydevd'].__name__ = 'pydevd'            
            
            from imp import new_module
            m = new_module('__main__')
            sys.modules['__main__'] = m
            m.__file__ = file
            globals = m.__dict__
            try:
                globals['__builtins__'] = __builtins__
            except NameError:
                pass #Not there on Jython...

        if locals is None: 
            locals = globals        
            
        #Predefined (writable) attributes: __name__ is the module's name; 
        #__doc__ is the module's documentation string, or None if unavailable; 
        #__file__ is the pathname of the file from which the module was loaded, 
        #if it was loaded from a file. The __file__ attribute is not present for 
        #C modules that are statically linked into the interpreter; for extension modules 
        #loaded dynamically from a shared library, it is the pathname of the shared library file. 


        #I think this is an ugly hack, bug it works (seems to) for the bug that says that sys.path should be the same in
        #debug and run.
        if m.__file__.startswith(sys.path[0]):
            #print >> sys.stderr, 'Deleting: ', sys.path[0]
            del sys.path[0]

        #now, the local directory has to be added to the pythonpath
        #sys.path.insert(0, os.getcwd())
        #Changed: it's not the local directory, but the directory of the file launched
        #The file being run ust be in the pythonpath (even if it was not before)
        sys.path.insert(0, os.path.split(file)[0])
        
        # for completness, we'll register the pydevd.reader & pydevd.writer threads
        net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.reader" id="-1"/></xml>')
        self.writer.addCommand(net)
        net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.writer" id="-1"/></xml>')
        self.writer.addCommand(net)

        pydevd_tracing.SetTrace(self.trace_dispatch) 
        try:                   
            #not available in jython!  
            threading.settrace(self.trace_dispatch) # for all future threads
        except:
            pass
        
        try:
            thread.start_new_thread = pydev_start_new_thread
            thread.start_new = pydev_start_new_thread
        except:
            pass

        while not self.readyToRun: 
            time.sleep(0.1) # busy wait until we receive run command
            
        PyDBCommandThread(debugger).start()

        pydev_imports.execfile(file, globals, locals) #execute the script