-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgvariant
38 lines (34 loc) · 1.35 KB
/
gvariant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# GVariant arrays
#
# Copyright (C) 2021 Rodrigo Silva (MestreLion) <[email protected]>
# License: GPLv3 or later. See <http://www.gnu.org/licenses/gpl.html>
# See: https://developer.gnome.org/glib/stable/gvariant-text.html
# and https://developer.gnome.org/glib/stable/glib-GVariantType.html
gvariant_array() (
local op=$1 # Operation to perform: include, remove, clear/new, set
local itemtype=$2 # List item type: 's' for string, 'u' for uint32, etc
local curlist=$3 # Current list, as a string in GVariant format: '@as []'
local args
case "${op,,}" in
insert)
local item=$4 # Item to insert, unquoted
local where=$5 # Insert item 'before' or 'after' the following items
shift 5 # Remaining arguments are reference items for position
args=(array_insert "$itemtype" "$curlist" "$item" "$where" "$@");;
*)
shift 3 # Remaining arguments are list items
args=(array "$op" "$itemtype" "$curlist" "$@");;
esac
debugvar args
python3 -- "$(absdir "${BASH_SOURCE[0]}")"/gvariant.py "${args[@]}"
)
gvariant_quote() {
local value=$1
# shortcut for gvariant.py quote "$value"
python3 -c 'import sys; print(repr(sys.argv[1]))' "$value"
}
gvariant_unquote() {
local value=$1
# No shortcuts, let gvariant.py handle ast.literal_eval() exceptions
python3 -- "$(absdir "${BASH_SOURCE[0]}")"/gvariant.py unquote "$value"
}