Exemplo n.º 1
0
 def test_trace_line_numbers(self):
     test_file = os.path.join(TEST_DIR, 'short-file')
     line_nums = pyficache.trace_line_numbers(test_file)
     if 0 == len(line_nums):
         self.assertEqual([], line_nums)
     else:
         self.assertEqual([1], line_nums)
         pass
     test_file = os.path.join(TEST_DIR, 'devious.py')
     self.assertEqual([2, 5, 7, 9], pyficache.trace_line_numbers(test_file))
     return
Exemplo n.º 2
0
def set_break(cmd_obj,
              func,
              filename,
              lineno,
              condition,
              temporary,
              args,
              force=False):
    if lineno is None:
        part1 = ("I don't understand '%s' as a line number, function name," %
                 ' '.join(args[1:]))
        msg = Mmisc.wrapped_lines(part1, "or file/module plus line number.",
                                  cmd_obj.settings['width'])
        cmd_obj.errmsg(msg)
        return False
    if filename is None:
        filename = cmd_obj.proc.curframe.f_code.co_filename
        filename = cmd_obj.core.canonic(filename)
        pass
    if func is None:
        try:
            ok_linenos = pyficache.trace_line_numbers(filename)
        except:
            ok_linenos = None

        if not ok_linenos or lineno not in ok_linenos:
            part1 = ('File %s' % cmd_obj.core.filename(filename))
            msg = Mmisc.wrapped_lines(part1,
                                      "is not stoppable at line %d." % lineno,
                                      cmd_obj.settings['width'])
            cmd_obj.errmsg(msg)
            if force:
                cmd_obj.msg("Breakpoint set although it may never be reached")
            else:
                return False
        pass
    bp = cmd_obj.core.bpmgr.add_breakpoint(filename, lineno, temporary,
                                           condition, func)
    if func and inspect.isfunction(func):
        cmd_obj.msg('Breakpoint %d set on calling function %s()' %
                    (bp.number, func.func_name))
        part1 = 'Currently this is line %d of file' % lineno
        msg = Mmisc.wrapped_lines(part1, cmd_obj.core.filename(filename),
                                  cmd_obj.settings['width'])
    else:
        part1 = ('Breakpoint %d set at line %d of file' % (bp.number, lineno))
        msg = Mmisc.wrapped_lines(part1, cmd_obj.core.filename(filename),
                                  cmd_obj.settings['width'])
        pass
    cmd_obj.msg(msg)
    return True
Exemplo n.º 3
0
def set_break(cmd_obj, func, filename, lineno, condition, temporary,
              args, force=False):
    if lineno is None:
        part1 = ("I don't understand '%s' as a line number, function name,"
                 % ' '.join(args[1:]))
        msg = Mmisc.wrapped_lines(part1, "or file/module plus line number.",
                                  cmd_obj.settings['width'])
        cmd_obj.errmsg(msg)
        return False
    if filename is None:
        filename = cmd_obj.proc.curframe.f_code.co_filename
        filename = cmd_obj.core.canonic(filename)
        pass
    if func is None:
        ok_linenos = pyficache.trace_line_numbers(filename)
        if not ok_linenos or lineno not in ok_linenos:
            part1 = ('File %s' % cmd_obj.core.filename(filename))
            msg = Mmisc.wrapped_lines(part1,
                                      "is not stoppable at line %d." %
                                      lineno, cmd_obj.settings['width'])
            cmd_obj.errmsg(msg)
            if force:
                cmd_obj.msg("Breakpoint set although it may never be reached")
            else:
                return False
        pass
    bp =  cmd_obj.core.bpmgr.add_breakpoint(filename, lineno, temporary,
                                         condition, func)
    if func and inspect.isfunction(func):
        cmd_obj.msg('Breakpoint %d set on calling function %s()'
                 % (bp.number, func.func_name))
        part1 = 'Currently this is line %d of file'  % lineno
        msg = Mmisc.wrapped_lines(part1, cmd_obj.core.filename(filename),
                                  cmd_obj.settings['width'])
    else:
        part1 = ( 'Breakpoint %d set at line %d of file'
                  % (bp.number, lineno))
        msg = Mmisc.wrapped_lines(part1, cmd_obj.core.filename(filename),
                                  cmd_obj.settings['width'])
        pass
    cmd_obj.msg(msg)
    return True
Exemplo n.º 4
0
def complete_break_linenumber(self, prefix):
    canonic_name = self.proc.curframe.f_code.co_filename
    completions = pyficache.trace_line_numbers(canonic_name)
    return Mcomplete.complete_token([str(i) for i in completions], prefix)
Exemplo n.º 5
0
    def run(self, args):
        """Get file information"""
        if len(args) == 0:
            if not self.proc.curframe:
                self.errmsg("No frame - no default file.")
                return False
            filename = self.proc.curframe.f_code.co_filename
        else:
            filename = args[0]
            pass

        m = filename + " is"
        filename_cache = self.core.filename_cache
        if filename in filename_cache:
            m += " cached in debugger"
            if filename_cache[filename] != filename:
                m += " as:"
                m = Mmisc.wrapped_lines(m, filename_cache[filename] + ".", self.settings["width"])
            else:
                m += "."
                pass
            self.msg(m)
        else:
            matches = [file for file in file_list() if file.endswith(filename)]
            if len(matches) > 1:
                self.msg("Multiple files found ending filename string:")
                for match_file in matches:
                    self.msg("\t%s" % match_file)
                    pass
            elif len(matches) == 1:
                canonic_name = pyficache.unmap_file(matches[0])
                m += " matched debugger cache file:\n  " + canonic_name
                self.msg(m)
            else:
                self.msg(m + " not cached in debugger.")
            pass
        canonic_name = self.core.canonic(filename)
        self.msg(Mmisc.wrapped_lines("Canonic name:", canonic_name, self.settings["width"]))
        for name in (canonic_name, filename):
            if name in sys.modules:
                for key in [k for k, v in list(sys.modules.items()) if name == v]:
                    self.msg("module: %s", key)
                    pass
                pass
            pass
        for arg in args[1:]:
            processed_arg = False
            if arg in ["all", "size"]:
                if pyficache.size(canonic_name):
                    self.msg("File has %d lines." % pyficache.size(canonic_name))
                    pass
                processed_arg = True
                pass
            if arg in ["all", "sha1"]:
                self.msg("SHA1 is %s." % pyficache.sha1(canonic_name))
                processed_arg = True
                pass
            if arg in ["all", "brkpts"]:
                lines = pyficache.trace_line_numbers(canonic_name)
                if lines:
                    self.section("Possible breakpoint line numbers:")
                    fmt_lines = columnize.columnize(lines, ljust=False, arrange_vertical=False, lineprefix="  ")
                    self.msg(fmt_lines)
                    pass
                processed_arg = True
                pass
            if not processed_arg:
                self.errmsg("Don't understand sub-option %s." % arg)
                pass
            pass
        return
Exemplo n.º 6
0
    def run(self, args):
        """Get file information"""
        if len(args) == 0:
            if not self.proc.curframe:
                self.errmsg("No frame - no default file.")
                return False
            filename = self.proc.curframe.f_code.co_filename
        else:
            filename = args[0]
            pass

        m = filename + ' is'
        filename_cache = self.core.filename_cache
        if filename in filename_cache:
            m += " cached in debugger"
            if filename_cache[filename] != filename:
                m += ' as:'
                m = Mmisc.wrapped_lines(m, filename_cache[filename] + '.',
                                        self.settings['width'])
            else:
                m += '.'
                pass
            self.msg(m)
        else:
            matches = [
                file for file in self.file_list() if file.endswith(filename)
            ]
            if (len(matches) > 1):
                self.msg("Multiple files found ending filename string:")
                for match_file in matches:
                    self.msg("\t%s" % match_file)
                    pass
            elif len(matches) == 1:
                canonic_name = pyficache.unmap_file(matches[0])
                m += " matched debugger cache file:\n  " + canonic_name
                self.msg(m)
            else:
                self.msg(m + ' not cached in debugger.')
            pass
        canonic_name = self.core.canonic(filename)
        self.msg(
            Mmisc.wrapped_lines('Canonic name:', canonic_name,
                                self.settings['width']))
        for name in (canonic_name, filename):
            if name in sys.modules:
                for key in [
                        k for k, v in list(sys.modules.items()) if name == v
                ]:
                    self.msg("module: %s", key)
                    pass
                pass
            pass
        for arg in args[1:]:
            processed_arg = False
            if arg in ['all', 'size']:
                if pyficache.size(canonic_name):
                    self.msg("File has %d lines." %
                             pyficache.size(canonic_name))
                    pass
                processed_arg = True
                pass
            if arg in ['all', 'sha1']:
                self.msg("SHA1 is %s." % pyficache.sha1(canonic_name))
                processed_arg = True
                pass
            if arg in ['all', 'brkpts']:
                lines = pyficache.trace_line_numbers(canonic_name)
                if lines:
                    self.section("Possible breakpoint line numbers:")
                    fmt_lines = columnize.columnize(lines,
                                                    ljust=False,
                                                    arrange_vertical=False,
                                                    lineprefix='  ')
                    self.msg(fmt_lines)
                    pass
                processed_arg = True
                pass
            if not processed_arg:
                self.errmsg("Don't understand sub-option %s." % arg)
                pass
            pass
        return
Exemplo n.º 7
0
def complete_break_linenumber(self, prefix):
    canonic_name = self.proc.curframe.f_code.co_filename
    completions = pyficache.trace_line_numbers(canonic_name)
    return Mcomplete.complete_token([str(i) for i in completions],
                                    prefix)
Exemplo n.º 8
0
    def run(self, args):
        """**info files** [*filename* [**all** | **brkpts** | **lines** | **sha1** | **size**]]

        Show information about the current file. If no filename is
        given and the program is running then the current file associated
        with the current stack entry is used. Sub options which can be
        shown about a file are:

        * **brkpts** Line numbers where there are statement boundaries. These lines can be used in breakpoint commands.

        * **sha1**	A SHA1 hash of the source text.

        The following may be useful in comparing source code.

        * **size**	The number of lines in the file.

        * **all** All of the above information.
        """
        if len(args) == 0:
            if not self.proc.curframe:
                self.errmsg("No frame - no default file.")
                return False
            filename = self.proc.curframe.f_code.co_filename
        else:
            filename = args[0]
            pass

        m = filename + " is"
        filename_cache = self.core.filename_cache
        if filename in filename_cache:
            m += " cached in debugger"
            if filename_cache[filename] != filename:
                m += " as:"
                m = Mmisc.wrapped_lines(m, filename_cache[filename] + ".",
                                        self.settings["width"])
            else:
                m += "."
                pass
            self.msg(m)
        else:
            matches = [file for file in file_list() if file.endswith(filename)]
            if len(matches) > 1:
                self.msg("Multiple files found ending filename string:")
                for match_file in matches:
                    self.msg("\t%s" % match_file)
                    pass
            elif len(matches) == 1:
                canonic_name = pyficache.unmap_file(matches[0])
                m += " matched debugger cache file:\n  " + canonic_name
                self.msg(m)
            else:
                self.msg(m + " not cached in debugger.")
            pass
        canonic_name = self.core.canonic(filename)
        self.msg(
            Mmisc.wrapped_lines("Canonic name:", canonic_name,
                                self.settings["width"]))
        for name in (canonic_name, filename):
            if name in sys.modules:
                for key in [
                        k for k, v in list(sys.modules.items()) if name == v
                ]:
                    self.msg("module: %s", key)
                    pass
                pass
            pass
        for arg in args[1:]:
            processed_arg = False
            if arg in ["all", "size"]:
                if pyficache.size(canonic_name):
                    self.msg("File has %d lines." %
                             pyficache.size(canonic_name))
                    pass
                processed_arg = True
                pass
            if arg in ["all", "sha1"]:
                self.msg("SHA1 is %s." % pyficache.sha1(canonic_name))
                processed_arg = True
                pass
            if arg in ["all", "brkpts"]:
                lines = pyficache.trace_line_numbers(canonic_name)
                if lines:
                    self.section("Possible breakpoint line numbers:")
                    fmt_lines = columnize.columnize(
                        list(lines),
                        ljust=False,
                        arrange_vertical=False,
                        lineprefix="  ",
                    )
                    self.msg(fmt_lines)
                    pass
                processed_arg = True
                pass
            if not processed_arg:
                self.errmsg("Don't understand sub-option %s." % arg)
                pass
            pass
        return