Ejemplo n.º 1
0
def sel_pipe(command, buffer=None):
    """Process the current selection in BUFFER through COMMAND,
       and replace that selection with the output of the command"""
    if not buffer:
        buffer = EditorBuffer.get()
    start = buffer.selection_start()
    end = buffer.selection_end()

    # Ignore white spaces and newlines at end, to preserve the rest
    # of the text
    if start != end:
        while end.get_char() == ' ' or end.get_char() == '\n':
            end = end - 1

        text = buffer.get_chars(start, end)
    else:
        text = ""

    proc = Process(command)
    proc.send(text)
    proc.send(chr(4))  # Close input
    output = proc.get_result()
    with buffer.new_undo_group():
        if start != end:
            buffer.delete(start, end)
        buffer.insert(start, output.rstrip())
Ejemplo n.º 2
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.º 3
0
Archivo: gcov.py Proyecto: AdaCore/gps
def run_gcov():
    "Run gcov to generate the coverage files"
    # Verify that the version of gcov is recent enough to support response
    # files and reading of .gc?? data in multiple directories.

    try:
        p = Process("gcov --version")
        out = p.get_result()
        p = re.compile("[1-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]")
        found = p.findall(out)
        if not found:
            MDI.dialog("Could not find a date in the output of gcov.")
        else:
            date = found[0]
            if int(date) < 20071005:
                MDI.dialog("Your version of gcov is dated " + str(date) +
                           ".\nThis plugin requires gcov for GNAT dated " +
                           "20071005 or later.")
                return
    except Exception:
        MDI.dialog("""Could not read gcov version number.

Make sure you are using gcov for GNAT dated 20071005 or later.""")

    # Determine the root project
    root_project = Project.root()

    # Determine where to create the gcov info
    GCOV_ROOT = os.getenv("GCOV_ROOT")

    if not GCOV_ROOT:
        root_object_dirs = root_project.object_dirs(False)
        if not root_object_dirs:
            MDI.dialog("""The root project does not have an object directory.
 Please add one, or set the enviroment variable GCOV_ROOT to
 the directory where you would like the gcov files to be
 generated.""")
            return
        else:
            gcov_dir = root_object_dirs[0]

    else:
        gcov_dir = GCOV_ROOT

    if not os.access(gcov_dir, os.R_OK and os.W_OK):
        MDI.dialog(""" Could not access the directory:

   """ + gcov_dir + """

Please point the environment variable GCOV_ROOT to a directory
on which you have permission to read and write.
         """)

    input_file = os.path.abspath(os.path.join(gcov_dir, "gcov_input.txt"))

    # List all the projects
    projects = root_project.dependencies(True)
    # List all object dirs
    object_dirs = root_project.object_dirs(True)

    # Write the response file
    res = open(input_file, 'w')

    gcda_file_found = False
    gcno_file_found = False

    for p in projects:
        sources = p.sources(False)

        for s in sources:
            n = s.path
            basename = n[max(n.rfind('\\'), n.rfind('/')) + 1:len(n)]
            unit = basename[0:basename.rfind('.')]

            for object_dir in object_dirs:
                gcda = object_dir + os.sep + unit + ".gcda"

                # If we have not yet found at least one .gcno file, attempt to
                # find one. This is to improve the precision of error messages,
                # and detect the case where compilation was successful but the
                # executable has never been run.

                if not gcno_file_found:
                    gcno = object_dir + os.sep + unit + ".gcno"
                    if os.access(gcno, os.F_OK):
                        gcno_file_found = True

                if os.access(gcda, os.F_OK):
                    gcda_file_found = True
                    # Write one entry in response file

                    # Escape all backslashes.
                    gcda = gcda.replace('\\', '\\\\')

                    res.write('"' + gcda + '"' + "\n")
                    break

    res.close()

    open(input_file).read()

    if not gcno_file_found:
        # No gcno file was found: display an appropriate message.
        MDI.dialog(
            """ No ".gcno" file was found in any of the object directories.

Make sure you have compiled the sources of interest with
the "Code coverage" flags.""")

    else:
        if not gcda_file_found:
            # Some gcno files were found, but no gcna files.
            MDI.dialog(
                """ No ".gcda" file was found in any of the object directories.

Make sure you have run the executable(s) at least once.
""")

        else:
            # Run gcov
            Gcov_Process("gcov", "@%s" % input_file, directory=gcov_dir)