Repository: buildbot/buildbot

Issue:
Fix flake8 nits.
This is the rebased version of flakechecks (which I kinda screwed up with merges).


Discussion:

Resolving patch:
diff --git a/master/buildbot/steps/source/base.py b/master/buildbot/steps/source/base.py
--- a/master/buildbot/steps/source/base.py
+++ b/master/buildbot/steps/source/base.py
@@ -185,8 +185,8 @@ def computeSourceRevision(self, changes):
         self.checkoutDelay value."""
         return None
 
-    def applyPatch(self, patchlevel):
-        patch_command = ['patch', '-p%s' % patchlevel, '--remove-empty-files',
+    def applyPatch(self, patch):
+        patch_command = ['patch', '-p%s' % patch[0], '--remove-empty-files',
                          '--force', '--forward', '-i', '.buildbot-diff']
         cmd = buildstep.RemoteShellCommand(self.workdir,
                                            patch_command,
@@ -204,7 +204,6 @@ def evaluateCommand(_):
         return d
 
     def patch(self, _, patch):
-        patchlevel = patch[0]
         diff = patch[1]
         root = None
         if len(patch) >= 3:
@@ -239,7 +238,7 @@ def evaluateCommand(_):
 
         d = _downloadFile(diff, ".buildbot-diff")
         d.addCallback(lambda _ : _downloadFile("patched\n", ".buildbot-patched"))
-        d.addCallback(lambda _: self.applyPatch(patchlevel))
+        d.addCallback(lambda _: self.applyPatch(patch))
         cmd = buildstep.RemoteCommand('rmdir', {'dir': os.path.join(self.workdir, ".buildbot-diff"),
                                                 'logEnviron':self.logEnviron})
         cmd.useLog(self.stdio_log, False)
diff --git a/master/buildbot/steps/source/git.py b/master/buildbot/steps/source/git.py
--- a/master/buildbot/steps/source/git.py
+++ b/master/buildbot/steps/source/git.py
@@ -516,3 +516,7 @@ def checkSupport(stdout):
             return gitInstalled
         d.addCallback(checkSupport)
         return d
+    def applyPatch(self, patch):
+        d = self._dovccmd(['apply', '--index', '-p', str(patch[0])],
+                          initialStdin=patch[1])
+        return d
diff --git a/master/buildbot/steps/source/mercurial.py b/master/buildbot/steps/source/mercurial.py
--- a/master/buildbot/steps/source/mercurial.py
+++ b/master/buildbot/steps/source/mercurial.py
@@ -102,13 +102,6 @@ def checkInstall(hgInstalled):
         d.addCallback(checkInstall)
 
         d.addCallback(lambda _: self.sourcedirIsPatched())
-        def checkPatched(patched):
-            if patched:
-                return self._dovccmd(['--config', 'extensions.purge=', 'purge'])
-            else:
-                return 0
-        d.addCallback(checkPatched)
-
         if self.branchType == 'dirname':
             self.repourl = self.repourl + (branch or '')
             self.branch = self.defaultBranch
@@ -371,3 +364,7 @@ def check(res):
         d.addCallback(check)
         return d
 
+    def applyPatch(self, patch):
+        d = self._dovccmd(['import', '--no-commit', '-p', str(patch[0]), '-'],
+               initialStdin=patch[1])
+        return d


Test patch:
diff --git a/master/buildbot/test/unit/test_steps_source_git.py b/master/buildbot/test/unit/test_steps_source_git.py
--- a/master/buildbot/test/unit/test_steps_source_git.py
+++ b/master/buildbot/test/unit/test_steps_source_git.py
@@ -190,8 +190,8 @@ def test_mode_full_clean_patch(self):
                                         mode=None))
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['patch', '-p1', '--remove-empty-files',
-                                 '--force', '--forward', '-i', '.buildbot-diff'])
+                        command=['git', 'apply', '--index', '-p', '1'],
+                        initialStdin='patch')
             + 0,
             Expect('rmdir', dict(dir='wkdir/.buildbot-diff',
                                  logEnviron=True))
@@ -245,8 +245,8 @@ def test_mode_full_clean_patch_fail(self):
                                         mode=None))
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['patch', '-p1', '--remove-empty-files',
-                                 '--force', '--forward', '-i', '.buildbot-diff'])
+                        command=['git', 'apply', '--index', '-p', '1'],
+                        initialStdin='patch')
             + 1,
         )
         self.expectOutcome(result=FAILURE, status_text=["updating"])
diff --git a/master/buildbot/test/unit/test_steps_source_mercurial.py b/master/buildbot/test/unit/test_steps_source_mercurial.py
--- a/master/buildbot/test/unit/test_steps_source_mercurial.py
+++ b/master/buildbot/test/unit/test_steps_source_mercurial.py
@@ -208,10 +208,6 @@ def test_mode_full_clean_patch(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
             + 0,
-            ExpectShell(workdir='wkdir',
-                        command=['hg', '--verbose', '--config',
-                                 'extensions.purge=', 'purge'])
-            + 0,
             Expect('stat', dict(file='wkdir/.hg',
                                       logEnviron=True))
             + 0,
@@ -246,8 +242,8 @@ def test_mode_full_clean_patch(self):
                                         mode=None))
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['patch', '-p1', '--remove-empty-files',
-                                 '--force', '--forward', '-i', '.buildbot-diff'])
+                        command=[ 'hg', '--verbose', 'import', '--no-commit', '-p', '1', '-'],
+                        initialStdin='patch')
             + 0,
             Expect('rmdir', dict(dir='wkdir/.buildbot-diff',
                                  logEnviron=True))
@@ -275,10 +271,6 @@ def test_mode_full_clean_patch_fail(self):
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                       logEnviron=True))
             + 0,
-            ExpectShell(workdir='wkdir',
-                        command=['hg', '--verbose', '--config',
-                                 'extensions.purge=', 'purge'])
-            + 0,
             Expect('stat', dict(file='wkdir/.hg',
                                       logEnviron=True))
             + 0,
@@ -313,8 +305,8 @@ def test_mode_full_clean_patch_fail(self):
                                         mode=None))
             + 0,
             ExpectShell(workdir='wkdir',
-                        command=['patch', '-p1', '--remove-empty-files',
-                                 '--force', '--forward', '-i', '.buildbot-diff'])
+                        command=[ 'hg', '--verbose', 'import', '--no-commit', '-p', '1', '-'],
+                        initialStdin='patch')
             + 1,
         )
         self.expectOutcome(result=FAILURE, status_text=["updating"])