Bug 1460912 - [testing/profiles] Add ability to diff and show multiple profiles with '+' draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 16 May 2018 17:10:13 -0400
changeset 796542 aa0ad798070e98a97cdfac8790876547bce02087
parent 796393 24bae072acb09114c367e6b9ffde9261b2ad8a58
child 796543 661b9ffd8aabd7df4c6bce3dcd3c3622a5198e68
push id110278
push userahalberstadt@mozilla.com
push dateThu, 17 May 2018 19:42:43 +0000
bugs1460912
milestone62.0a1
Bug 1460912 - [testing/profiles] Add ability to diff and show multiple profiles with '+' 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.