Synadm CLI Package#

The synadm.cli package contains all the command line frontend code (using the Python Click module), see the sections for each subcommand for help on usage and have a look into the files inside the synadm/cli directory to see how the CLI frontend is constructed. The main command is defined in __init__.py and each subcommand lives in its own module (e.g user.py, room.py, …)

Click command definition code is not very well suited for autogenerated Python package documentations (in this case using Sphinx autodoc) but one thing in this package that is worth mentioning and generating documentation for, is the synadm.cli.APIHelper class which is the connection between the CLI code and the backend code in synadm.api:

CLI helpers and utilities

class synadm.cli._helper.APIHelper(config_path, verbose, no_confirm, output_format_cli)#

Bases: object

API client enriched with CLI-level functions, used as a proxy to the client object.

FORMATTERS = {'human': <function humanize>, 'json': <function APIHelper.<lambda>>, 'minified': <function APIHelper.<lambda>>, 'pprint': <function pformat>, 'yaml': <function dump>}#
CONFIG = {'admin_path': '/_synapse/admin', 'base_url': 'http://localhost:8008', 'homeserver': 'auto-retrieval', 'matrix_path': '/_matrix', 'server_discovery': 'well-known', 'ssl_verify': True, 'timeout': 30, 'token': '', 'user': ''}#
init_logger(verbose)#

Log both to console (defaults to WARNING) and file (DEBUG).

_set_formatter(_output_format)#
load()#

Load the configuration and initialize the client.

write_config(config)#

Write a new version of the configuration to file.

output(data)#

Output data object using the configured formatter.

retrieve_homeserver_name(uri=None)#

Try to retrieve the homeserver name.

When homeserver is set in the config already, it’s just returned and nothing is tried to be fetched automatically. If not, either the location of the Federation API is looked up via a .well-known resource or a DNS SRV lookup. This depends on the server_discovery setting in the config. Finally the Federation API is used to retrieve the homeserver name.

Parameters:

uri (string) – proto://name:port or proto://fqdn:port

Returns:

hostname, FQDN or DOMAIN; or None on errors.

Return type:

string

generate_mxid(user_id)#

Checks whether the given user ID is an MXID already or else generates it from the passed string and the homeserver name fetched via the retrieve_homeserver_name method.

Parameters:

user_id (string) – User ID given by user as command argument.

Returns:

the fully qualified Matrix User ID (MXID) or None if the

user_id parameter is None or no regex matched.

Return type:

string