Example #1
0
    def clean_diff(self):
        """
        Validate the diff form.
        This function will be invoked by django.form.Forms.is_valid(), and
        will raise the exception ValidationError
        """
        self.the_patch = patch.fromstring(self.cleaned_data['diff'])
        # Check that the submitted diff patches the correct number of files
        if len(self.the_patch.hunks) != 1:
            raise ValidationError, 'The patch affects more than one file.'

        # Check that the filename it patches is correct.
        if self.FILE_TO_BE_PATCHED not in self.cleaned_data['diff']:
            raise ValidationError, 'The patch affects the wrong file.'

        # Now we need to generate a working copy to apply the patch to.
        # We can also use this working copy to commit the patch if it's OK.
        repo = view_helpers.SvnRepository(self.username)
        view_helpers.subproc_check_output(
            ['svn', 'co', repo.file_trunk_url(), self.wcdir])

        # Check that it will apply correctly to the working copy.
        if not self.the_patch._match_file_hunks(self.file_to_patch, self.the_patch.hunks[0]):
            raise ValidationError, 'The patch will not apply correctly to the lastest revision.'

        # Check that the resulting file matches what is expected.
        self.new_content = ''.join(
            self.the_patch.patch_stream(open(self.file_to_patch), self.the_patch.hunks[0]))
        if self.new_content != open(self.NEW_CONTENT).read():
            raise ValidationError, 'The file resulting from patching does not have the correct contents.'
Example #2
0
    def clean_diff(self):
        """
        Validate the diff form.
        This function will be invoked by django.form.Forms.is_valid(), and
        will raise the exception ValidationError
        """
        self.the_patch = patch.fromstring(self.cleaned_data['diff'])
        # Check that the submitted diff patches the correct number of files
        if len(self.the_patch.hunks) != 1:
            raise ValidationError, 'The patch affects more than one file.'

        # Check that the filename it patches is correct.
        if self.FILE_TO_BE_PATCHED not in self.cleaned_data['diff']:
            raise ValidationError, 'The patch affects the wrong file.'

        # Now we need to generate a working copy to apply the patch to.
        # We can also use this working copy to commit the patch if it's OK.
        repo = view_helpers.SvnRepository(self.username)
        view_helpers.subproc_check_output(
            ['svn', 'co', repo.file_trunk_url(), self.wcdir])

        # Check that it will apply correctly to the working copy.
        if not self.the_patch._match_file_hunks(self.file_to_patch,
                                                self.the_patch.hunks[0]):
            raise ValidationError, 'The patch will not apply correctly to the lastest revision.'

        # Check that the resulting file matches what is expected.
        self.new_content = ''.join(
            self.the_patch.patch_stream(open(self.file_to_patch),
                                        self.the_patch.hunks[0]))
        if self.new_content != open(self.NEW_CONTENT).read():
            raise ValidationError, 'The file resulting from patching does not have the correct contents.'
Example #3
0
    def commit_diff(self):
        '''Commit the diff form.'''
        # Commit the patch.
        open(self.file_to_patch, 'w').write(self.new_content)
        commit_message = '''Fix a typo in %s.

Thanks for reporting this, %s!''' % (self.FILE_TO_BE_PATCHED, self.username)
        view_helpers.subproc_check_output(['svn', 'commit', '-m', commit_message, '--username', 'mr_bad', self.wcdir])
Example #4
0
 def commit_diff(self):
     """Commit the diff form and the patch."""
     open(self.file_to_patch, 'w').write(self.new_content)
     commit_message = '''Fix a typo in %s. Thanks for reporting this, %s!''' % (
         self.FILE_TO_BE_PATCHED, self.username)
     view_helpers.subproc_check_output([
         'svn', 'commit', '-m', commit_message, '--username', 'mr_bad',
         self.wcdir
     ])
Example #5
0
    def commit_diff(self):
        """Commit the diff form."""
        # Commit the patch.
        open(self.file_to_patch, "w").write(self.new_content)
        commit_message = """Fix a typo in %s.

Thanks for reporting this, %s!""" % (
            self.FILE_TO_BE_PATCHED,
            self.username,
        )
        view_helpers.subproc_check_output(["svn", "commit", "-m", commit_message, "--username", "mr_bad", self.wcdir])