xref: /aosp_15_r20/external/skia/infra/bots/find_tasks.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1#!/usr/bin/env python
2#
3# Copyright 2024 Google LLC
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8
9'''Simple tool for finding tasks in tasks.json which match search terms.
10
11Example usage:
12
13Find tasks with dimension "os:Mac-14.5"
14$ find_tasks.py ^os:Mac-14.5$
15
16Find tasks with "ANGLE" in dimensions or name:
17$ find_tasks.py ANGLE
18
19Find tasks with dimension "os:Mac-14.5" and "ANGLE" in dimensions or name:
20$ find_tasks.py ^os:Mac-14.5$ ANGLE
21'''
22
23
24import json
25import os
26import re
27import sys
28
29
30# match_dimensions returns true iff the given search term matches at least one
31# of the task's dimensions.
32def match_dimensions(term, task):
33  for dim in task['dimensions']:
34    if re.search(term, dim):
35      return True
36  return False
37
38
39# match_name returns true iff the given search term matches the task's name.
40def match_name(term, name):
41  return re.search(term, name)
42
43
44# match_task returns true iff all search terms match some part of the task.
45def match_task(terms, name, task):
46  for term in terms:
47    if not (match_name(term, name)
48        or match_dimensions(term, task)):
49      return False
50  return True
51
52
53def main(terms):
54  dir = os.path.dirname(os.path.realpath(__file__))
55  tasks_json = os.path.join(dir, 'tasks.json')
56  with open(tasks_json) as f:
57    taskCfg = json.load(f)
58  for name, task in taskCfg['tasks'].items():
59    if match_task(terms, name, task):
60      print(name)
61
62
63if __name__ == '__main__':
64  main(sys.argv[1:])
65