mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +02:00
mozboot.util.get_state_dir() returns a tuple of (<path>, <bool). The bool denotes whether or not the state dir came from an environment variable. But this value is only used in a single place, and is very easy to test for anyway. It's not worth the added complexity it imposes on all other consumers of this function. Let's just make this function return the path. Differential Revision: https://phabricator.services.mozilla.com/D15723 --HG-- extra : moz-landing-system : lando
69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
# 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/.
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
import ConfigParser
|
|
import os
|
|
import subprocess
|
|
|
|
from mozboot.util import get_state_dir
|
|
|
|
|
|
CONFIG_PATH = os.path.join(get_state_dir(), "autotry.ini")
|
|
|
|
|
|
def list_presets(section=None):
|
|
config = ConfigParser.RawConfigParser()
|
|
|
|
data = []
|
|
if config.read([CONFIG_PATH]):
|
|
sections = [section] if section else config.sections()
|
|
for s in sections:
|
|
try:
|
|
data.extend(config.items(s))
|
|
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
|
pass
|
|
|
|
if not data:
|
|
print("No presets found")
|
|
|
|
for name, value in data:
|
|
print("%s: %s" % (name, value))
|
|
|
|
|
|
def edit_presets(section=None):
|
|
if 'EDITOR' not in os.environ:
|
|
print("error: must set the $EDITOR environment variable to use --edit-presets")
|
|
return
|
|
subprocess.call([os.environ['EDITOR'], CONFIG_PATH])
|
|
|
|
|
|
def load(name, section=None):
|
|
config = ConfigParser.RawConfigParser()
|
|
if not config.read([CONFIG_PATH]):
|
|
return
|
|
|
|
sections = [section] if section else config.sections()
|
|
for s in sections:
|
|
try:
|
|
return config.get(s, name), s
|
|
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
|
|
pass
|
|
return None, None
|
|
|
|
|
|
def save(section, name, data):
|
|
config = ConfigParser.RawConfigParser()
|
|
config.read([CONFIG_PATH])
|
|
|
|
if not config.has_section(section):
|
|
config.add_section(section)
|
|
|
|
config.set(section, name, data)
|
|
|
|
with open(CONFIG_PATH, "w") as f:
|
|
config.write(f)
|
|
|
|
print('preset saved, run with: --preset={}'.format(name))
|