llvmbot monitor: Reformat code with black

make_table.py was already formatted correctly.

Change-Id: I1917983f9763394d5b370c9c76246572a24bcd3c
diff --git a/monitor/bot-status.py b/monitor/bot-status.py
index 9bf60d7..e86e7bc 100755
--- a/monitor/bot-status.py
+++ b/monitor/bot-status.py
@@ -17,6 +17,7 @@
 import shutil
 import time
 from datetime import datetime, timedelta
+
 # The requests allows HTTP keep-alive which re-uses the same TCP connection
 # to download multiple files.
 import requests
@@ -25,17 +26,20 @@
 
 from buildkite_status import get_buildkite_bots_status
 
+
 def ignored(s):
-  return 'ignore' in s and s['ignore']
+    return "ignore" in s and s["ignore"]
+
+
 def not_ignored(s):
-  return not ignored(s)
+    return not ignored(s)
 
 
 # Returns the parsed json URL or raises an exception
 def wget(session, url):
-  got = session.get(url)
-  got.raise_for_status()
-  return got.json()
+    got = session.get(url)
+    got.raise_for_status()
+    return got.json()
 
 
 # Map from buildbot status codes we want to treat as errors to the color they
@@ -43,99 +47,107 @@
 # https://docs.buildbot.net/latest/developer/results.html#build-result-codes,
 # and these colors match the suggested ones there.
 RESULT_COLORS = {
-  2: 'red',    # Error
-  4: 'purple', # Exception
-  5: 'purple', # Retry
-  6: 'pink',   # Cancelled
+    2: "red",  # Error
+    4: "purple",  # Exception
+    5: "purple",  # Retry
+    6: "pink",  # Cancelled
 }
 
-def get_bot_failing_steps(session, base_url, buildid):
-  try:
-    contents = wget(session, "{}/api/v2/builds/{}/steps"
-                             .format(base_url, buildid))
-  except requests.exceptions.RequestException:
-    return ""
 
-  for step in contents["steps"]:
-    if step["results"] in RESULT_COLORS:
-      yield (step["name"], step["results"])
+def get_bot_failing_steps(session, base_url, buildid):
+    try:
+        contents = wget(session, "{}/api/v2/builds/{}/steps".format(base_url, buildid))
+    except requests.exceptions.RequestException:
+        return ""
+
+    for step in contents["steps"]:
+        if step["results"] in RESULT_COLORS:
+            yield (step["name"], step["results"])
 
 
 # Get the status of a individual bot BOT.  Returns a dict with the
 # information.
 def get_bot_status(session, bot, base_url, builder_url, build_url):
-  try:
-    builds = wget(session,
-                    "{}/api/v2/{}/{}/{}"
-                    .format(base_url, builder_url, bot, build_url))
-  except requests.exceptions.RequestException as e:
-      logging.debug("    Couldn't get builds for bot {}!".format(bot))
-      return {'valid': False}
+    try:
+        builds = wget(
+            session, "{}/api/v2/{}/{}/{}".format(base_url, builder_url, bot, build_url)
+        )
+    except requests.exceptions.RequestException as e:
+        logging.debug("    Couldn't get builds for bot {}!".format(bot))
+        return {"valid": False}
 
-  reversed_builds = iter(sorted(builds['builds'], key=lambda b: -b["number"]))
-  next_build = None
-  for build in reversed_builds:
-    if not build['complete']:
-      next_build = build
-      continue
+    reversed_builds = iter(sorted(builds["builds"], key=lambda b: -b["number"]))
+    next_build = None
+    for build in reversed_builds:
+        if not build["complete"]:
+            next_build = build
+            continue
 
-    time_since = (int(datetime.now().timestamp()) - int(build['complete_at']))
-    duration = int(build['complete_at']) - int(build['started_at'])
-    agent_url = "{}/#/{}/{}".format(base_url, builder_url, build['builderid'])
+        time_since = int(datetime.now().timestamp()) - int(build["complete_at"])
+        duration = int(build["complete_at"]) - int(build["started_at"])
+        agent_url = "{}/#/{}/{}".format(base_url, builder_url, build["builderid"])
 
-    status = {
-      'builder_url': agent_url,
-      'number': build['number'],
-      'build_url':  "{}/builds/{}".format(agent_url, build['number']),
-      'state': build['state_string'],
-      'time_since': timedelta(seconds=time_since),
-      'duration': timedelta(seconds=duration),
-      'fail': build['state_string'] != 'build successful',
-      'next_in_progress': next_build is not None
-    }
+        status = {
+            "builder_url": agent_url,
+            "number": build["number"],
+            "build_url": "{}/builds/{}".format(agent_url, build["number"]),
+            "state": build["state_string"],
+            "time_since": timedelta(seconds=time_since),
+            "duration": timedelta(seconds=duration),
+            "fail": build["state_string"] != "build successful",
+            "next_in_progress": next_build is not None,
+        }
 
-    if status['fail']:
-      buildid = build['buildid']
-      status['steps'] = list(get_bot_failing_steps(session, base_url,
-                                                   buildid))
+        if status["fail"]:
+            buildid = build["buildid"]
+            status["steps"] = list(get_bot_failing_steps(session, base_url, buildid))
 
-    return status
+        return status
 
 
 # Get status for all bots named in the config
 # Return a dictionary of (base_url, bot name) -> status info
 def get_buildbot_bots_status(config):
-  session = requests.Session()
-  bot_cache = {}
+    session = requests.Session()
+    bot_cache = {}
 
-  for server in filter(not_ignored, config):
-    if server['name'] == "Buildkite":
-        continue
+    for server in filter(not_ignored, config):
+        if server["name"] == "Buildkite":
+            continue
 
-    base_url = server['base_url']
-    logging.debug('Parsing server {}...'.format(server['name']))
-    for builder in server['builders']:
-      logging.debug('  Parsing builders {}...'.format(builder['name']))
-      for bot in builder['bots']:
-        bot_key = (base_url, bot['name'])
-        if bot_key in bot_cache:
-          continue
+        base_url = server["base_url"]
+        logging.debug("Parsing server {}...".format(server["name"]))
+        for builder in server["builders"]:
+            logging.debug("  Parsing builders {}...".format(builder["name"]))
+            for bot in builder["bots"]:
+                bot_key = (base_url, bot["name"])
+                if bot_key in bot_cache:
+                    continue
 
-        logging.debug('    Parsing bot {}...'.format(bot['name']))
-        status = get_bot_status(session, bot['name'], base_url, server['builder_url'],
-                                server['build_url'])
-        if status is not None:
-          if status.get("valid", True):
-            logging.debug("    Bot status: " + ("FAIL" if status['fail'] else "PASS"))
-          bot_cache[bot_key] = status
+                logging.debug("    Parsing bot {}...".format(bot["name"]))
+                status = get_bot_status(
+                    session,
+                    bot["name"],
+                    base_url,
+                    server["builder_url"],
+                    server["build_url"],
+                )
+                if status is not None:
+                    if status.get("valid", True):
+                        logging.debug(
+                            "    Bot status: " + ("FAIL" if status["fail"] else "PASS")
+                        )
+                    bot_cache[bot_key] = status
 
-  return bot_cache
+    return bot_cache
 
 
 def write_bot_status(config, output_file, bots_status):
-  temp = tempfile.NamedTemporaryFile(mode='w+', delete=False)
+    temp = tempfile.NamedTemporaryFile(mode="w+", delete=False)
 
-  temp.write(dedent("""\
+    temp.write(
+        dedent(
+            """\
           <!DOCTYPE html>
           <style>
             /* Combine the border between cells to prevent 1px gaps
@@ -147,129 +159,153 @@
             tbody tr:nth-child(even) td {
               background-color: #ededed;
             }
-          </style>"""))
+          </style>"""
+        )
+    )
 
-  column_titles = [
-          "Buildbot",
-          "Status",
-          "T Since",
-          "Duration",
-          "Build",
-          "Failing steps",
-          "Build In Progress",
-  ]
-  num_columns = len(column_titles)
+    column_titles = [
+        "Buildbot",
+        "Status",
+        "T Since",
+        "Duration",
+        "Build",
+        "Failing steps",
+        "Build In Progress",
+    ]
+    num_columns = len(column_titles)
 
-  # The first table should also say when this was generated.
-  # If we were to put this in its own header only table, it would
-  # not align with the rest because it has no content.
-  first = True
+    # The first table should also say when this was generated.
+    # If we were to put this in its own header only table, it would
+    # not align with the rest because it has no content.
+    first = True
 
-  # Dump all servers / bots
-  for server in filter(not_ignored, config):
-    with Table(temp) as table:
-      table.Border(0).Cellspacing(1).Cellpadding(2)
+    # Dump all servers / bots
+    for server in filter(not_ignored, config):
+        with Table(temp) as table:
+            table.Border(0).Cellspacing(1).Cellpadding(2)
 
-      table.AddRow().AddCell().Colspan(num_columns)
+            table.AddRow().AddCell().Colspan(num_columns)
 
-      if first:
-        table.AddRow().AddHeader("Generated {} ({})".format(
-            datetime.today().ctime(), time.tzname[time.daylight])).Colspan(num_columns)
-        table.AddRow().AddCell().Colspan(num_columns)
-        first = False
+            if first:
+                table.AddRow().AddHeader(
+                    "Generated {} ({})".format(
+                        datetime.today().ctime(), time.tzname[time.daylight]
+                    )
+                ).Colspan(num_columns)
+                table.AddRow().AddCell().Colspan(num_columns)
+                first = False
 
-      table.AddRow().AddHeader(server['name']).Colspan(num_columns)
+            table.AddRow().AddHeader(server["name"]).Colspan(num_columns)
 
-      for builder in server['builders']:
-        table.AddRow().AddCell().Colspan(num_columns)
-        table.AddRow().AddHeader(builder['name']).Colspan(num_columns)
-        title_row = table.AddRow()
-        for title in column_titles:
-          title_row.AddHeader(title)
+            for builder in server["builders"]:
+                table.AddRow().AddCell().Colspan(num_columns)
+                table.AddRow().AddHeader(builder["name"]).Colspan(num_columns)
+                title_row = table.AddRow()
+                for title in column_titles:
+                    title_row.AddHeader(title)
 
-        table.BeginBody()
+                table.BeginBody()
 
-        for bot in builder['bots']:
-          logging.debug("Writing out status for {}".format(bot['name']))
+                for bot in builder["bots"]:
+                    logging.debug("Writing out status for {}".format(bot["name"]))
 
-          row = table.AddRow()
-          base_url = server['base_url']
-          try:
-            status = bots_status[(base_url, bot['name'])]
-          except KeyError:
-            row.AddCell("{} is offline!".format(bot['name'])).Colspan(num_columns)
-            continue
-          else:
-              if not status.get('valid', True):
-                row.AddCell("Could not read status for {}!".format(
-                  bot['name'])).Colspan(num_columns)
-                continue
+                    row = table.AddRow()
+                    base_url = server["base_url"]
+                    try:
+                        status = bots_status[(base_url, bot["name"])]
+                    except KeyError:
+                        row.AddCell("{} is offline!".format(bot["name"])).Colspan(
+                            num_columns
+                        )
+                        continue
+                    else:
+                        if not status.get("valid", True):
+                            row.AddCell(
+                                "Could not read status for {}!".format(bot["name"])
+                            ).Colspan(num_columns)
+                            continue
 
-          row.AddCell("<a href='{}'>{}</a>".format(status['builder_url'], bot['name']))
-          row.AddCell("<font color='{}'>{}</font>"
-                     .format('red' if status['fail'] else 'green',
-                             'FAIL' if status['fail'] else 'PASS'))
+                    row.AddCell(
+                        "<a href='{}'>{}</a>".format(status["builder_url"], bot["name"])
+                    )
+                    row.AddCell(
+                        "<font color='{}'>{}</font>".format(
+                            "red" if status["fail"] else "green",
+                            "FAIL" if status["fail"] else "PASS",
+                        )
+                    )
 
-          time_since_cell = row.AddCell()
-          if 'time_since' in status:
-            time_since = status['time_since']
-            # No build should be taking more than a day
-            if time_since > timedelta(hours=24):
-                time_since = "<p style=\"color:red\">{}</p>".format(
-                        time_since)
-            else:
-                time_since = str(time_since)
+                    time_since_cell = row.AddCell()
+                    if "time_since" in status:
+                        time_since = status["time_since"]
+                        # No build should be taking more than a day
+                        if time_since > timedelta(hours=24):
+                            time_since = '<p style="color:red">{}</p>'.format(
+                                time_since
+                            )
+                        else:
+                            time_since = str(time_since)
 
-            time_since_cell.Content(time_since)
+                        time_since_cell.Content(time_since)
 
-          duration_cell = row.AddCell()
-          if 'duration' in status:
-            duration_cell.Content(status['duration'])
+                    duration_cell = row.AddCell()
+                    if "duration" in status:
+                        duration_cell.Content(status["duration"])
 
-          number_cell = row.AddCell()
-          if 'number' in status:
-            number_cell.Content("<a href='{}'>{}</a>".format(
-                status['build_url'], status['number']))
+                    number_cell = row.AddCell()
+                    if "number" in status:
+                        number_cell.Content(
+                            "<a href='{}'>{}</a>".format(
+                                status["build_url"], status["number"]
+                            )
+                        )
 
-          steps_cell = row.AddCell()
-          if 'steps' in status and status['steps']:
-            def render_step(name, result):
-              return "<font color='{}'>{}</font>".format(RESULT_COLORS[result], name)
-            step_list = ', '.join(render_step(name, result) for name, result in status['steps'])
-            steps_cell.Style("text-align:center").Content(step_list)
+                    steps_cell = row.AddCell()
+                    if "steps" in status and status["steps"]:
 
-          next_in_progress_cell = row.AddCell()
-          if 'next_in_progress' in status:
-            next_in_progress_cell.Content(
-                       "Yes" if status['next_in_progress'] else "No")
+                        def render_step(name, result):
+                            return "<font color='{}'>{}</font>".format(
+                                RESULT_COLORS[result], name
+                            )
 
-        table.EndBody()
+                        step_list = ", ".join(
+                            render_step(name, result)
+                            for name, result in status["steps"]
+                        )
+                        steps_cell.Style("text-align:center").Content(step_list)
 
-  # Move temp to main (atomic change)
-  temp.close()
-  shutil.move(temp.name, output_file)
+                    next_in_progress_cell = row.AddCell()
+                    if "next_in_progress" in status:
+                        next_in_progress_cell.Content(
+                            "Yes" if status["next_in_progress"] else "No"
+                        )
+
+                table.EndBody()
+
+    # Move temp to main (atomic change)
+    temp.close()
+    shutil.move(temp.name, output_file)
 
 
 if __name__ == "__main__":
-  parser = argparse.ArgumentParser()
-  parser.add_argument('-d', dest='debug', action='store_true',
-                      help='show debug log messages')
-  parser.add_argument('config_file',
-                      help='Bots description in JSON format')
-  parser.add_argument('output_file',
-                      help='output HTML path')
-  args = parser.parse_args()
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        "-d", dest="debug", action="store_true", help="show debug log messages"
+    )
+    parser.add_argument("config_file", help="Bots description in JSON format")
+    parser.add_argument("output_file", help="output HTML path")
+    args = parser.parse_args()
 
-  if args.debug:
-    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
+    if args.debug:
+        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
 
-  try:
-    with open(args.config_file, "r") as f:
-      config = json.load(f)
-  except IOError as e:
-    print("error: failed to read {} config file: {}".format(args.config_file, e))
-    sys.exit(os.EX_CONFIG)
+    try:
+        with open(args.config_file, "r") as f:
+            config = json.load(f)
+    except IOError as e:
+        print("error: failed to read {} config file: {}".format(args.config_file, e))
+        sys.exit(os.EX_CONFIG)
 
-  status = get_buildbot_bots_status(config)
-  status.update(get_buildkite_bots_status(config))
-  write_bot_status(config, args.output_file, status)
+    status = get_buildbot_bots_status(config)
+    status.update(get_buildkite_bots_status(config))
+    write_bot_status(config, args.output_file, status)
diff --git a/monitor/buildkite_status.py b/monitor/buildkite_status.py
index 0dbaa10..3f9924b 100755
--- a/monitor/buildkite_status.py
+++ b/monitor/buildkite_status.py
@@ -4,9 +4,11 @@
 import logging
 from datetime import timedelta
 from functools import lru_cache
+
 # Base dict order not guaranteed until 3.7+
 from collections import OrderedDict
 from datetime import datetime
+
 # To convert time stamps
 # (use datetime.datetime.fromisoformat in Python3.7+)
 import dateutil.parser
@@ -37,12 +39,10 @@
             # strip to remove ending newline
             token = f.readline().strip()
         if not token:
-            logging.debug(err_msg.format(
-                "Buildkite API token file was empty"))
+            logging.debug(err_msg.format("Buildkite API token file was empty"))
             token = None
     except FileNotFoundError:
-        logging.debug(err_msg.format(
-            "Couldn't read Buildkite API token file"))
+        logging.debug(err_msg.format("Couldn't read Buildkite API token file"))
 
     return token
 
@@ -50,13 +50,14 @@
 @lru_cache(maxsize=None)
 def get_pipeline_builds(organisation, pipeline):
     return buildkite.builds().list_all_for_pipeline(
-        organisation, pipeline,
+        organisation,
+        pipeline,
         # Finished means passed, failed, blocked or cancelled
-        states=[BuildState.FINISHED])
+        states=[BuildState.FINISHED],
+    )
 
 
-def get_last_finished_build_status(organisation, job_name,
-                                   pipeline):
+def get_last_finished_build_status(organisation, job_name, pipeline):
     """
     Get information about the last finished build of a particular
     job. (where a job is one of the pipeline steps)
@@ -69,55 +70,53 @@
         # branches.
         # For the status page we ignore pre-commit and release builds.
         # ph_buildable_revision is set if Phabricator triggered this build.
-        if 'ph_buildable_revision' in build['env'] or \
-           build['branch'] != 'main':
+        if "ph_buildable_revision" in build["env"] or build["branch"] != "main":
             continue
 
         # Where each "job" is a config e.g. AArch64, MacOS, C++20 etc.
-        for job in build['jobs']:
+        for job in build["jobs"]:
             # Some jobs won't have a name. I think these are the wait steps
             # between jobs or groups of jobs.
-            if job.get('name') != job_name:
+            if job.get("name") != job_name:
                 continue
 
             # Some jobs were never started due to failures earlier in the pipeline.
             # This isn't our fault so ignore these.
-            started_time = job.get('started_at')
+            started_time = job.get("started_at")
             if started_time is None:
                 continue
 
             # We use started because that's when it starts to
             # run on the agent (don't want to include waiting time)
             started = dateutil.parser.isoparse(started_time)
-            finished = dateutil.parser.isoparse(job['finished_at'])
+            finished = dateutil.parser.isoparse(job["finished_at"])
             # Buildkite gives us mS resoloution but we don't need that
-            duration = timedelta(seconds=int(
-                (finished - started).total_seconds()))
+            duration = timedelta(seconds=int((finished - started).total_seconds()))
             # Time from buildkite ends up as UTC but now has no
             # timezone info by default
             now = datetime.now(finished.tzinfo)
-            time_since = timedelta(
-                seconds=int((now - finished).total_seconds()))
+            time_since = timedelta(seconds=int((now - finished).total_seconds()))
 
-            state = job['state']
-            failed = state != 'passed'
+            state = job["state"]
+            failed = state != "passed"
             status = {
                 # 'url' is the API url, we want a clickable link
-                'builder_url': job['agent']['web_url'],
+                "builder_url": job["agent"]["web_url"],
                 # We use the job's url because it takes you to the
                 # specific agent, instead of the build's url
-                'build_url': job['web_url'],
-                'number': build['number'],
-                'state': state,
-                'duration': duration,
-                'time_since': time_since,
-                'fail': failed,
+                "build_url": job["web_url"],
+                "number": build["number"],
+                "state": state,
+                "duration": duration,
+                "time_since": time_since,
+                "fail": failed,
             }
             return status
 
     logging.debug(
-        "Found no finished builds for job \"{}\" "
-        "on pipeline \"{}\"".format(job_name, pipeline))
+        'Found no finished builds for job "{}" '
+        'on pipeline "{}"'.format(job_name, pipeline)
+    )
     return dict(valid=False)
 
 
@@ -134,31 +133,29 @@
     buildkite.set_access_token(token)
 
     for server in config:
-        if server['name'] != "Buildkite":
+        if server["name"] != "Buildkite":
             continue
 
         if token is None:
             # We cannot query buildkite but we don't want to mark these
             # bots as offline because we don't know that.
-            for builder in server['builders']:
-                for job in builder['bots']:
-                    status[bot_key(job['name'])] = {'valid': False}
+            for builder in server["builders"]:
+                for job in builder["bots"]:
+                    status[bot_key(job["name"])] = {"valid": False}
             continue
 
         # If we have a valid token then we can get the real status
-        organisation = server.get('buildkite_org')
+        organisation = server.get("buildkite_org")
         if organisation is None:
-            raise RuntimeError(
-                "Buildkite servers must also have a 'buildkite_org'")
+            raise RuntimeError("Buildkite servers must also have a 'buildkite_org'")
 
-        for builder in server['builders']:
-            for job in builder['bots']:
-                job_name = job['name']
-                logging.debug("Getting status for buildkite job \"{}\"".format(
-                    job_name))
+        for builder in server["builders"]:
+            for job in builder["bots"]:
+                job_name = job["name"]
+                logging.debug('Getting status for buildkite job "{}"'.format(job_name))
 
                 status[bot_key(job_name)] = get_last_finished_build_status(
-                    organisation, job_name,
-                    job['buildkite_pipeline'])
+                    organisation, job_name, job["buildkite_pipeline"]
+                )
 
     return status