mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 1460912 - [testing/profiles] Add a ./profile rm subcommand for removing prefs from a profile r=rwood
Usage is: ./profile rm <profile> [<file>] The file is a list of prefs, one per line, to remove. The file defaults to stdin, so the culmination of the last three commits is the ability to do: ./profile diff reftest common -f names -k same | ./profile rm reftest The above command will remove from the reftest profile, the prefs that are identical in both reftest and common. This method is quicker and less error prone than doing it manually (which was how I was doing this previously). MozReview-Commit-ID: Je0JjFXoora --HG-- extra : rebase_source : 38dae2dcdc3986910cfcd5091f7fc968bf8cc22a
This commit is contained in:
parent
ae47cd1150
commit
862e0f0951
@ -178,12 +178,7 @@ def diff(a, b, fmt, limit_key):
|
|||||||
return format_diff(results, fmt, limit_key)
|
return format_diff(results, fmt, limit_key)
|
||||||
|
|
||||||
|
|
||||||
def sort_file(path):
|
def read_with_comments(path):
|
||||||
"""Sort the given pref file alphabetically, preserving preceding comments
|
|
||||||
that start with '//'.
|
|
||||||
|
|
||||||
:param path: Path to the preference file to sort.
|
|
||||||
"""
|
|
||||||
with open(path, 'r') as fh:
|
with open(path, 'r') as fh:
|
||||||
lines = fh.readlines()
|
lines = fh.readlines()
|
||||||
|
|
||||||
@ -204,12 +199,21 @@ def sort_file(path):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
result.append([line])
|
result.append([line])
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def sort_file(path):
|
||||||
|
"""Sort the given pref file alphabetically, preserving preceding comments
|
||||||
|
that start with '//'.
|
||||||
|
|
||||||
|
:param path: Path to the preference file to sort.
|
||||||
|
"""
|
||||||
|
result = read_with_comments(path)
|
||||||
result = sorted(result, key=lambda x: x[-1])
|
result = sorted(result, key=lambda x: x[-1])
|
||||||
result = chain(*result)
|
result = chain(*result)
|
||||||
|
|
||||||
with open(path, 'w') as fh:
|
with open(path, 'w') as fh:
|
||||||
fh.write('\n'.join(result))
|
fh.write('\n'.join(result) + '\n')
|
||||||
|
|
||||||
|
|
||||||
def sort(profile):
|
def sort(profile):
|
||||||
@ -236,6 +240,28 @@ def show(suite):
|
|||||||
print("{}: {}".format(k, repr(v)))
|
print("{}: {}".format(k, repr(v)))
|
||||||
|
|
||||||
|
|
||||||
|
def rm(profile, pref_file):
|
||||||
|
if pref_file == '-':
|
||||||
|
lines = sys.stdin.readlines()
|
||||||
|
else:
|
||||||
|
with open(pref_file, 'r') as fh:
|
||||||
|
lines = fh.readlines()
|
||||||
|
|
||||||
|
lines = [l.strip() for l in lines if l.strip()]
|
||||||
|
if not lines:
|
||||||
|
return
|
||||||
|
|
||||||
|
def filter_line(content):
|
||||||
|
return not any(line in content[-1] for line in lines)
|
||||||
|
|
||||||
|
path = os.path.join(here, profile, 'user.js')
|
||||||
|
contents = read_with_comments(path)
|
||||||
|
contents = filter(filter_line, contents)
|
||||||
|
contents = chain(*contents)
|
||||||
|
with open(path, 'w') as fh:
|
||||||
|
fh.write('\n'.join(contents))
|
||||||
|
|
||||||
|
|
||||||
def cli(args=sys.argv[1:]):
|
def cli(args=sys.argv[1:]):
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
@ -261,6 +287,12 @@ def cli(args=sys.argv[1:]):
|
|||||||
show_parser.add_argument('suite', help="Name of suite to show arguments for.")
|
show_parser.add_argument('suite', help="Name of suite to show arguments for.")
|
||||||
show_parser.set_defaults(func=show)
|
show_parser.set_defaults(func=show)
|
||||||
|
|
||||||
|
rm_parser = subparsers.add_parser('rm')
|
||||||
|
rm_parser.add_argument('profile', help="Name of the profile to remove prefs from.")
|
||||||
|
rm_parser.add_argument('--pref-file', default='-', help="File containing a list of pref "
|
||||||
|
"substrings to delete (default: stdin)")
|
||||||
|
rm_parser.set_defaults(func=rm)
|
||||||
|
|
||||||
args = vars(parser.parse_args(args))
|
args = vars(parser.parse_args(args))
|
||||||
func = args.pop('func')
|
func = args.pop('func')
|
||||||
func(**args)
|
func(**args)
|
||||||
|
Loading…
Reference in New Issue
Block a user