# HG changeset patch # User Dal # Date 1381150569 -7200 # Node ID 09bbd5c002446d395b1d39eb1ce9ac416244c907 # Parent 7d6e5807504aa664ee749f651579bf517ee8afeb jp: profiles management diff -r 7d6e5807504a -r 09bbd5c00244 frontends/src/jp/jp --- a/frontends/src/jp/jp Wed Oct 02 20:25:19 2013 +0200 +++ b/frontends/src/jp/jp Mon Oct 07 14:56:09 2013 +0200 @@ -108,6 +108,14 @@ 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 @@ 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 @@ 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 @@ 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: