Skip to content

Commit 92ec0f3

Browse files
committed
Bug 1244996 - add a script to manage a user's settings
1 parent 939604e commit 92ec0f3

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

scripts/user-prefs.pl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/perl -w
2+
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
#
7+
# This Source Code Form is "Incompatible With Secondary Licenses", as
8+
# defined by the Mozilla Public License, v. 2.0.
9+
10+
use strict;
11+
use 5.10.1;
12+
13+
use FindBin qw( $RealBin );
14+
use lib ("$RealBin/..", "$RealBin/../lib");
15+
16+
use Bugzilla;
17+
use Bugzilla::Constants;
18+
use Bugzilla::User;
19+
use Bugzilla::User::APIKey;
20+
21+
Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
22+
23+
my ($login, $action, $param, $value) = @ARGV;
24+
($login && $action && $action =~ /^(get|set)$/)
25+
or die "syntax: $0 <bugzilla-login> <get|set> [param] [value]\n";
26+
27+
my $user = Bugzilla::User->check({ name => $login });
28+
my $settings = $user->settings;
29+
30+
if ($action eq 'get') {
31+
if ($param eq '') {
32+
foreach my $name (sort keys %$settings) {
33+
printf "%s=%s\n", $name, $settings->{$name}->{value};
34+
}
35+
} elsif (exists $settings->{$param}) {
36+
say $settings->{$param}->{value};
37+
} else {
38+
die "Invalid parameter name: $param\n";
39+
}
40+
} else {
41+
if ($param eq '') {
42+
die "Parameter name required\n";
43+
} elsif (!exists $settings->{$param}) {
44+
die "Invalid parameter name: $param\n";
45+
} elsif (!defined($value) || $value eq '') {
46+
die "Missing parameter value\n";
47+
} else {
48+
my $setting = $settings->{$param};
49+
# not using validate_value here so we can print out a list of the legal values
50+
my $legal_values = $setting->legal_values;
51+
if (! grep { $value eq $_ } @$legal_values) {
52+
die "Invalid value '$value' for param $param.\nAccepted values: " . join(' ', @$legal_values) . "\n";
53+
}
54+
$setting->set($value);
55+
say "'$param' set to '$value'";
56+
}
57+
}

0 commit comments

Comments
 (0)