mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 17:40:40 -05:00
tools/get-state: Change to use argparse
This will make adding more arguments easier. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2448>
This commit is contained in:
parent
4e3932c7ac
commit
e883046c5f
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
import enum
|
import enum
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -12,29 +13,17 @@ class Source(enum.Enum):
|
|||||||
FILE = 2
|
FILE = 2
|
||||||
|
|
||||||
|
|
||||||
def print_usage():
|
parser = argparse.ArgumentParser(description='Get display state')
|
||||||
print(f'Usage: {sys.argv[0]} [--help] [FILE]')
|
parser.add_argument('file', metavar='FILE', type=str, nargs='?',
|
||||||
|
help='Read the output from gdbus call instead of calling D-Bus')
|
||||||
|
|
||||||
def print_help():
|
args = parser.parse_args()
|
||||||
print(f'Without any argument this command queries the GNOME display server '
|
|
||||||
'using D-Bus and pretty prints the result')
|
|
||||||
print()
|
|
||||||
print(f' --help Show this help screen')
|
|
||||||
print(f' FILE Read the output from gdbus call instead of calling D-Bus')
|
|
||||||
|
|
||||||
|
if args.file:
|
||||||
if len(sys.argv) > 2:
|
source = Source.FILE
|
||||||
print_usage()
|
path = args.file
|
||||||
sys.exit(1)
|
|
||||||
elif len(sys.argv) == 1:
|
|
||||||
source = Source.DBUS
|
|
||||||
elif sys.argv[1] == '--help':
|
|
||||||
print_usage()
|
|
||||||
print_help()
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
else:
|
||||||
source = Source.FILE
|
source = Source.DBUS
|
||||||
path = sys.argv[1]
|
|
||||||
|
|
||||||
type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})'
|
type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})'
|
||||||
variant_type = GLib.VariantType.new(type_signature)
|
variant_type = GLib.VariantType.new(type_signature)
|
||||||
|
Loading…
Reference in New Issue
Block a user