Revert "devserver: Stop patching devserver internals for port=0"

This reverts commit 0ee73f408b6fa66b1f7defadb1073ff051567010.

In addition, this makes hacking --port=0 on cherrypy conditional on the
version of the cherrypy. The reason we need this is that our devservers
run on older linux and their cherrypy can't be upreved easily. But for
Chrome OS we have already upreved cherrypy and we don't need this
hacking.

There are also other pylint errors fixed.

BUG=chromium:1018237
TEST=devserver_integration_test

Change-Id: If65b75deb565ca78353803c8eab3f7cfc3851e5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1914538
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/devserver.py b/devserver.py
index eeb5418..3b89260 100755
--- a/devserver.py
+++ b/devserver.py
@@ -24,6 +24,7 @@
 
 from __future__ import print_function
 
+import distutils.version  # pylint: disable=import-error,no-name-in-module
 import json
 import optparse  # pylint: disable=deprecated-module
 import os
@@ -1680,6 +1681,18 @@
   dev_server = DevServerRoot(_xbuddy)
   health_checker_app = health_checker.Root(dev_server, options.static_dir)
 
+  # Patch CherryPy to support binding to any available port (--port=0) only for
+  # cherrypy versions smaller or equal to 3.2.2.
+  #
+  # TODO(crbug/1006305): Remove this once we have deprecated omaha_devserver.py
+  # in the autotests as that is the only use case.
+  #
+  # pylint: disable=no-member
+  if (distutils.version.StrictVersion(cherrypy.__version__) <=
+      distutils.version.StrictVersion('3.2.2')):
+    cherrypy_ext.ZeroPortPatcher.DoPatch(cherrypy)
+  # pylint: enable=no-member
+
   if options.pidfile:
     plugins.PIDFile(cherrypy.engine, options.pidfile).subscribe()