Exemplo n.º 1
0
    def _do_plugin(self, args):
        print """Running 'python-tidy' plugin"""

        # Apply the changes:
        file_changes = {}
        for filename in args.source_files:

            if not filename.endswith('.py'):
                continue

            with open(filename) as f:
                old_contents = f.read()
            try:
                new_contents = self.do_text(old_contents, args, filename=filename)
            except:
                print "Error processing:", f
                continue

            if PatchManager.get_patches_for_filename(filename):
                raise OutstandingChangesException()

            if old_contents != new_contents:
                file_changes[filename] = (old_contents, new_contents)

        PatchManager.create_patchset(file_changes)
Exemplo n.º 2
0
    def _do_apply_filename(self, target_filename):
        print 'Applying patches to: %s' % target_filename

        patches = PatchManager.get_patches_for_filename(target_filename)
        patch_datas = [p.patch_data for p in patches]
        print ' - Patches Found: %d' % len(patches)

        try:
            # Apply the patches:
            PatchManager.apply_patchs(target_filename, patch_datas)

            # Remove these patches from the database:
            for p in patches:
                session.delete(p)
            session.commit()
            PatchManager.clear_empty_patchsets()
        except PatchApplyError:
            print 'Error applying patch to XX'
Exemplo n.º 3
0
    def _do_plugin(self, args):
        print """Running 'Python-whitespace' plugin"""

        # Apply the changes:
        file_changes = {}
        for filename in args.source_files:

            with open(filename) as f:
                old_contents = f.read()
            new_contents = self.do_text(old_contents, args)

            if PatchManager.get_patches_for_filename(filename):
                raise OutstandingChangesException()

            if old_contents != new_contents:
                file_changes[filename] = (old_contents, new_contents)

        PatchManager.create_patchset(file_changes)