Mercurial > libervia-backend
comparison frontends/src/jp/jp @ 657:09bbd5c00244
jp: profiles management
author | Dal <kedals0@gmail.com> |
---|---|
date | Mon, 07 Oct 2013 14:56:09 +0200 |
parents | d207c2186519 |
children | f7878ad3c846 |
comparison
equal
deleted
inserted
replaced
656:7d6e5807504a | 657:09bbd5c00244 |
---|---|
106 help=_("Show progress bar")) | 106 help=_("Show progress bar")) |
107 parser.add_option("-s", "--separate", action="store_true", default=False, | 107 parser.add_option("-s", "--separate", action="store_true", default=False, |
108 help=_("Separate xmpp messages: send one message per line instead of one message alone.")) | 108 help=_("Separate xmpp messages: send one message per line instead of one message alone.")) |
109 parser.add_option("-n", "--new-line", action="store_true", default=False, | 109 parser.add_option("-n", "--new-line", action="store_true", default=False, |
110 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))")) | 110 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))")) |
111 parser.add_option("--list-profiles", action="store_true", default=False, | |
112 help=_("List available profiles")) | |
113 parser.add_option("-c", "--create-profile", action="store", type="string", nargs=3, | |
114 help=_("Create a profile (args: profile_name jid password)")) | |
115 parser.add_option("--get-profile", action="store", type="string", | |
116 help=_("Get profile informations (arg: profile_name)")) | |
117 parser.add_option("--rm-profile", action="store", type="string", | |
118 help=_("Remove profile")) | |
111 parser.add_option("--connect", action="store_true", default=False, | 119 parser.add_option("--connect", action="store_true", default=False, |
112 help=_("Connect the profile before doing anything else")) | 120 help=_("Connect the profile before doing anything else")) |
113 parser.add_option("--pipe-in", action="store_true", default=False, | 121 parser.add_option("--pipe-in", action="store_true", default=False, |
114 help=_("Wait for the reception of a pipe stream")) | 122 help=_("Wait for the reception of a pipe stream")) |
115 parser.add_option("--pipe-out", action="store_true", default=False, | 123 parser.add_option("--pipe-out", action="store_true", default=False, |
116 help=_("Pipe a stream out ")) | 124 help=_("Pipe a stream out ")) |
117 | 125 |
118 (self.options, args) = parser.parse_args() | 126 (self.options, args) = parser.parse_args() |
127 if self.options.list_profiles: | |
128 for p in self.bridge.getProfilesList(): | |
129 info(p) | |
130 exit(0) | |
131 if self.options.create_profile or self.options.get_profile: | |
132 self.start_loop = True | |
133 return args | |
134 if self.options.rm_profile: | |
135 self.start_loop = False | |
136 return args | |
119 | 137 |
120 if len(args) < 1 and not self.options.wait_file: | 138 if len(args) < 1 and not self.options.wait_file: |
121 parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8')) | 139 parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8')) |
122 | 140 |
123 if self.options.wait_file or self.options.pipe_in: | 141 if self.options.wait_file or self.options.pipe_in: |
137 else: | 155 else: |
138 self.start_loop = False | 156 self.start_loop = False |
139 | 157 |
140 | 158 |
141 return args | 159 return args |
160 | |
161 def create_profile(self): | |
162 """Create a new profile""" | |
163 profile, jid, password = self.options.create_profile | |
164 if profile in self.bridge.getProfilesList(): | |
165 error("Profile %s already exists."%profile) | |
166 exit(1) | |
167 self.bridge.asyncCreateProfile(profile, lambda : self._create_profile(profile, jid, password), None) | |
168 | |
169 def get_profile(self): | |
170 def setJID(jid): | |
171 info("jid: %s"%jid) | |
172 self.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword) | |
173 def setPassword(password): | |
174 info("pwd: %s"%password) | |
175 self.loop.quit() | |
176 profile_name = self.options.get_profile | |
177 if profile_name not in self.bridge.getProfilesList(): | |
178 error("Profile %s doesn't exist."%profile_name) | |
179 exit(1) | |
180 self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID) | |
181 | |
182 def rm_profile(self): | |
183 profile_name = self.options.rm_profile | |
184 if profile_name not in self.bridge.getProfilesList(): | |
185 error("Profile %s doesn't exist."%profile_name) | |
186 exit(1) | |
187 self.bridge.deleteProfile(profile_name) | |
188 | |
189 def _create_profile(self, profile_name, jid, password): | |
190 self.bridge.setParam("JabberID", jid, "Connection" ,profile_key=profile_name) | |
191 self.bridge.setParam("Server", JID(jid).domain, "Connection", profile_key=profile_name) | |
192 self.bridge.setParam("Password", password, "Connection", profile_key=profile_name) | |
193 self.loop.quit() | |
142 | 194 |
143 def check_jabber_status(self): | 195 def check_jabber_status(self): |
144 """Check that jabber status is allright""" | 196 """Check that jabber status is allright""" |
145 def cantConnect(): | 197 def cantConnect(): |
146 error(_(u"Can't connect profile")) | 198 error(_(u"Can't connect profile")) |
350 | 402 |
351 return True | 403 return True |
352 | 404 |
353 def go(self): | 405 def go(self): |
354 self.check_options() | 406 self.check_options() |
355 self.check_jabber_status() | 407 if self.options.create_profile: |
408 self.create_profile() | |
409 elif self.options.get_profile: | |
410 self.get_profile() | |
411 elif self.options.rm_profile: | |
412 self.rm_profile() | |
413 else: | |
414 self.check_jabber_status() | |
356 if self.start_loop: | 415 if self.start_loop: |
357 self.loop = gobject.MainLoop() | 416 self.loop = gobject.MainLoop() |
358 try: | 417 try: |
359 self.loop.run() | 418 self.loop.run() |
360 except KeyboardInterrupt: | 419 except KeyboardInterrupt: |