Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -31,9 +31,13 @@ class Get(base.CommandBase):
|
|||
|
||||
def __init__(self, host):
|
||||
super().__init__(
|
||||
host, 'get', use_output=C.OUTPUT_DICT, use_verbose=True,
|
||||
extra_outputs = {"default": self.default_output},
|
||||
help=_('retrieve the roster entities'))
|
||||
host,
|
||||
"get",
|
||||
use_output=C.OUTPUT_DICT,
|
||||
use_verbose=True,
|
||||
extra_outputs={"default": self.default_output},
|
||||
help=_("retrieve the roster entities"),
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
|
|
@ -42,11 +46,11 @@ class Get(base.CommandBase):
|
|||
for contact_jid, contact_data in data.items():
|
||||
all_keys = list(contact_data.keys())
|
||||
keys_to_show = []
|
||||
name = contact_data.get('name', contact_jid.node)
|
||||
name = contact_data.get("name", contact_jid.node)
|
||||
|
||||
if self.verbosity >= 1:
|
||||
keys_to_show.append('groups')
|
||||
all_keys.remove('groups')
|
||||
keys_to_show.append("groups")
|
||||
all_keys.remove("groups")
|
||||
if self.verbosity >= 2:
|
||||
keys_to_show.extend(all_keys)
|
||||
|
||||
|
|
@ -58,9 +62,10 @@ class Get(base.CommandBase):
|
|||
value = contact_data[k]
|
||||
if value:
|
||||
if isinstance(value, list):
|
||||
value = ', '.join(value)
|
||||
self.disp(A.color(
|
||||
" ", C.A_SUBHEADER, f"{k}: ", A.RESET, str(value)))
|
||||
value = ", ".join(value)
|
||||
self.disp(
|
||||
A.color(" ", C.A_SUBHEADER, f"{k}: ", A.RESET, str(value))
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
try:
|
||||
|
|
@ -73,10 +78,10 @@ class Get(base.CommandBase):
|
|||
for contact_jid_s, data, groups in contacts:
|
||||
# FIXME: we have to convert string to bool here for historical reason
|
||||
# contacts_get format should be changed and serialised properly
|
||||
for key in ('from', 'to', 'ask'):
|
||||
for key in ("from", "to", "ask"):
|
||||
if key in data:
|
||||
data[key] = C.bool(data[key])
|
||||
data['groups'] = list(groups)
|
||||
data["groups"] = list(groups)
|
||||
contacts_dict[jid.JID(contact_jid_s)] = data
|
||||
|
||||
await self.output(contacts_dict)
|
||||
|
|
@ -86,19 +91,28 @@ class Get(base.CommandBase):
|
|||
class Set(base.CommandBase):
|
||||
|
||||
def __init__(self, host):
|
||||
super().__init__(host, 'set', help=_('set metadata for a roster entity'))
|
||||
super().__init__(host, "set", help=_("set metadata for a roster entity"))
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"-n", "--name", default="", help=_('name to use for this entity'))
|
||||
"-n", "--name", default="", help=_("name to use for this entity")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-g", "--group", dest='groups', action='append', metavar='GROUP', default=[],
|
||||
help=_('groups for this entity'))
|
||||
"-g",
|
||||
"--group",
|
||||
dest="groups",
|
||||
action="append",
|
||||
metavar="GROUP",
|
||||
default=[],
|
||||
help=_("groups for this entity"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-R", "--replace", action="store_true",
|
||||
help=_("replace all metadata instead of adding them"))
|
||||
self.parser.add_argument(
|
||||
"jid", help=_("jid of the roster entity"))
|
||||
"-R",
|
||||
"--replace",
|
||||
action="store_true",
|
||||
help=_("replace all metadata instead of adding them"),
|
||||
)
|
||||
self.parser.add_argument("jid", help=_("jid of the roster entity"))
|
||||
|
||||
async def start(self):
|
||||
|
||||
|
|
@ -108,17 +122,19 @@ class Set(base.CommandBase):
|
|||
else:
|
||||
try:
|
||||
entity_data = await self.host.bridge.contact_get(
|
||||
self.args.jid, self.host.profile)
|
||||
self.args.jid, self.host.profile
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"error while retrieving the contact: {e}", error=True)
|
||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
||||
name = self.args.name or entity_data[0].get('name') or ''
|
||||
name = self.args.name or entity_data[0].get("name") or ""
|
||||
groups = set(entity_data[1])
|
||||
groups = list(groups.union(self.args.groups))
|
||||
|
||||
try:
|
||||
await self.host.bridge.contact_update(
|
||||
self.args.jid, name, groups, self.host.profile)
|
||||
self.args.jid, name, groups, self.host.profile
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"error while updating the contact: {e}", error=True)
|
||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
||||
|
|
@ -128,14 +144,13 @@ class Set(base.CommandBase):
|
|||
class Delete(base.CommandBase):
|
||||
|
||||
def __init__(self, host):
|
||||
super().__init__(host, 'delete', help=_('remove an entity from roster'))
|
||||
super().__init__(host, "delete", help=_("remove an entity from roster"))
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"-f", "--force", action="store_true", help=_("delete without confirmation")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"jid", help=_("jid of the roster entity"))
|
||||
self.parser.add_argument("jid", help=_("jid of the roster entity"))
|
||||
|
||||
async def start(self):
|
||||
if not self.args.force:
|
||||
|
|
@ -144,8 +159,7 @@ class Delete(base.CommandBase):
|
|||
)
|
||||
await self.host.confirm_or_quit(message, _("entity deletion cancelled"))
|
||||
try:
|
||||
await self.host.bridge.contact_del(
|
||||
self.args.jid, self.host.profile)
|
||||
await self.host.bridge.contact_del(self.args.jid, self.host.profile)
|
||||
except Exception as e:
|
||||
self.disp(f"error while deleting the entity: {e}", error=True)
|
||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
||||
|
|
@ -155,7 +169,9 @@ class Delete(base.CommandBase):
|
|||
class Stats(base.CommandBase):
|
||||
|
||||
def __init__(self, host):
|
||||
super(Stats, self).__init__(host, 'stats', help=_('Show statistics about a roster'))
|
||||
super(Stats, self).__init__(
|
||||
host, "stats", help=_("Show statistics about a roster")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
|
|
@ -189,15 +205,18 @@ class Stats(base.CommandBase):
|
|||
total_group_subscription += len(groups)
|
||||
if not groups:
|
||||
no_group += 1
|
||||
hosts = OrderedDict(sorted(list(hosts.items()), key=lambda item:-item[1]))
|
||||
hosts = OrderedDict(sorted(list(hosts.items()), key=lambda item: -item[1]))
|
||||
|
||||
print()
|
||||
print("Total number of contacts: %d" % len(contacts))
|
||||
print("Number of different hosts: %d" % len(hosts))
|
||||
print()
|
||||
for host, count in hosts.items():
|
||||
print("Contacts on {host}: {count} ({rate:.1f}%)".format(
|
||||
host=host, count=count, rate=100 * float(count) / len(contacts)))
|
||||
print(
|
||||
"Contacts on {host}: {count} ({rate:.1f}%)".format(
|
||||
host=host, count=count, rate=100 * float(count) / len(contacts)
|
||||
)
|
||||
)
|
||||
print()
|
||||
print("Contacts with no 'from' subscription: %d" % no_from)
|
||||
print("Contacts with no 'to' subscription: %d" % no_to)
|
||||
|
|
@ -222,16 +241,22 @@ class Purge(base.CommandBase):
|
|||
|
||||
def __init__(self, host):
|
||||
super(Purge, self).__init__(
|
||||
host, 'purge',
|
||||
help=_('purge the roster from its contacts with no subscription'))
|
||||
host,
|
||||
"purge",
|
||||
help=_("purge the roster from its contacts with no subscription"),
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
"--no-from", action="store_true",
|
||||
help=_("also purge contacts with no 'from' subscription"))
|
||||
"--no-from",
|
||||
action="store_true",
|
||||
help=_("also purge contacts with no 'from' subscription"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"--no-to", action="store_true",
|
||||
help=_("also purge contacts with no 'to' subscription"))
|
||||
"--no-to",
|
||||
action="store_true",
|
||||
help=_("also purge contacts with no 'to' subscription"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
try:
|
||||
|
|
@ -259,7 +284,8 @@ class Purge(base.CommandBase):
|
|||
for contact in no_sub + no_from + no_to:
|
||||
try:
|
||||
await self.host.bridge.contact_del(
|
||||
contact, profile_key=self.host.profile)
|
||||
contact, profile_key=self.host.profile
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"can't delete contact {contact!r}: {e}", error=True)
|
||||
else:
|
||||
|
|
@ -278,24 +304,27 @@ class Purge(base.CommandBase):
|
|||
if no_sub:
|
||||
self.disp(
|
||||
f"There's no subscription between profile {self.host.profile!r} and the "
|
||||
f"following contacts:")
|
||||
f"following contacts:"
|
||||
)
|
||||
self.disp(" " + "\n ".join(no_sub))
|
||||
if no_from:
|
||||
self.disp(
|
||||
f"There's no 'from' subscription between profile {self.host.profile!r} "
|
||||
f"and the following contacts:")
|
||||
f"and the following contacts:"
|
||||
)
|
||||
self.disp(" " + "\n ".join(no_from))
|
||||
if no_to:
|
||||
self.disp(
|
||||
f"There's no 'to' subscription between profile {self.host.profile!r} and "
|
||||
f"the following contacts:")
|
||||
f"the following contacts:"
|
||||
)
|
||||
self.disp(" " + "\n ".join(no_to))
|
||||
message = f"REMOVE them from profile {self.host.profile}'s roster"
|
||||
while True:
|
||||
res = await self.host.ainput(f"{message} (y/N)? ")
|
||||
if not res or res.lower() == 'n':
|
||||
if not res or res.lower() == "n":
|
||||
return False
|
||||
if res.lower() == 'y':
|
||||
if res.lower() == "y":
|
||||
return True
|
||||
|
||||
|
||||
|
|
@ -303,7 +332,8 @@ class Resync(base.CommandBase):
|
|||
|
||||
def __init__(self, host):
|
||||
super(Resync, self).__init__(
|
||||
host, 'resync', help=_('do a full resynchronisation of roster with server'))
|
||||
host, "resync", help=_("do a full resynchronisation of roster with server")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
|
|
@ -324,4 +354,5 @@ class Roster(base.CommandBase):
|
|||
|
||||
def __init__(self, host):
|
||||
super(Roster, self).__init__(
|
||||
host, 'roster', use_profile=True, help=_("Manage an entity's roster"))
|
||||
host, "roster", use_profile=True, help=_("Manage an entity's roster")
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue