Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -30,7 +30,7 @@ log = getLogger(__name__)
|
|||
|
||||
__commands__ = ["Profile"]
|
||||
|
||||
PROFILE_HELP = _('The name of the profile')
|
||||
PROFILE_HELP = _("The name of the profile")
|
||||
|
||||
|
||||
class ProfileConnect(base.CommandBase):
|
||||
|
|
@ -39,7 +39,9 @@ class ProfileConnect(base.CommandBase):
|
|||
def __init__(self, host):
|
||||
# it's weird to have a command named "connect" with need_connect=False, but it can be handy to be able
|
||||
# to launch just the session, so some paradoxes don't hurt
|
||||
super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=('connect a profile'))
|
||||
super(ProfileConnect, self).__init__(
|
||||
host, "connect", need_connect=False, help=("connect a profile")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
|
|
@ -51,10 +53,13 @@ class ProfileConnect(base.CommandBase):
|
|||
self.parser.error(_("You need to use either --connect or --start-session"))
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class ProfileDisconnect(base.CommandBase):
|
||||
|
||||
def __init__(self, host):
|
||||
super(ProfileDisconnect, self).__init__(host, 'disconnect', need_connect=False, help=('disconnect a profile'))
|
||||
super(ProfileDisconnect, self).__init__(
|
||||
host, "disconnect", need_connect=False, help=("disconnect a profile")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
|
|
@ -72,29 +77,44 @@ class ProfileDisconnect(base.CommandBase):
|
|||
class ProfileCreate(base.CommandBase):
|
||||
def __init__(self, host):
|
||||
super(ProfileCreate, self).__init__(
|
||||
host, 'create', use_profile=False, help=('create a new profile'))
|
||||
host, "create", use_profile=False, help=("create a new profile")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument('profile', type=str, help=_('the name of the profile'))
|
||||
self.parser.add_argument("profile", type=str, help=_("the name of the profile"))
|
||||
self.parser.add_argument(
|
||||
'-p', '--password', type=str, default='',
|
||||
help=_('the password of the profile'))
|
||||
self.parser.add_argument(
|
||||
'-j', '--jid', type=str, help=_('the jid of the profile'))
|
||||
self.parser.add_argument(
|
||||
'-x', '--xmpp-password', type=str,
|
||||
help=_(
|
||||
'the password of the XMPP account (use profile password if not specified)'
|
||||
),
|
||||
metavar='PASSWORD')
|
||||
self.parser.add_argument(
|
||||
'-A', '--autoconnect', choices=[C.BOOL_TRUE, C.BOOL_FALSE], nargs='?',
|
||||
const=C.BOOL_TRUE,
|
||||
help=_('connect this profile automatically when backend starts')
|
||||
"-p",
|
||||
"--password",
|
||||
type=str,
|
||||
default="",
|
||||
help=_("the password of the profile"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
'-C', '--component', default='',
|
||||
help=_('set to component import name (entry point) if this is a component'))
|
||||
"-j", "--jid", type=str, help=_("the jid of the profile")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-x",
|
||||
"--xmpp-password",
|
||||
type=str,
|
||||
help=_(
|
||||
"the password of the XMPP account (use profile password if not specified)"
|
||||
),
|
||||
metavar="PASSWORD",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-A",
|
||||
"--autoconnect",
|
||||
choices=[C.BOOL_TRUE, C.BOOL_FALSE],
|
||||
nargs="?",
|
||||
const=C.BOOL_TRUE,
|
||||
help=_("connect this profile automatically when backend starts"),
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-C",
|
||||
"--component",
|
||||
default="",
|
||||
help=_("set to component import name (entry point) if this is a component"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
"""Create a new profile"""
|
||||
|
|
@ -103,55 +123,70 @@ class ProfileCreate(base.CommandBase):
|
|||
self.host.quit(C.EXIT_BRIDGE_ERROR)
|
||||
try:
|
||||
await self.host.bridge.profile_create(
|
||||
self.args.profile, self.args.password, self.args.component)
|
||||
self.args.profile, self.args.password, self.args.component
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"can't create profile: {e}", error=True)
|
||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
||||
|
||||
try:
|
||||
await self.host.bridge.profile_start_session(
|
||||
self.args.password, self.args.profile)
|
||||
self.args.password, self.args.profile
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"can't start profile session: {e}", error=True)
|
||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
||||
|
||||
if self.args.jid:
|
||||
await self.host.bridge.param_set(
|
||||
"JabberID", self.args.jid, "Connection", profile_key=self.args.profile)
|
||||
"JabberID", self.args.jid, "Connection", profile_key=self.args.profile
|
||||
)
|
||||
xmpp_pwd = self.args.password or self.args.xmpp_password
|
||||
if xmpp_pwd:
|
||||
await self.host.bridge.param_set(
|
||||
"Password", xmpp_pwd, "Connection", profile_key=self.args.profile)
|
||||
"Password", xmpp_pwd, "Connection", profile_key=self.args.profile
|
||||
)
|
||||
|
||||
if self.args.autoconnect is not None:
|
||||
await self.host.bridge.param_set(
|
||||
"autoconnect_backend", self.args.autoconnect, "Connection",
|
||||
profile_key=self.args.profile)
|
||||
"autoconnect_backend",
|
||||
self.args.autoconnect,
|
||||
"Connection",
|
||||
profile_key=self.args.profile,
|
||||
)
|
||||
|
||||
self.disp(f'profile {self.args.profile} created successfully', 1)
|
||||
self.disp(f"profile {self.args.profile} created successfully", 1)
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class ProfileDefault(base.CommandBase):
|
||||
def __init__(self, host):
|
||||
super(ProfileDefault, self).__init__(
|
||||
host, 'default', use_profile=False, help=('print default profile'))
|
||||
host, "default", use_profile=False, help=("print default profile")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
|
||||
async def start(self):
|
||||
print(await self.host.bridge.profile_name_get('@DEFAULT@'))
|
||||
print(await self.host.bridge.profile_name_get("@DEFAULT@"))
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class ProfileDelete(base.CommandBase):
|
||||
def __init__(self, host):
|
||||
super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=('delete a profile'))
|
||||
super(ProfileDelete, self).__init__(
|
||||
host, "delete", use_profile=False, help=("delete a profile")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument('profile', type=str, help=PROFILE_HELP)
|
||||
self.parser.add_argument('-f', '--force', action='store_true', help=_('delete profile without confirmation'))
|
||||
self.parser.add_argument("profile", type=str, help=PROFILE_HELP)
|
||||
self.parser.add_argument(
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help=_("delete profile without confirmation"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
if self.args.profile not in await self.host.bridge.profiles_list_get():
|
||||
|
|
@ -170,25 +205,35 @@ class ProfileInfo(base.CommandBase):
|
|||
|
||||
def __init__(self, host):
|
||||
super(ProfileInfo, self).__init__(
|
||||
host, 'info', need_connect=False, use_output=C.OUTPUT_DICT,
|
||||
help=_('get information about a profile'))
|
||||
self.to_show = [(_("jid"), "Connection", "JabberID"),]
|
||||
host,
|
||||
"info",
|
||||
need_connect=False,
|
||||
use_output=C.OUTPUT_DICT,
|
||||
help=_("get information about a profile"),
|
||||
)
|
||||
self.to_show = [
|
||||
(_("jid"), "Connection", "JabberID"),
|
||||
]
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument(
|
||||
'--show-password', action='store_true',
|
||||
help=_('show the XMPP password IN CLEAR TEXT'))
|
||||
"--show-password",
|
||||
action="store_true",
|
||||
help=_("show the XMPP password IN CLEAR TEXT"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
if self.args.show_password:
|
||||
self.to_show.append((_("XMPP password"), "Connection", "Password"))
|
||||
self.to_show.append((_("autoconnect (backend)"), "Connection",
|
||||
"autoconnect_backend"))
|
||||
self.to_show.append(
|
||||
(_("autoconnect (backend)"), "Connection", "autoconnect_backend")
|
||||
)
|
||||
data = {}
|
||||
for label, category, name in self.to_show:
|
||||
try:
|
||||
value = await self.host.bridge.param_get_a_async(
|
||||
name, category, profile_key=self.host.profile)
|
||||
name, category, profile_key=self.host.profile
|
||||
)
|
||||
except Exception as e:
|
||||
self.disp(f"can't get {name}/{category} param: {e}", error=True)
|
||||
else:
|
||||
|
|
@ -201,15 +246,20 @@ class ProfileInfo(base.CommandBase):
|
|||
class ProfileList(base.CommandBase):
|
||||
def __init__(self, host):
|
||||
super(ProfileList, self).__init__(
|
||||
host, 'list', use_profile=False, use_output='list', help=('list profiles'))
|
||||
host, "list", use_profile=False, use_output="list", help=("list profiles")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
group = self.parser.add_mutually_exclusive_group()
|
||||
group.add_argument(
|
||||
'-c', '--clients', action='store_true', help=_('get clients profiles only'))
|
||||
"-c", "--clients", action="store_true", help=_("get clients profiles only")
|
||||
)
|
||||
group.add_argument(
|
||||
'-C', '--components', action='store_true',
|
||||
help=('get components profiles only'))
|
||||
"-C",
|
||||
"--components",
|
||||
action="store_true",
|
||||
help=("get components profiles only"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
if self.args.clients:
|
||||
|
|
@ -226,55 +276,82 @@ class ProfileModify(base.CommandBase):
|
|||
|
||||
def __init__(self, host):
|
||||
super(ProfileModify, self).__init__(
|
||||
host, 'modify', need_connect=False, help=_('modify an existing profile'))
|
||||
host, "modify", need_connect=False, help=_("modify an existing profile")
|
||||
)
|
||||
|
||||
def add_parser_options(self):
|
||||
profile_pwd_group = self.parser.add_mutually_exclusive_group()
|
||||
profile_pwd_group.add_argument(
|
||||
'-w', '--password', help=_('change the password of the profile'))
|
||||
"-w", "--password", help=_("change the password of the profile")
|
||||
)
|
||||
profile_pwd_group.add_argument(
|
||||
'--disable-password', action='store_true',
|
||||
help=_('disable profile password (dangerous!)'))
|
||||
self.parser.add_argument('-j', '--jid', help=_('the jid of the profile'))
|
||||
"--disable-password",
|
||||
action="store_true",
|
||||
help=_("disable profile password (dangerous!)"),
|
||||
)
|
||||
self.parser.add_argument("-j", "--jid", help=_("the jid of the profile"))
|
||||
self.parser.add_argument(
|
||||
'-x', '--xmpp-password', help=_('change the password of the XMPP account'),
|
||||
metavar='PASSWORD')
|
||||
"-x",
|
||||
"--xmpp-password",
|
||||
help=_("change the password of the XMPP account"),
|
||||
metavar="PASSWORD",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
'-D', '--default', action='store_true', help=_('set as default profile'))
|
||||
"-D", "--default", action="store_true", help=_("set as default profile")
|
||||
)
|
||||
self.parser.add_argument(
|
||||
'-A', '--autoconnect', choices=[C.BOOL_TRUE, C.BOOL_FALSE], nargs='?',
|
||||
"-A",
|
||||
"--autoconnect",
|
||||
choices=[C.BOOL_TRUE, C.BOOL_FALSE],
|
||||
nargs="?",
|
||||
const=C.BOOL_TRUE,
|
||||
help=_('connect this profile automatically when backend starts')
|
||||
help=_("connect this profile automatically when backend starts"),
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
if self.args.disable_password:
|
||||
self.args.password = ''
|
||||
self.args.password = ""
|
||||
if self.args.password is not None:
|
||||
await self.host.bridge.param_set(
|
||||
"Password", self.args.password, "General", profile_key=self.host.profile)
|
||||
"Password", self.args.password, "General", profile_key=self.host.profile
|
||||
)
|
||||
if self.args.jid is not None:
|
||||
await self.host.bridge.param_set(
|
||||
"JabberID", self.args.jid, "Connection", profile_key=self.host.profile)
|
||||
"JabberID", self.args.jid, "Connection", profile_key=self.host.profile
|
||||
)
|
||||
if self.args.xmpp_password is not None:
|
||||
await self.host.bridge.param_set(
|
||||
"Password", self.args.xmpp_password, "Connection",
|
||||
profile_key=self.host.profile)
|
||||
"Password",
|
||||
self.args.xmpp_password,
|
||||
"Connection",
|
||||
profile_key=self.host.profile,
|
||||
)
|
||||
if self.args.default:
|
||||
await self.host.bridge.profile_set_default(self.host.profile)
|
||||
if self.args.autoconnect is not None:
|
||||
await self.host.bridge.param_set(
|
||||
"autoconnect_backend", self.args.autoconnect, "Connection",
|
||||
profile_key=self.host.profile)
|
||||
"autoconnect_backend",
|
||||
self.args.autoconnect,
|
||||
"Connection",
|
||||
profile_key=self.host.profile,
|
||||
)
|
||||
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class Profile(base.CommandBase):
|
||||
subcommands = (
|
||||
ProfileConnect, ProfileDisconnect, ProfileCreate, ProfileDefault, ProfileDelete,
|
||||
ProfileInfo, ProfileList, ProfileModify)
|
||||
ProfileConnect,
|
||||
ProfileDisconnect,
|
||||
ProfileCreate,
|
||||
ProfileDefault,
|
||||
ProfileDelete,
|
||||
ProfileInfo,
|
||||
ProfileList,
|
||||
ProfileModify,
|
||||
)
|
||||
|
||||
def __init__(self, host):
|
||||
super(Profile, self).__init__(
|
||||
host, 'profile', use_profile=False, help=_('profile commands'))
|
||||
host, "profile", use_profile=False, help=_("profile commands")
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue