Bug 1460912 - [testing/profiles] Add ability to diff and show multiple profiles with '+' r=rwood
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 16 May 2018 17:10:13 -0400
changeset 418774 2600a2947d2546ca97546c35791a27dc6524cbfc
parent 418773 639903e9e1367206a4f2757460d365a1f934bd67
child 418775 0b6ae2cdbebab544db08477b7e51b57cd0f8a211
push id103398
push userdluca@mozilla.com
push dateFri, 18 May 2018 10:00:25 +0000
treeherdermozilla-inbound@54db0dcb08f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrwood
bugs1460912
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1460912 - [testing/profiles] Add ability to diff and show multiple profiles with '+' r=rwood This lets you compare show or diff multiple profiles joined together. For example: ./profile show common+perf Or: ./profile diff common+perf unittest MozReview-Commit-ID: nf8xOjmd1u
testing/profiles/profile
--- a/testing/profiles/profile
+++ b/testing/profiles/profile
@@ -4,17 +4,17 @@
 
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # The beginning of this script is both valid shell and valid python,
 # such that the script starts with the shell and is reexecuted python
 '''which' mach > /dev/null 2>&1 && exec mach python "$0" "$@" ||
-echo "mach not found, either add it to your \$PATH or run this script via ./mach python testing/profiles/profile"; exit
+echo "mach not found, either add it to your \$PATH or run this script via ./mach python testing/profiles/profile"; exit  # noqa
 '''
 
 from __future__ import absolute_import, unicode_literals, print_function
 
 """This script can be used to:
 
     1) Show all preferences for a given suite
     2) Diff preferences between two suites or profiles
@@ -62,34 +62,46 @@ def read_prefs(profile, pref_files=None)
 
         try:
             prefs.update(Preferences.read_json(path))
         except ValueError:
             prefs.update(Preferences.read_prefs(path))
     return prefs
 
 
+def get_profiles(key):
+    """Return a list of profile names for key."""
+    with open(os.path.join(here, 'profiles.json'), 'r') as fh:
+        profiles = json.load(fh)
+
+    if '+' in key:
+        keys = key.split('+')
+    else:
+        keys = [key]
+
+    names = set()
+    for key in keys:
+        if key in profiles:
+            names.update(profiles[key])
+        elif os.path.isdir(os.path.join(here, key)):
+            names.add(key)
+
+    if not names:
+        raise ValueError('{} is not a recognized suite or profile'.format(key))
+    return names
+
+
 def read(key):
     """Read preferences relevant to either a profile or suite.
 
     :param key: Can either be the name of a profile, or the name of
                 a suite as defined in suites.json.
     """
-    with open(os.path.join(here, 'profiles.json'), 'r') as fh:
-        profiles = json.load(fh)
-
-    if key in profiles:
-        names = profiles[key]
-    elif os.path.isdir(os.path.join(here, key)):
-        names = [key]
-    else:
-        raise ValueError('{} is not a recognized suite or profile'.format(key))
-
     prefs = {}
-    for profile in names:
+    for profile in get_profiles(key):
         prefs.update(read_prefs(profile))
     return prefs
 
 
 def diff(a, b):
     """Diff two profiles or suites.
 
     :param a: The first profile or suite name.