jp: profiles management
This commit is contained in:
parent
6f58566118
commit
95e6be2b20
1 changed files with 60 additions and 1 deletions
|
|
@ -108,6 +108,14 @@ class JP(object):
|
|||
help=_("Separate xmpp messages: send one message per line instead of one message alone."))
|
||||
parser.add_option("-n", "--new-line", action="store_true", default=False,
|
||||
help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
|
||||
parser.add_option("--list-profiles", action="store_true", default=False,
|
||||
help=_("List available profiles"))
|
||||
parser.add_option("-c", "--create-profile", action="store", type="string", nargs=3,
|
||||
help=_("Create a profile (args: profile_name jid password)"))
|
||||
parser.add_option("--get-profile", action="store", type="string",
|
||||
help=_("Get profile informations (arg: profile_name)"))
|
||||
parser.add_option("--rm-profile", action="store", type="string",
|
||||
help=_("Remove profile"))
|
||||
parser.add_option("--connect", action="store_true", default=False,
|
||||
help=_("Connect the profile before doing anything else"))
|
||||
parser.add_option("--pipe-in", action="store_true", default=False,
|
||||
|
|
@ -116,6 +124,16 @@ class JP(object):
|
|||
help=_("Pipe a stream out "))
|
||||
|
||||
(self.options, args) = parser.parse_args()
|
||||
if self.options.list_profiles:
|
||||
for p in self.bridge.getProfilesList():
|
||||
info(p)
|
||||
exit(0)
|
||||
if self.options.create_profile or self.options.get_profile:
|
||||
self.start_loop = True
|
||||
return args
|
||||
if self.options.rm_profile:
|
||||
self.start_loop = False
|
||||
return args
|
||||
|
||||
if len(args) < 1 and not self.options.wait_file:
|
||||
parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8'))
|
||||
|
|
@ -140,6 +158,40 @@ class JP(object):
|
|||
|
||||
return args
|
||||
|
||||
def create_profile(self):
|
||||
"""Create a new profile"""
|
||||
profile, jid, password = self.options.create_profile
|
||||
if profile in self.bridge.getProfilesList():
|
||||
error("Profile %s already exists."%profile)
|
||||
exit(1)
|
||||
self.bridge.asyncCreateProfile(profile, lambda : self._create_profile(profile, jid, password), None)
|
||||
|
||||
def get_profile(self):
|
||||
def setJID(jid):
|
||||
info("jid: %s"%jid)
|
||||
self.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword)
|
||||
def setPassword(password):
|
||||
info("pwd: %s"%password)
|
||||
self.loop.quit()
|
||||
profile_name = self.options.get_profile
|
||||
if profile_name not in self.bridge.getProfilesList():
|
||||
error("Profile %s doesn't exist."%profile_name)
|
||||
exit(1)
|
||||
self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID)
|
||||
|
||||
def rm_profile(self):
|
||||
profile_name = self.options.rm_profile
|
||||
if profile_name not in self.bridge.getProfilesList():
|
||||
error("Profile %s doesn't exist."%profile_name)
|
||||
exit(1)
|
||||
self.bridge.deleteProfile(profile_name)
|
||||
|
||||
def _create_profile(self, profile_name, jid, password):
|
||||
self.bridge.setParam("JabberID", jid, "Connection" ,profile_key=profile_name)
|
||||
self.bridge.setParam("Server", JID(jid).domain, "Connection", profile_key=profile_name)
|
||||
self.bridge.setParam("Password", password, "Connection", profile_key=profile_name)
|
||||
self.loop.quit()
|
||||
|
||||
def check_jabber_status(self):
|
||||
"""Check that jabber status is allright"""
|
||||
def cantConnect():
|
||||
|
|
@ -352,7 +404,14 @@ class JP(object):
|
|||
|
||||
def go(self):
|
||||
self.check_options()
|
||||
self.check_jabber_status()
|
||||
if self.options.create_profile:
|
||||
self.create_profile()
|
||||
elif self.options.get_profile:
|
||||
self.get_profile()
|
||||
elif self.options.rm_profile:
|
||||
self.rm_profile()
|
||||
else:
|
||||
self.check_jabber_status()
|
||||
if self.start_loop:
|
||||
self.loop = gobject.MainLoop()
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in a new issue