[dconf: 2/6] bin: Sort output of list and dump commands
- From: Daniel Playfair Cal <danielplayfaircal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf: 2/6] bin: Sort output of list and dump commands
- Date: Thu, 15 Nov 2018 22:17:02 +0000 (UTC)
commit 25aca2e7c3c13b298290148cfd55ab426f1c68d4
Author: Tomasz MiÄ…sko <tomasz miasko gmail com>
Date: Sat Nov 10 00:00:00 2018 +0000
bin: Sort output of list and dump commands
bin/dconf-dump.vala | 13 ++++++++++++-
bin/dconf.vala | 5 ++++-
tests/test-dconf.py | 17 +++++------------
3 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/bin/dconf-dump.vala b/bin/dconf-dump.vala
index 135b230..d63e3eb 100644
--- a/bin/dconf-dump.vala
+++ b/bin/dconf-dump.vala
@@ -8,7 +8,18 @@ void add_to_keyfile (KeyFile kf, DConf.Client client, string topdir, string? rel
this_group = "/";
}
- foreach (var item in client.list (this_dir)) {
+ var items = client.list (this_dir);
+ GLib.qsort_with_data<string> (items, sizeof (string), (a, b) => {
+ var a_dir = a.has_suffix ("/");
+ var b_dir = b.has_suffix ("/");
+ if (a_dir != b_dir) {
+ return (int) a_dir - (int) b_dir;
+ } else {
+ return GLib.strcmp (a, b);
+ }
+ });
+
+ foreach (var item in items) {
if (item.has_suffix ("/")) {
add_to_keyfile (kf, client, topdir, rel + item);
} else {
diff --git a/bin/dconf.vala b/bin/dconf.vala
index 349e1ea..8b0f211 100644
--- a/bin/dconf.vala
+++ b/bin/dconf.vala
@@ -186,7 +186,10 @@ void dconf_list (string?[] args) throws Error {
DConf.verify_dir (dir);
- foreach (var item in client.list (dir)) {
+ var items = client.list (dir);
+ GLib.qsort_with_data<string> (items, sizeof (string), (a, b) => GLib.strcmp (a, b));
+
+ foreach (var item in items) {
print ("%s\n", item);
}
}
diff --git a/tests/test-dconf.py b/tests/test-dconf.py
index 6e804d7..bbb76f7 100755
--- a/tests/test-dconf.py
+++ b/tests/test-dconf.py
@@ -70,10 +70,7 @@ def dconf_write(key, value):
def dconf_list(key):
- lines = dconf('list', key).stdout.splitlines()
- # FIXME: Change dconf to produce sorted output.
- lines.sort()
- return lines
+ return dconf('list', key).stdout.splitlines()
def dconf_watch(path):
@@ -281,23 +278,19 @@ class DBusTest(unittest.TestCase):
"""Checks that output produced with dump can be used with load and
vice versa.
"""
- # FIXME: This test depends on:
- # * order of groups
- # * order of items within groups
- # Change dconf to produce output in sorted order.
-
keyfile = dedent('''\
[/]
password='secret'
+ [org/editor]
+ window-fullscreen=true
+ window-size=(1024, 768)
+
[org/editor/language/c-sharp]
tab-width=8
[org/editor/language/c]
tab-width=2
-
- [org/editor]
- window-size=(1280, 977)
''')
# Load and dump is identity.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]