Пример #1
0
    def get_patched_content(self):
        """Get self.patched_content, computing it if necessary.

        This is the content of the file after applying this patch.

        Returns:
          a Content instance.

        Raises:
          engine.FetchError: If there was a problem fetching the old content.
        """
        try:
            if self.patched_content is not None:
                return self.patched_content
        except db.Error:
            # This may happen when a Content entity was deleted behind our
            # back.
            self.patched_content = None

        old_lines = self.get_content().text.splitlines(True)
        logging.info('Creating patched_content for %s', self.filename)
        chunks = patching.ParsePatchToChunks(self.lines, self.filename)
        new_lines = []
        for _, _, new in patching.PatchChunks(old_lines, chunks):
            new_lines.extend(new)
        text = db.Text(''.join(new_lines))
        patched_content = Content(text=text, parent=self)
        patched_content.put()
        self.patched_content = patched_content
        self.put()
        return patched_content
Пример #2
0
def _apply_patch(old_lines, patch_name, dif_lines):
    new_lines = []
    chunks = patching.ParsePatchToChunks(dif_lines, patch_name)
    for tag, old, new in patching.PatchChunks(old_lines, chunks):
        new_lines.extend(new)
    return ''.join(new_lines)