jp (profile): added --autoconnect argument in modify and create + use output in info
This commit is contained in:
parent
da3b7b5fea
commit
610a8ff10b
1 changed files with 83 additions and 41 deletions
|
|
@ -22,10 +22,12 @@ and retrieve information about a profile."""
|
||||||
|
|
||||||
from sat_frontends.jp.constants import Const as C
|
from sat_frontends.jp.constants import Const as C
|
||||||
from sat.core.log import getLogger
|
from sat.core.log import getLogger
|
||||||
log = getLogger(__name__)
|
|
||||||
from sat.core.i18n import _
|
from sat.core.i18n import _
|
||||||
from sat_frontends.jp import base
|
from sat_frontends.jp import base
|
||||||
|
|
||||||
|
log = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
__commands__ = ["Profile"]
|
__commands__ = ["Profile"]
|
||||||
|
|
||||||
PROFILE_HELP = _('The name of the profile')
|
PROFILE_HELP = _('The name of the profile')
|
||||||
|
|
@ -69,16 +71,30 @@ class ProfileDisconnect(base.CommandBase):
|
||||||
|
|
||||||
class ProfileCreate(base.CommandBase):
|
class ProfileCreate(base.CommandBase):
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=('create a new profile'))
|
super(ProfileCreate, self).__init__(
|
||||||
|
host, 'create', use_profile=False, help=('create a new profile'))
|
||||||
|
|
||||||
def add_parser_options(self):
|
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(
|
||||||
self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile'))
|
'-p', '--password', type=str, default='',
|
||||||
self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account (use profile password if not specified)'),
|
help=_('the password of the profile'))
|
||||||
metavar='PASSWORD')
|
self.parser.add_argument(
|
||||||
self.parser.add_argument('-C', '--component', default='',
|
'-j', '--jid', type=str, help=_('the jid of the profile'))
|
||||||
help=_('set to component import name (entry point) if this is a component'))
|
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):
|
async def start(self):
|
||||||
"""Create a new profile"""
|
"""Create a new profile"""
|
||||||
|
|
@ -107,13 +123,19 @@ class ProfileCreate(base.CommandBase):
|
||||||
await self.host.bridge.setParam(
|
await self.host.bridge.setParam(
|
||||||
"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.setParam(
|
||||||
|
"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()
|
self.host.quit()
|
||||||
|
|
||||||
|
|
||||||
class ProfileDefault(base.CommandBase):
|
class ProfileDefault(base.CommandBase):
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=('print default profile'))
|
super(ProfileDefault, self).__init__(
|
||||||
|
host, 'default', use_profile=False, help=('print default profile'))
|
||||||
|
|
||||||
def add_parser_options(self):
|
def add_parser_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -145,48 +167,49 @@ class ProfileDelete(base.CommandBase):
|
||||||
|
|
||||||
|
|
||||||
class ProfileInfo(base.CommandBase):
|
class ProfileInfo(base.CommandBase):
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile'))
|
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"),]
|
self.to_show = [(_("jid"), "Connection", "JabberID"),]
|
||||||
self.largest = max([len(item[0]) for item in self.to_show])
|
|
||||||
|
|
||||||
def add_parser_options(self):
|
def add_parser_options(self):
|
||||||
self.parser.add_argument('--show-password', action='store_true', help=_('show the XMPP password IN CLEAR TEXT'))
|
self.parser.add_argument(
|
||||||
|
'--show-password', action='store_true',
|
||||||
|
help=_('show the XMPP password IN CLEAR TEXT'))
|
||||||
|
|
||||||
async def showNextValue(self, label=None, category=None, value=None):
|
async def start(self):
|
||||||
"""Show next value from self.to_show and quit on last one"""
|
if self.args.show_password:
|
||||||
if label is not None:
|
self.to_show.append((_("XMPP password"), "Connection", "Password"))
|
||||||
print((("{label:<"+str(self.largest+2)+"}{value}").format(
|
self.to_show.append((_("autoconnect (backend)"), "Connection",
|
||||||
label=label+": ", value=value)))
|
"autoconnect_backend"))
|
||||||
try:
|
data = {}
|
||||||
label, category, name = self.to_show.pop(0)
|
for label, category, name in self.to_show:
|
||||||
except IndexError:
|
|
||||||
self.host.quit()
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
value = await self.host.bridge.asyncGetParamA(
|
value = await self.host.bridge.asyncGetParamA(
|
||||||
name, category, profile_key=self.host.profile)
|
name, category, profile_key=self.host.profile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.disp(f"can't get {name}/{category} param: {e}", error=True)
|
self.disp(f"can't get {name}/{category} param: {e}", error=True)
|
||||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
|
||||||
else:
|
else:
|
||||||
await self.showNextValue(label, category, value)
|
data[label] = value
|
||||||
|
|
||||||
async def start(self):
|
await self.output(data)
|
||||||
if self.args.show_password:
|
self.host.quit()
|
||||||
self.to_show.append((_("XMPP password"), "Connection", "Password"))
|
|
||||||
await self.showNextValue()
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileList(base.CommandBase):
|
class ProfileList(base.CommandBase):
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=('list profiles'))
|
super(ProfileList, self).__init__(
|
||||||
|
host, 'list', use_profile=False, use_output='list', help=('list profiles'))
|
||||||
|
|
||||||
def add_parser_options(self):
|
def add_parser_options(self):
|
||||||
group = self.parser.add_mutually_exclusive_group()
|
group = self.parser.add_mutually_exclusive_group()
|
||||||
group.add_argument('-c', '--clients', action='store_true', help=_('get clients profiles only'))
|
group.add_argument(
|
||||||
group.add_argument('-C', '--components', action='store_true', help=('get components 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'))
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
if self.args.clients:
|
if self.args.clients:
|
||||||
|
|
@ -202,16 +225,27 @@ class ProfileList(base.CommandBase):
|
||||||
class ProfileModify(base.CommandBase):
|
class ProfileModify(base.CommandBase):
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=_('modify an existing profile'))
|
super(ProfileModify, self).__init__(
|
||||||
|
host, 'modify', need_connect=False, help=_('modify an existing profile'))
|
||||||
|
|
||||||
def add_parser_options(self):
|
def add_parser_options(self):
|
||||||
profile_pwd_group = self.parser.add_mutually_exclusive_group()
|
profile_pwd_group = self.parser.add_mutually_exclusive_group()
|
||||||
profile_pwd_group.add_argument('-w', '--password', help=_('change the password of the profile'))
|
profile_pwd_group.add_argument(
|
||||||
profile_pwd_group.add_argument('--disable-password', action='store_true', help=_('disable profile password (dangerous!)'))
|
'-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'))
|
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'),
|
self.parser.add_argument(
|
||||||
metavar='PASSWORD')
|
'-x', '--xmpp-password', help=_('change the password of the XMPP account'),
|
||||||
self.parser.add_argument('-D', '--default', action='store_true', help=_('set as default profile'))
|
metavar='PASSWORD')
|
||||||
|
self.parser.add_argument(
|
||||||
|
'-D', '--default', action='store_true', help=_('set as default profile'))
|
||||||
|
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')
|
||||||
|
)
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
if self.args.disable_password:
|
if self.args.disable_password:
|
||||||
|
|
@ -224,15 +258,23 @@ class ProfileModify(base.CommandBase):
|
||||||
"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:
|
if self.args.xmpp_password is not None:
|
||||||
await self.host.bridge.setParam(
|
await self.host.bridge.setParam(
|
||||||
"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:
|
if self.args.default:
|
||||||
await self.host.bridge.profileSetDefault(self.host.profile)
|
await self.host.bridge.profileSetDefault(self.host.profile)
|
||||||
|
if self.args.autoconnect is not None:
|
||||||
|
await self.host.bridge.setParam(
|
||||||
|
"autoconnect_backend", self.args.autoconnect, "Connection",
|
||||||
|
profile_key=self.host.profile)
|
||||||
|
|
||||||
self.host.quit()
|
self.host.quit()
|
||||||
|
|
||||||
|
|
||||||
class Profile(base.CommandBase):
|
class Profile(base.CommandBase):
|
||||||
subcommands = (ProfileConnect, ProfileDisconnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify)
|
subcommands = (
|
||||||
|
ProfileConnect, ProfileDisconnect, ProfileCreate, ProfileDefault, ProfileDelete,
|
||||||
|
ProfileInfo, ProfileList, ProfileModify)
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('profile commands'))
|
super(Profile, self).__init__(
|
||||||
|
host, 'profile', use_profile=False, help=_('profile commands'))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue