Ejemplo n.º 1
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.º 2
0
 def on_lock_taken(self, proc, exit_status, output):
     """
     Called when we have finished taking the lock on the local RCS file
     """
     pwd = os.getcwd()
     os.chdir(self.rcs_dir)
     # Specify our own date, so that the date associated with the revision
     # is the one when the file was saved. Otherwise, it defaults to the
     # last modification of the date, and this might dependent on the local
     # time zone
     proc = Process(
         "ci -d" + datetime.datetime.now().strftime("%Y/%m/%d\\ %H:%M:%S") +
         " " + os.path.basename(self.file))
     os.chdir(pwd)
     proc.send(".\n")
Ejemplo n.º 3
0
    def local_checkout(self, revision):
        """Do a local checkout of file at given revision in the RCS directory.
           Return the name of the checked out file"""
        if self.rcs_dir and os.path.isdir(self.rcs_dir):
            try:
                os.unlink(os.path.join(self.rcs_dir,
                                       os.path.basename(self.file)))
            except Exception:
                pass

            pwd = os.getcwd()
            os.chdir(self.rcs_dir)
            proc = Process("co -r" + revision + " " + self.rcs_file)
            os.chdir(pwd)
            if proc.wait() == 0:
                return os.path.join(self.rcs_dir, os.path.basename(self.file))
        return None
Ejemplo n.º 4
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.º 5
0
 def backtrace(self, bt):
     self.clear()
     cmd = "addr2line -e " + self.executable + " " + \
         Preference("Plugins/addr2line/args").get()
     self.write(cmd + "\n")
     Process(["addr2line", "-e", self.executable] +
             Preference("Plugins/addr2line/args").get().split() +
             bt.split(),
             ".+",
             on_exit=self.on_exit,
             on_match=self.on_output)
Ejemplo n.º 6
0
    def add_to_history(self):
        """Expand the local history for file, to include the current version"""
        if not self.rcs_dir:
            Logger("LocalHist").log("No RCS dir for file " + self.file)
            return
        if not os.path.isdir(self.rcs_dir):
            os.makedirs(self.rcs_dir)
            Logger("LocalHist").log("creating directory %s" % self.rcs_dir)

        shutil.copy2(self.file, self.rcs_dir)
        if os.path.isfile(self.rcs_file):
            Process("rcs -l " + self.rcs_file, on_exit=self.on_lock_taken)
        else:
            self.on_lock_taken(None, 0, "")
Ejemplo n.º 7
0
    def cleanup_history(self):
        """Remove the older revision histories for self"""
        if not self.rcs_dir:
            return

        max_days = Preference("Plugins/local_history/maxdays").get()
        older = datetime.datetime.now() - datetime.timedelta(days=max_days)
        older = older.strftime("%Y.%m.%d.%H.%M.%S")

        revisions = self.get_revisions()
        max_revisions = Preference("Plugins/local_history/maxrevisions").get()
        if revisions:
            version = max(0, revisions[0][0] - max_revisions)
            for r in revisions:
                if r[1] < older:
                    version = max(version, r[0])
                    break

            if version >= 1:
                Logger("LocalHist").log("Truncating file %s to revision %s" %
                                        (self.rcs_file, version))
                proc = Process("rcs -o:1.%s %s" % (version, self.rcs_file))
                proc.wait()
Ejemplo n.º 8
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)