# 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 andis 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 # noqa
'''
"""This script can be used to:
1) Show all preferences for a given suite 2) Diff preferences between two suites or profiles 3) Sort preference files alphabetically for a given profile
To use, either make sure that `mach` is on your $PATH, or run: $ ./mach python testing/profiles/profile <args>
For more details run: $ ./profile -- --help
"""
import json
import os
import sys from argparse import ArgumentParser from itertools import chain
from mozprofile import Profile from mozprofile.prefs import Preferences
def read_prefs(profile, pref_files=None): """Read and return all preferences set in the given profile.
:param profile: Profile name relative to this `here`. :returns: A dictionary of preferences set in the profile. """
pref_files = pref_files or Profile.preference_file_names
prefs = {} for name in pref_files:
path = os.path.join(here, profile, name) if not os.path.isfile(path):
continue
def get_profiles(key): """Return a list of profile names for key.""" withopen(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. """
prefs = {} for profile in get_profiles(key):
prefs.update(read_prefs(profile))
return prefs
def format_diff(diff, fmt, limit_key): """Format a diff."""
indent = ' ' if limit_key:
diff = {limit_key: diff[limit_key]}
indent = ''
if fmt == 'json':
print(json.dumps(diff, sort_keys=True, indent=2))
return 0
lines = [] for key, prefs in sorted(diff.items()): if not limit_key:
lines.append("{}:".format(key))
for pref, valuein sorted(prefs.items()): context = {'pref': pref, 'value': repr(value)}
if isinstance(value, list): context['value_a'] = repr(value[0]) context['value_b'] = repr(value[1]) text = FORMAT_STRINGS[fmt][1].format(**context) else: text=FORMAT_STRINGS[fmt][0].format(**context)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.