mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 12:32:05 +00: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
|
||||
|
||||
import argparse
|
||||
import enum
|
||||
import subprocess
|
||||
import sys
|
||||
@ -12,29 +13,17 @@ class Source(enum.Enum):
|
||||
FILE = 2
|
||||
|
||||
|
||||
def print_usage():
|
||||
print(f'Usage: {sys.argv[0]} [--help] [FILE]')
|
||||
parser = argparse.ArgumentParser(description='Get display state')
|
||||
parser.add_argument('file', metavar='FILE', type=str, nargs='?',
|
||||
help='Read the output from gdbus call instead of calling D-Bus')
|
||||
|
||||
def print_help():
|
||||
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')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
elif len(sys.argv) == 1:
|
||||
source = Source.DBUS
|
||||
elif sys.argv[1] == '--help':
|
||||
print_usage()
|
||||
print_help()
|
||||
sys.exit(0)
|
||||
if args.file:
|
||||
source = Source.FILE
|
||||
path = args.file
|
||||
else:
|
||||
source = Source.FILE
|
||||
path = sys.argv[1]
|
||||
source = Source.DBUS
|
||||
|
||||
type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})'
|
||||
variant_type = GLib.VariantType.new(type_signature)
|
||||
|
Loading…
Reference in New Issue
Block a user