improvements to configure
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Add an account to GNOME Online Accounts, the way Settings does.
|
||||
"""Add or remove an account in GNOME Online Accounts, the way Settings does.
|
||||
|
||||
Settings adds accounts by calling AddAccount on the Online Accounts service,
|
||||
which saves the account and keeps its password in the GNOME keyring. This
|
||||
@@ -9,6 +9,7 @@ so its password doesn't show up in the process list.
|
||||
Usage:
|
||||
goa-account exists <provider> <presentation-identity>
|
||||
goa-account add < account.json
|
||||
goa-account remove <provider> <presentation-identity>
|
||||
|
||||
account.json:
|
||||
{"provider": "owncloud", "identity": "...", "presentation_identity": "...",
|
||||
@@ -36,16 +37,20 @@ def accounts(bus):
|
||||
(objects,) = call(bus, "/org/gnome/OnlineAccounts",
|
||||
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects",
|
||||
None, "(a{oa{sa{sv}}})")
|
||||
for interfaces in objects.values():
|
||||
for path, interfaces in objects.items():
|
||||
account = interfaces.get("org.gnome.OnlineAccounts.Account")
|
||||
if account:
|
||||
yield account
|
||||
yield path, account
|
||||
|
||||
|
||||
def find(bus, provider, presentation_identity):
|
||||
return [path for path, account in accounts(bus)
|
||||
if account.get("ProviderType") == provider
|
||||
and account.get("PresentationIdentity") == presentation_identity]
|
||||
|
||||
|
||||
def exists(bus, provider, presentation_identity):
|
||||
return any(account.get("ProviderType") == provider
|
||||
and account.get("PresentationIdentity") == presentation_identity
|
||||
for account in accounts(bus))
|
||||
return bool(find(bus, provider, presentation_identity))
|
||||
|
||||
|
||||
def add(bus, account):
|
||||
@@ -58,6 +63,11 @@ def add(bus, account):
|
||||
"org.gnome.OnlineAccounts.Manager", "AddAccount", parameters, "(o)")
|
||||
|
||||
|
||||
def remove(bus, provider, presentation_identity):
|
||||
for path in find(bus, provider, presentation_identity):
|
||||
call(bus, path, "org.gnome.OnlineAccounts.Account", "Remove", None, "()")
|
||||
|
||||
|
||||
def main():
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "exists":
|
||||
@@ -68,6 +78,9 @@ def main():
|
||||
return 0
|
||||
add(bus, account)
|
||||
return 0
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "remove":
|
||||
remove(bus, sys.argv[2], sys.argv[3])
|
||||
return 0
|
||||
print(__doc__.strip().split("\n\n")[2], file=sys.stderr)
|
||||
return 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user