Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -874,39 +874,63 @@ class CachePurge(base.CommandBase):
|
|||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"-s", "--service", action="append", metavar="JID", dest="services",
|
||||
"-s",
|
||||
"--service",
|
||||
action="append",
|
||||
metavar="JID",
|
||||
dest="services",
|
||||
help="purge items only for these services. If not specified, items from ALL "
|
||||
"services will be purged. May be used several times."
|
||||
"services will be purged. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-n", "--node", action="append", dest="nodes",
|
||||
"-n",
|
||||
"--node",
|
||||
action="append",
|
||||
dest="nodes",
|
||||
help="purge items only for these nodes. If not specified, items from ALL "
|
||||
"nodes will be purged. May be used several times."
|
||||
"nodes will be purged. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-p", "--profile", action="append", dest="profiles",
|
||||
"-p",
|
||||
"--profile",
|
||||
action="append",
|
||||
dest="profiles",
|
||||
help="purge items only for these profiles. If not specified, items from ALL "
|
||||
"profiles will be purged. May be used several times."
|
||||
"profiles will be purged. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-b", "--updated-before", type=base.date_decoder, metavar="TIME_PATTERN",
|
||||
help="purge items which have been last updated before given time."
|
||||
"-b",
|
||||
"--updated-before",
|
||||
type=base.date_decoder,
|
||||
metavar="TIME_PATTERN",
|
||||
help="purge items which have been last updated before given time.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-C", "--created-before", type=base.date_decoder, metavar="TIME_PATTERN",
|
||||
help="purge items which have been last created before given time."
|
||||
"-C",
|
||||
"--created-before",
|
||||
type=base.date_decoder,
|
||||
metavar="TIME_PATTERN",
|
||||
help="purge items which have been last created before given time.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-t", "--type", action="append", dest="types",
|
||||
help="purge items flagged with TYPE. May be used several times."
|
||||
"-t",
|
||||
"--type",
|
||||
action="append",
|
||||
dest="types",
|
||||
help="purge items flagged with TYPE. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-S", "--subtype", action="append", dest="subtypes",
|
||||
help="purge items flagged with SUBTYPE. May be used several times."
|
||||
"-S",
|
||||
"--subtype",
|
||||
action="append",
|
||||
dest="subtypes",
|
||||
help="purge items flagged with SUBTYPE. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-f", "--force", action="store_true",
|
||||
help=_("purge items without confirmation")
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help=_("purge items without confirmation"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -916,22 +940,23 @@ class CachePurge(base.CommandBase):
|
|||
"Are you sure to purge items from cache? You'll have to bypass cache "
|
||||
"or resynchronise nodes to access deleted items again."
|
||||
),
|
||||
_("Items purgins has been cancelled.")
|
||||
_("Items purgins has been cancelled."),
|
||||
)
|
||||
purge_data = {}
|
||||
for key in (
|
||||
"services", "nodes", "profiles", "updated_before", "created_before",
|
||||
"types", "subtypes"
|
||||
"services",
|
||||
"nodes",
|
||||
"profiles",
|
||||
"updated_before",
|
||||
"created_before",
|
||||
"types",
|
||||
"subtypes",
|
||||
):
|
||||
value = getattr(self.args, key)
|
||||
if value is not None:
|
||||
purge_data[key] = value
|
||||
try:
|
||||
await self.host.bridge.ps_cache_purge(
|
||||
data_format.serialise(
|
||||
purge_data
|
||||
)
|
||||
)
|
||||
await self.host.bridge.ps_cache_purge(data_format.serialise(purge_data))
|
||||
except Exception as e:
|
||||
self.disp(f"Internal error: {e}", error=True)
|
||||
self.host.quit(C.EXIT_INTERNAL_ERROR)
|
||||
|
|
@ -951,8 +976,10 @@ class CacheReset(base.CommandBase):
|
|||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"-f", "--force", action="store_true",
|
||||
help=_("reset cache without confirmation")
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help=_("reset cache without confirmation"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -963,7 +990,7 @@ class CacheReset(base.CommandBase):
|
|||
"from it, then it will be progressively refilled as if it were new. "
|
||||
"This may be resources intensive."
|
||||
),
|
||||
_("Pubsub cache reset has been cancelled.")
|
||||
_("Pubsub cache reset has been cancelled."),
|
||||
)
|
||||
try:
|
||||
await self.host.bridge.ps_cache_reset()
|
||||
|
|
@ -995,32 +1022,55 @@ class CacheSearch(base.CommandBase):
|
|||
"-f", "--fts", help=_("Full-Text Search query"), metavar="FTS_QUERY"
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-p", "--profile", action="append", dest="profiles", metavar="PROFILE",
|
||||
help="search items only from these profiles. May be used several times."
|
||||
"-p",
|
||||
"--profile",
|
||||
action="append",
|
||||
dest="profiles",
|
||||
metavar="PROFILE",
|
||||
help="search items only from these profiles. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-s", "--service", action="append", dest="services", metavar="SERVICE",
|
||||
help="items must be from specified service. May be used several times."
|
||||
"-s",
|
||||
"--service",
|
||||
action="append",
|
||||
dest="services",
|
||||
metavar="SERVICE",
|
||||
help="items must be from specified service. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-n", "--node", action="append", dest="nodes", metavar="NODE",
|
||||
help="items must be in the specified node. May be used several times."
|
||||
"-n",
|
||||
"--node",
|
||||
action="append",
|
||||
dest="nodes",
|
||||
metavar="NODE",
|
||||
help="items must be in the specified node. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-t", "--type", action="append", dest="types", metavar="TYPE",
|
||||
help="items must be of specified type. May be used several times."
|
||||
"-t",
|
||||
"--type",
|
||||
action="append",
|
||||
dest="types",
|
||||
metavar="TYPE",
|
||||
help="items must be of specified type. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-S", "--subtype", action="append", dest="subtypes", metavar="SUBTYPE",
|
||||
help="items must be of specified subtype. May be used several times."
|
||||
"-S",
|
||||
"--subtype",
|
||||
action="append",
|
||||
dest="subtypes",
|
||||
metavar="SUBTYPE",
|
||||
help="items must be of specified subtype. May be used several times.",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-P", "--payload", action="store_true", help=_("include item XML payload")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-o", "--order-by", action="append", nargs="+",
|
||||
"-o",
|
||||
"--order-by",
|
||||
action="append",
|
||||
nargs="+",
|
||||
metavar=("ORDER", "[FIELD] [DIRECTION]"),
|
||||
help=_("how items must be ordered. May be used several times.")
|
||||
help=_("how items must be ordered. May be used several times."),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-l", "--limit", type=int, help=_("maximum number of items to return")
|
||||
|
|
@ -1075,10 +1125,12 @@ class CacheSearch(base.CommandBase):
|
|||
elif len(args) == 2:
|
||||
path, direction = args
|
||||
else:
|
||||
self.parser.error(_(
|
||||
"You can't specify more that 2 arguments for a field in "
|
||||
"--order-by"
|
||||
))
|
||||
self.parser.error(
|
||||
_(
|
||||
"You can't specify more that 2 arguments for a field in "
|
||||
"--order-by"
|
||||
)
|
||||
)
|
||||
try:
|
||||
path = json.loads(path)
|
||||
except json.JSONDecodeError:
|
||||
|
|
@ -1087,17 +1139,15 @@ class CacheSearch(base.CommandBase):
|
|||
"path": path,
|
||||
}
|
||||
else:
|
||||
order_query = {
|
||||
"order": order
|
||||
}
|
||||
order_query = {"order": order}
|
||||
if not args:
|
||||
direction = "asc"
|
||||
elif len(args) == 1:
|
||||
direction = args[0]
|
||||
else:
|
||||
self.parser.error(_(
|
||||
"there are too many arguments in --order-by option"
|
||||
))
|
||||
self.parser.error(
|
||||
_("there are too many arguments in --order-by option")
|
||||
)
|
||||
if direction.lower() not in ("asc", "desc"):
|
||||
self.parser.error(_("invalid --order-by direction: {direction!r}"))
|
||||
order_query["direction"] = direction
|
||||
|
|
@ -1118,10 +1168,14 @@ class CacheSearch(base.CommandBase):
|
|||
|
||||
# handling of TP(<time pattern>)
|
||||
if operator in (">", "gt", "<", "le", "between"):
|
||||
|
||||
def datetime_sub(match):
|
||||
return str(date_utils.date_parse_ext(
|
||||
match.group(1), default_tz=date_utils.TZ_LOCAL
|
||||
))
|
||||
return str(
|
||||
date_utils.date_parse_ext(
|
||||
match.group(1), default_tz=date_utils.TZ_LOCAL
|
||||
)
|
||||
)
|
||||
|
||||
value = re.sub(r"\bTP\(([^)]+)\)", datetime_sub, value)
|
||||
|
||||
try:
|
||||
|
|
@ -1134,11 +1188,7 @@ class CacheSearch(base.CommandBase):
|
|||
if not isinstance(value, list):
|
||||
value = [value]
|
||||
|
||||
parsed.append({
|
||||
"path": path,
|
||||
"op": operator,
|
||||
"value": value
|
||||
})
|
||||
parsed.append({"path": path, "op": operator, "value": value})
|
||||
|
||||
query["parsed"] = parsed
|
||||
|
||||
|
|
@ -1148,9 +1198,7 @@ class CacheSearch(base.CommandBase):
|
|||
self.args.keys.append("item_payload")
|
||||
try:
|
||||
found_items = data_format.deserialise(
|
||||
await self.host.bridge.ps_cache_search(
|
||||
data_format.serialise(query)
|
||||
),
|
||||
await self.host.bridge.ps_cache_search(data_format.serialise(query)),
|
||||
type_check=list,
|
||||
)
|
||||
except BridgeException as e:
|
||||
|
|
@ -1162,7 +1210,7 @@ class CacheSearch(base.CommandBase):
|
|||
else:
|
||||
if self.args.keys:
|
||||
found_items = [
|
||||
{k: v for k,v in item.items() if k in self.args.keys}
|
||||
{k: v for k, v in item.items() if k in self.args.keys}
|
||||
for item in found_items
|
||||
]
|
||||
await self.output(found_items)
|
||||
|
|
@ -1228,19 +1276,19 @@ class Set(base.CommandBase):
|
|||
"-e",
|
||||
"--encrypt",
|
||||
action="store_true",
|
||||
help=_("end-to-end encrypt the blog item")
|
||||
help=_("end-to-end encrypt the blog item"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"--encrypt-for",
|
||||
metavar="JID",
|
||||
action="append",
|
||||
help=_("encrypt a single item for")
|
||||
help=_("encrypt a single item for"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-X",
|
||||
"--sign",
|
||||
action="store_true",
|
||||
help=_("cryptographically sign the blog post")
|
||||
help=_("cryptographically sign the blog post"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"item",
|
||||
|
|
@ -1363,8 +1411,10 @@ class Delete(base.CommandBase):
|
|||
"-f", "--force", action="store_true", help=_("delete without confirmation")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"--no-notification", dest="notify", action="store_false",
|
||||
help=_("do not send notification (not recommended)")
|
||||
"--no-notification",
|
||||
dest="notify",
|
||||
action="store_false",
|
||||
help=_("do not send notification (not recommended)"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -1410,19 +1460,19 @@ class Edit(base.CommandBase, common.BaseEdit):
|
|||
"-e",
|
||||
"--encrypt",
|
||||
action="store_true",
|
||||
help=_("end-to-end encrypt the blog item")
|
||||
help=_("end-to-end encrypt the blog item"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"--encrypt-for",
|
||||
metavar="JID",
|
||||
action="append",
|
||||
help=_("encrypt a single item for")
|
||||
help=_("encrypt a single item for"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-X",
|
||||
"--sign",
|
||||
action="store_true",
|
||||
help=_("cryptographically sign the blog post")
|
||||
help=_("cryptographically sign the blog post"),
|
||||
)
|
||||
|
||||
async def publish(self, content):
|
||||
|
|
@ -1544,7 +1594,8 @@ class Subscribe(base.CommandBase):
|
|||
except KeyError:
|
||||
self.disp(
|
||||
"Pubsub Public Subscription plugin is not loaded, can't use --public "
|
||||
"option, subscription stopped", error=True
|
||||
"option, subscription stopped",
|
||||
error=True,
|
||||
)
|
||||
self.host.quit(C.EXIT_MISSING_FEATURE)
|
||||
else:
|
||||
|
|
@ -1628,7 +1679,7 @@ class Subscriptions(base.CommandBase):
|
|||
self.args.node,
|
||||
self.profile,
|
||||
),
|
||||
type_check=list
|
||||
type_check=list,
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(_("can't retrieve subscriptions: {e}").format(e=e), error=True)
|
||||
|
|
@ -1685,10 +1736,7 @@ class Reference(base.CommandBase):
|
|||
choices=("data", "mention"),
|
||||
help=_("type of reference to send (DEFAULT: mention)"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"recipient",
|
||||
help=_("recipient of the reference")
|
||||
)
|
||||
self.parser.add_argument("recipient", help=_("recipient of the reference"))
|
||||
|
||||
async def start(self):
|
||||
service = self.args.service or await self.host.get_profile_jid()
|
||||
|
|
@ -2496,7 +2544,7 @@ class AttachmentGet(base.CommandBase):
|
|||
help=_(
|
||||
"get attached data published only by those JIDs (DEFAULT: get all "
|
||||
"attached data)"
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -2535,7 +2583,7 @@ class AttachmentSet(base.CommandBase):
|
|||
help=_(
|
||||
"replace previous versions of attachments (DEFAULT: update previous "
|
||||
"version)"
|
||||
)
|
||||
),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-N",
|
||||
|
|
@ -2543,21 +2591,21 @@ class AttachmentSet(base.CommandBase):
|
|||
metavar="BOOLEAN",
|
||||
nargs="?",
|
||||
default="keep",
|
||||
help=_("mark item as (un)noticed (DEFAULT: keep current value))")
|
||||
help=_("mark item as (un)noticed (DEFAULT: keep current value))"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-r",
|
||||
"--reactions",
|
||||
# FIXME: to be replaced by "extend" when we stop supporting python 3.7
|
||||
action="append",
|
||||
help=_("emojis to add to react to an item")
|
||||
help=_("emojis to add to react to an item"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-R",
|
||||
"--reactions-remove",
|
||||
# FIXME: to be replaced by "extend" when we stop supporting python 3.7
|
||||
action="append",
|
||||
help=_("emojis to remove from reactions to an item")
|
||||
help=_("emojis to remove from reactions to an item"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -2565,7 +2613,7 @@ class AttachmentSet(base.CommandBase):
|
|||
"service": self.args.service,
|
||||
"node": self.args.node,
|
||||
"id": self.args.item,
|
||||
"extra": {}
|
||||
"extra": {},
|
||||
}
|
||||
operation = "replace" if self.args.replace else "update"
|
||||
if self.args.noticed != "keep":
|
||||
|
|
@ -2574,16 +2622,13 @@ class AttachmentSet(base.CommandBase):
|
|||
attachments_data["extra"]["noticed"] = C.bool(self.args.noticed)
|
||||
|
||||
if self.args.reactions or self.args.reactions_remove:
|
||||
reactions = attachments_data["extra"]["reactions"] = {
|
||||
"operation": operation
|
||||
}
|
||||
reactions = attachments_data["extra"]["reactions"] = {"operation": operation}
|
||||
if self.args.replace:
|
||||
reactions["reactions"] = self.args.reactions
|
||||
else:
|
||||
reactions["add"] = self.args.reactions
|
||||
reactions["remove"] = self.args.reactions_remove
|
||||
|
||||
|
||||
if not attachments_data["extra"]:
|
||||
self.parser.error(_("At leat one attachment must be specified."))
|
||||
|
||||
|
|
@ -2633,7 +2678,7 @@ class SignatureSign(base.CommandBase):
|
|||
"extra": {
|
||||
# we set None to use profile's bare JID
|
||||
"signature": {"signer": None}
|
||||
}
|
||||
},
|
||||
}
|
||||
try:
|
||||
await self.host.bridge.ps_attachments_set(
|
||||
|
|
@ -2660,11 +2705,7 @@ class SignatureCheck(base.CommandBase):
|
|||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"signature",
|
||||
metavar="JSON",
|
||||
help=_("signature data")
|
||||
)
|
||||
self.parser.add_argument("signature", metavar="JSON", help=_("signature data"))
|
||||
|
||||
async def start(self):
|
||||
try:
|
||||
|
|
@ -2690,9 +2731,7 @@ class Signature(base.CommandBase):
|
|||
)
|
||||
|
||||
def __init__(self, host):
|
||||
super().__init__(
|
||||
host, "signature", use_profile=False, help=_("items signatures")
|
||||
)
|
||||
super().__init__(host, "signature", use_profile=False, help=_("items signatures"))
|
||||
|
||||
|
||||
class SecretShare(base.CommandBase):
|
||||
|
|
@ -2707,11 +2746,16 @@ class SecretShare(base.CommandBase):
|
|||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"-k", "--key", metavar="ID", dest="secret_ids", action="append", default=[],
|
||||
"-k",
|
||||
"--key",
|
||||
metavar="ID",
|
||||
dest="secret_ids",
|
||||
action="append",
|
||||
default=[],
|
||||
help=_(
|
||||
"only share secrets with those IDs (default: share all secrets of the "
|
||||
"node)"
|
||||
)
|
||||
),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"recipient", metavar="JID", help=_("entity who must get the shared secret")
|
||||
|
|
@ -2745,15 +2789,18 @@ class SecretRevoke(base.CommandBase):
|
|||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument("secret_id", help=_("ID of the secrets to revoke"))
|
||||
self.parser.add_argument(
|
||||
"secret_id", help=_("ID of the secrets to revoke")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-r", "--recipient", dest="recipients", metavar="JID", action="append",
|
||||
default=[], help=_(
|
||||
"-r",
|
||||
"--recipient",
|
||||
dest="recipients",
|
||||
metavar="JID",
|
||||
action="append",
|
||||
default=[],
|
||||
help=_(
|
||||
"entity who must get the revocation notification (default: send to all "
|
||||
"entities known to have the shared secret)"
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -2785,11 +2832,16 @@ class SecretRotate(base.CommandBase):
|
|||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"-r", "--recipient", dest="recipients", metavar="JID", action="append",
|
||||
default=[], help=_(
|
||||
"-r",
|
||||
"--recipient",
|
||||
dest="recipients",
|
||||
metavar="JID",
|
||||
action="append",
|
||||
default=[],
|
||||
help=_(
|
||||
"entity who must get the revocation and shared secret notifications "
|
||||
"(default: send to all entities known to have the shared secret)"
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
|
|
@ -2817,7 +2869,7 @@ class SecretList(base.CommandBase):
|
|||
use_verbose=True,
|
||||
pubsub_flags={C.NODE},
|
||||
help=_("list known secrets for a pubsub node"),
|
||||
use_output=C.OUTPUT_LIST_DICT
|
||||
use_output=C.OUTPUT_LIST_DICT,
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
|
|
@ -2825,11 +2877,14 @@ class SecretList(base.CommandBase):
|
|||
|
||||
async def start(self):
|
||||
try:
|
||||
secrets = data_format.deserialise(await self.host.bridge.ps_secrets_list(
|
||||
self.args.service,
|
||||
self.args.node,
|
||||
self.profile,
|
||||
), type_check=list)
|
||||
secrets = data_format.deserialise(
|
||||
await self.host.bridge.ps_secrets_list(
|
||||
self.args.service,
|
||||
self.args.node,
|
||||
self.profile,
|
||||
),
|
||||
type_check=list,
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"can't list node secrets: {e}", error=True)
|
||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
||||
|
|
|
|||
Loading…
Reference in a new issue