Bug 1513951 - [tryselect] Pass preset path into PresetHandler's constructor r=gbrown
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 28 Feb 2019 18:26:03 +0000
changeset 519877 3ea24e73acf56ab31adf31b779df854e468a4906
parent 519876 277d70b1fd3964c42bdeb73da196c4c2b036035c
child 519878 74de0c0022dc572d9a6aab43e723942836eb8afd
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1513951 - [tryselect] Pass preset path into PresetHandler's constructor r=gbrown This will make it possible to have multiple instances of PresetHandler to support multiple preset files. Differential Revision: https://phabricator.services.mozilla.com/D21429
--- a/tools/tryselect/preset.py
+++ b/tools/tryselect/preset.py
@@ -9,25 +9,25 @@ import os
 import subprocess
 from collections import defaultdict
 import yaml
 from mozboot.util import get_state_dir
 class PresetHandler(object):
-    config_path = os.path.join(get_state_dir(), "try_presets.yml")
-    def __init__(self):
+    def __init__(self, path):
+        self.path = path
         self._presets = {}
     def presets(self):
-        if not self._presets and os.path.isfile(self.config_path):
-            with open(self.config_path, 'r') as fh:
+        if not self._presets and os.path.isfile(self.path):
+            with open(self.path, 'r') as fh:
                 self._presets = yaml.safe_load(fh) or {}
         return self._presets
     def __contains__(self, name):
         return name in self.presets
     def __getitem__(self, name):
@@ -42,38 +42,38 @@ class PresetHandler(object):
     def edit(self):
         if 'EDITOR' not in os.environ:
             print("error: must set the $EDITOR environment variable to use --edit-presets")
-        subprocess.call([os.environ['EDITOR'], self.config_path])
+        subprocess.call([os.environ['EDITOR'], self.path])
     def save(self, name, **data):
         self.presets[name] = data
-        with open(self.config_path, "w") as fh:
+        with open(self.path, "w") as fh:
-presets = PresetHandler()
+presets = PresetHandler(os.path.join(get_state_dir(), "try_presets.yml"))
 def migrate_old_presets():
     """Move presets from the old `autotry.ini` format to the new
     `try_presets.yml` one.
     from .selectors.syntax import AutoTry, SyntaxParser
     old_preset_path = os.path.join(get_state_dir(), 'autotry.ini')
-    if os.path.isfile(presets.config_path) or not os.path.isfile(old_preset_path):
+    if os.path.isfile(presets.path) or not os.path.isfile(old_preset_path):
-    print("migrating saved presets from '{}' to '{}'".format(old_preset_path, presets.config_path))
+    print("migrating saved presets from '{}' to '{}'".format(old_preset_path, presets.path))
     config = ConfigParser.ConfigParser()
     unknown = defaultdict(list)
     for section in config.sections():
         for name, value in config.items(section):
             kwargs = {}
             if section == 'fuzzy':  # try fuzzy