findmissing: getopen: add debug option

Add debug option (-d, --debug) to enable debug logs.

Note: Python's logging default writes logs to stderr.  Thus, the patch
doesn't break such `./getopen.py -c -d | tee -a conflicts` usage if any.

BUG=none
TEST=./getopen.py -c -d

Change-Id: I086d897adb69d22fc09e01694a3d52ca923c5d82
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/3463399
Tested-by: Tzung-Bi Shih <tzungbi@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Commit-Queue: Tzung-Bi Shih <tzungbi@chromium.org>
diff --git a/contrib/findmissing/getopen.py b/contrib/findmissing/getopen.py
index 1a95686..a9a6b64 100755
--- a/contrib/findmissing/getopen.py
+++ b/contrib/findmissing/getopen.py
@@ -217,12 +217,13 @@
 
 @util.cloud_sql_proxy_decorator
 @util.preliminary_check_decorator(False)
-def report_integration_status(branch, conflicts, is_chromium):
+def report_integration_status(branch=None, conflicts=False, chromium=False,
+                              debug=False):
     """Report list of open patches"""
 
     handled_shas = []
 
-    if is_chromium:
+    if chromium:
         metadata = common.get_kernel_metadata(common.Kernel.linux_chrome)
     else:
         metadata = common.get_kernel_metadata(common.Kernel.linux_stable)
@@ -246,7 +247,7 @@
     """Parses command line args and calls the actual function with parsed parameters
 
     To execute:
-    ./getopen [-b branch] [-c] [-C]
+    ./getopen [-b branch] [-c] [-C] [-d]
     """
 
     metadata = common.get_kernel_metadata(common.Kernel.linux_stable)
@@ -257,9 +258,11 @@
                         help='Look for pending chromium patches')
     parser.add_argument('-c', '--conflicts', action='store_true',
                         help='Check for conflicting patches')
-    args = parser.parse_args()
+    parser.add_argument('-d', '--debug', action='store_true',
+                        help='Enable debug messages')
+    args = vars(parser.parse_args())
 
-    report_integration_status(args.branch, args.conflicts, args.chromium)
+    report_integration_status(**args)
 
 if __name__ == '__main__':
     report_integration_status_parse()
diff --git a/contrib/findmissing/util.py b/contrib/findmissing/util.py
index a855290..1c01d00 100755
--- a/contrib/findmissing/util.py
+++ b/contrib/findmissing/util.py
@@ -59,7 +59,7 @@
     """Decorator for performing environment related checks."""
     def wrap_preliminary_check(f):
         """Inner function that wraps method with preliminary check."""
-        def wrapped_preliminary_check(*args):
+        def wrapped_preliminary_check(*args, **kwargs):
             """Sanity checks on state of environment before executing decorated function."""
             if is_gce:
                 # Ensures we have service account credentials to connect to cloudsql (GCP)
@@ -73,12 +73,15 @@
             if is_gce:
                 level = logging.INFO
             else:
-                level = logging.WARNING
+                if kwargs.get('debug'):
+                    level = logging.DEBUG
+                else:
+                    level = logging.WARNING
 
             logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=level,
                                 datefmt='%Y-%m-%d %H:%M:%S')
 
-            f(*args)
+            f(*args, **kwargs)
         return wrapped_preliminary_check
     return wrap_preliminary_check