Ejemplo n.º 1
0
 def add_dependency(self, dependency, newdep=True, removed=False):
     """Indicate a new GPS.Project dependency for the current project"""
     show_diff = Preference("Plugins/dependencies/show_diff").get()
     if removed and show_diff:
         Console().write(" - " + dependency.path + "\n")
     elif newdep or not show_diff:
         Console().write(" + " + dependency.path + "\n")
Ejemplo n.º 2
0
 def __init__(self, executable):
     self.executable = executable
     self.name = "addr2line -e " + os.path.basename(self.executable)
     Console.__init__(self, self.name, on_input=Addr2line.on_input)
     self.create_link(file_line_re, self.onclick)
     self.clear()
     self.write("Backtrace ?")
     self.enable_input(True)
     MDI.get(self.name).raise_window()
Ejemplo n.º 3
0
def describe_char(char=None):
    """Describe the unicode character under the cursor (name, value,...)"""
    if not char:
        char = EditorBuffer.get().current_view().cursor().get_char()
    uni = char.decode("utf-8")
    Console().write("Character:  " + char + "\n")
    Console().write("      Name: " + unicodedata.name(uni) + "\n")
    Console().write("   Unicode: " + repr(ord(uni)) +
                    " (U+" + hex(ord(uni))[2:] + ")\n")
    Console().write("  Category: " + unicodedata.category(uni) + "\n")
Ejemplo n.º 4
0
 def show_diff(self, revision, date):
     """Show, in a console, the diff between the current version and
        revision"""
     if self.rcs_dir and os.path.isdir(self.rcs_dir):
         pwd = os.getcwd()
         os.chdir(os.path.dirname(self.file))
         diff_switches = Preference(
             "Plugins/local_history/diff_switches").get()
         proc = Process("rcsdiff " + diff_switches +
                        " -r" + revision + " " + self.rcs_file)
         diff = proc.get_result()
         os.chdir(pwd)
         Console("Local History").clear()
         Console("Local History").write("Local history at " + date + "\n")
         Console("Local History").write(diff)
Ejemplo n.º 5
0
def indent_all(menu):
    for f in Project.root().sources(recursive=True):
        ed = EditorBuffer.get(f)
        ed.indent()
        ed.save()
        ed.close()
    Console().write("Done indenting")
Ejemplo n.º 6
0
 def explain_dependency(self, file, depends_on):
     """Explains the last add_dependency: file depends on depends_on"""
     if Preference("Plugins/dependencies/show_source").get():
         Console().write(
             "   => {} depends on {}\n".format(
                 os.path.basename(file.path),
                 os.path.basename(depends_on.path)
             )
         )
Ejemplo n.º 7
0
def on_compilation_finished(*args):
    obj_dirs = Project.root().object_dirs(False)
    path = obj_dirs[0] if obj_dirs else dirname(Project.root().file().path)
    base = file_name_pref.get()

    if not base:
        Console().write(
            "plugin save_on_compile.py: no file name is specified in the"
            " preferences\n")
    else:
        try:
            full = join(path, base)
            with open(full, "w") as f:
                f.write(Console().get_text())
            Console().write("Output saved in %s\n" % (full, ))
        except Exception:
            Console().write(
                "plugin save_on_compile.py: error saving in '%s'\n" % (full, ))
Ejemplo n.º 8
0
def on_project_view_changed(h):
    global autocont_br
    try:
        autocont_br = set(
            Project.root().get_property("autocont_br").split("--"))
        Console().write(
            "The debugger will not stop when an exception is raised at " +
            "\n".join(autocont_br))
    except:
        autocont_br = set()
Ejemplo n.º 9
0
def check_wf():
    """Check whether the current XML document is well-formed"""
    try:
        file = EditorBuffer.get().file()
        handler = xml.sax.handler.ContentHandler()
        errors = GPSErrorHandler()
        xml.sax.parse(file.path, handler, errors)

        Locations.remove_category('XML well-formedness')
        if not errors.output:
            Console().write('Document is well-formed\n')
        else:
            Console().write(errors.output)
            Locations.parse(errors.output, 'XML well-formedness')
    except StopProcessing:
        Locations.parse(errors.output, 'XML well-formedness')
    except xml.sax.SAXParseException:
        Console().write('Unexpected error while parsing the XML document')
    except:
        Console().write('Unexpected error %s' % (traceback.format_exc(), ))
Ejemplo n.º 10
0
def compute_project_dependencies(output):
    try:
        depends_on = dict()
        current_deps = dict()
        for p in Project.root().dependencies(recursive=True):
            current_deps[p] = [cur for cur in p.dependencies(recursive=False)]
            tmp = dict()
            previous = p
            for s in p.sources(recursive=False):
                for imp in s.imports(include_implicit=True,
                                     include_system=False):
                    ip = imp.project(default_to_root=False)
                    if ip and ip != p:
                        if show_single_file:
                            if ip != previous:
                                tmp[ip] = [(s, imp)]
                        else:
                            try:
                                tmp[ip].append((s, imp))
                            except KeyError:
                                tmp[ip] = [(s, imp)]
                        previous = ip
            depends_on[p] = tmp

        no_source_projects = [
            s.strip().lower() for s in Preference(
                "Plugins/dependencies/no_src_prj").get().split(",")
        ]

        for p in depends_on:
            output.set_current_project(p)
            for dep in depends_on[p]:
                output.add_dependency(dep, newdep=dep not in current_deps[p])
                for reason in depends_on[p][dep]:
                    output.explain_dependency(reason[0], reason[1])

                try:
                    current_deps[p].remove(dep)
                except:
                    pass

            for dep in current_deps[p]:
                if dep.path.lower() not in no_source_projects:
                    output.add_dependency(dep, newdep=False, removed=True)

        output.close()
    except:
        Console().write("Unexpected exception " + traceback.format_exc())
Ejemplo n.º 11
0
def show_unused_entities(where, globals_only):
    """List all unused global entities from WHERE in the locations window"""
    Editor.register_highlighting("Unused_Entities", "blue")
    Locations.remove_category("Unused entity")
    MDI.get("Messages").raise_window()

    for e in UnusedIterator(where, globals_only=globals_only):
        Locations.add(category="Unused entity",
                      file=e.declaration().file(),
                      line=e.declaration().line(),
                      column=e.declaration().column(),
                      message="unused entity " + e.name(),
                      highlight="Unused_Entities",
                      length=len(e.name()))

    Console().write("Done searching for unused entities\n")
Ejemplo n.º 12
0
def EntityIterator(where):
    """Return all entities from WHERE"""
    if not where:
        ignore_projects = [
            s.strip().lower() for s in Preference(
                "Plugins/unused_entities/ignoreprj").get().split(",")
        ]

        for p in Project.root().dependencies(recursive=True):
            if p.name().lower() not in ignore_projects:
                Console().write("Searching unused entities in project " +
                                p.name() + "\n")
                for s in p.sources():
                    for e in s.entities(local=True):
                        yield e
    elif isinstance(where, Project):
        for s in where.sources():
            for e in s.entities(local=True):
                yield e
    elif isinstance(where, File):
        for e in where.entities(local=True):
            yield e
Ejemplo n.º 13
0
 def set_current_project(self, project):
     """Set the name of the current project in the output.
        Its list of dependencies will be output afterwards"""
     Console().write("Project " + project.name() + " depends on:\n")
Ejemplo n.º 14
0
def print_in_console(debug, txt):
    Console("Debugger Console").write(txt)