Bug 1216950 - Add --list to |mach try| to display saved try strings, r=chmanchester
authorJames Graham <james@hoppipolla.co.uk>
Wed, 21 Oct 2015 12:13:48 +0100
changeset 304299 783dfecbca55b4285e1abce644eb080c4052cc9f
parent 304298 781f5d938ed3a146fb4256756632ef838b707292
child 304300 f31d5853b0a0ebd0730b85cc1514215e1f8864b5
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1216950
milestone44.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 1216950 - Add --list to |mach try| to display saved try strings, r=chmanchester
testing/mach_commands.py
testing/tools/autotry/autotry.py
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -598,18 +598,22 @@ class PushToTry(MachCommandBase):
         """
 
         from mozbuild.testing import TestResolver
         from mozbuild.controller.building import BuildDriver
         from autotry import AutoTry
 
         print("mach try is under development, please file bugs blocking 1149670.")
 
-        resolver = self._spawn(TestResolver)
-        at = AutoTry(self.topsrcdir, resolver, self._mach_context)
+        resolver_func = lambda: self._spawn(TestResolver)
+        at = AutoTry(self.topsrcdir, resolver_func, self._mach_context)
+
+        if kwargs["list"]:
+            at.list_presets()
+            sys.exit()
 
         if kwargs["load"] is not None:
             defaults = at.load_config(kwargs["load"])
 
             if defaults is None:
                 print("No saved configuration called %s found in autotry.ini" % kwargs["load"],
                       file=sys.stderr)
 
--- a/testing/tools/autotry/autotry.py
+++ b/testing/tools/autotry/autotry.py
@@ -33,16 +33,18 @@ def arg_parser():
     parser.add_argument('--no-push', dest='push', action='store_false',
                         help='Do not push to try as a result of running this command (if '
                         'specified this command will only print calculated try '
                         'syntax and selection info).')
     parser.add_argument('--save', dest="save", action='store',
                         help="Save the command line arguments for future use with --preset.")
     parser.add_argument('--preset', dest="load", action='store',
                         help="Load a saved set of arguments. Additional arguments will override saved ones.")
+    parser.add_argument('--list', action='store_true',
+                        help="List all saved try strings")
     parser.add_argument('extra_args', nargs=argparse.REMAINDER,
                         help='Extra arguments to put in the try push.')
     parser.add_argument('-v', "--verbose", dest='verbose', action='store_true', default=False,
                         help='Print detailed information about the resulting test selection '
                         'and commands performed.')
     return parser
 
 class TryArgumentTokenizer(object):
@@ -164,27 +166,34 @@ class AutoTry(object):
         "chrome": "mochitest-o",
         "browser-chrome": "mochitest-bc",
         "devtools-chrome": "mochitest-dt",
         "crashtest": "crashtest",
         "reftest": "reftest",
         "web-platform-tests": "web-platform-tests",
     }
 
-    def __init__(self, topsrcdir, resolver, mach_context):
+    def __init__(self, topsrcdir, resolver_func, mach_context):
         self.topsrcdir = topsrcdir
-        self.resolver = resolver
+        self._resolver_func = resolver_func
+        self._resolver = None
         self.mach_context = mach_context
 
         if os.path.exists(os.path.join(self.topsrcdir, '.hg')):
             self._use_git = False
         else:
             self._use_git = True
 
     @property
+    def resolver(self):
+        if self._resolver is None:
+            self._resolver = self.resolver_func
+        return self._resolver
+
+    @property
     def config_path(self):
         return os.path.join(self.mach_context.state_dir, "autotry.ini")
 
     def load_config(self, name):
         config = ConfigParser.RawConfigParser()
         success = config.read([self.config_path])
         if not success:
             return None
@@ -193,16 +202,33 @@ class AutoTry(object):
             data = config.get("try", name)
         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
             return None
 
         kwargs = vars(arg_parser().parse_args(self.split_try_string(data)))
 
         return kwargs
 
+    def list_presets(self):
+        config = ConfigParser.RawConfigParser()
+        success = config.read([self.config_path])
+
+        data = []
+        if success:
+            try:
+                data = config.items("try")
+            except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+                pass
+
+        if not data:
+            print("No presets found")
+
+        for name, try_string in data:
+            print("%s: %s" % (name, try_string))
+
     def split_try_string(self, data):
         return re.findall(r'(?:\[.*?\]|\S)+', data)
 
     def save_config(self, name, data):
         assert data.startswith("try: ")
         data = data[len("try: "):]
 
         parser = ConfigParser.RawConfigParser()