more work on configure

This commit is contained in:
2026-10-30 11:45:16 -06:00
parent c0df6537ca
commit 7e08a048ca
2 changed files with 59 additions and 7 deletions
+33
View File
@@ -13,6 +13,8 @@ Usage:
goa-account add < account.json
goa-account update <provider> <presentation-identity> < credentials.json
goa-account check <provider> <presentation-identity>
goa-account disabled <provider> <presentation-identity>
goa-account enable <provider> <presentation-identity>
goa-account remove <provider> <presentation-identity>
account.json:
@@ -22,6 +24,8 @@ account.json:
credentials.json is the account's "credentials", e.g. {"password": "..."}.
check signs in with what's saved, and fails if the server says no. update
exits with 3 if it saved the password but the server didn't accept it.
disabled prints the features CoreDesktop uses that are turned off in Settings,
e.g. "Calendar, Files", and enable turns them back on.
"""
import json
@@ -40,6 +44,10 @@ BUS_NAME = "org.gnome.OnlineAccounts"
SCHEMA = Secret.Schema.new("org.gnome.OnlineAccounts", Secret.SchemaFlags.DONT_MATCH_NAME,
{"goa-identity": Secret.SchemaAttributeType.STRING})
# The features CoreDesktop sets each kind of account up for. Every account has
# a <feature>Disabled property for each feature, used or not.
FEATURES = {"owncloud": ["Calendar", "Contacts", "Files"], "imap_smtp": ["Mail"]}
def call(bus, path, interface, method, parameters, reply_type):
return bus.call_sync(BUS_NAME, path, interface, method, parameters,
@@ -127,6 +135,25 @@ def check(bus, provider, presentation_identity):
ensure_credentials(bus, path)
def disabled(bus, provider, presentation_identity):
found = find_accounts(bus, provider, presentation_identity)
if not found:
raise LookupError(f"there's no {provider} account for {presentation_identity}")
return [feature for feature in FEATURES.get(provider, [])
if any(account.get(f"{feature}Disabled") for _, account in found)]
# Settings turns a feature off or on by setting its property
def enable(bus, provider, presentation_identity):
for path, account in find_accounts(bus, provider, presentation_identity):
for feature in FEATURES.get(provider, []):
if account.get(f"{feature}Disabled"):
call(bus, path, "org.freedesktop.DBus.Properties", "Set",
GLib.Variant("(ssv)", ("org.gnome.OnlineAccounts.Account",
f"{feature}Disabled", GLib.Variant("b", False))),
"()")
def remove(bus, provider, presentation_identity):
for path in find(bus, provider, presentation_identity):
call(bus, path, "org.gnome.OnlineAccounts.Account", "Remove", None, "()")
@@ -147,6 +174,12 @@ def main():
if len(sys.argv) == 4 and sys.argv[1] == "check":
check(bus, sys.argv[2], sys.argv[3])
return 0
if len(sys.argv) == 4 and sys.argv[1] == "disabled":
print(", ".join(disabled(bus, sys.argv[2], sys.argv[3])))
return 0
if len(sys.argv) == 4 and sys.argv[1] == "enable":
enable(bus, sys.argv[2], sys.argv[3])
return 0
if len(sys.argv) == 4 and sys.argv[1] == "remove":
remove(bus, sys.argv[2], sys.argv[3])
return 0