comparison frontends/src/jp/base.py @ 1033:d87aa6bdb0b4

jp: option '-c' is not longer a flag but a string to define the profile password: - no '-c': same behavior as before, do not connect the profile - '-c' with not following value: autoconnect and use the default value '' as profile password - '-c' with a following value: autoconnect and use that value as profile password Note that previous scripts may not work. For example, even if the profile password for "test1" is empty: jp disco -p test1 -c contact@host.net must be changed to: jp disco -p test1 -c -- contact@host.net Otherwise, argparse will think that "contact@host.net" is the password and that the target JID is missing.
author souliane <souliane@mailoo.org>
date Wed, 07 May 2014 16:10:20 +0200
parents 8ca5c990ed92
children 75025461141f
comparison
equal deleted inserted replaced
1032:b262ae6d53af 1033:d87aa6bdb0b4
109 def _make_parents(self): 109 def _make_parents(self):
110 self.parents = {} 110 self.parents = {}
111 111
112 profile_parent = self.parents['profile'] = argparse.ArgumentParser(add_help=False) 112 profile_parent = self.parents['profile'] = argparse.ArgumentParser(add_help=False)
113 profile_parent.add_argument("-p", "--profile", action="store", type=str, default='@DEFAULT@', help=_("Use PROFILE profile key (default: %(default)s)")) 113 profile_parent.add_argument("-p", "--profile", action="store", type=str, default='@DEFAULT@', help=_("Use PROFILE profile key (default: %(default)s)"))
114 profile_parent.add_argument("-c", "--connect", action="store_true", help=_("Connect the profile before doing anything else")) 114 profile_parent.add_argument("-c", "--connect", action="store", type=str, nargs='?', const='', default=None, metavar='PASSWORD', help=_("Connect the profile before doing anything else"))
115 115
116 progress_parent = self.parents['progress'] = argparse.ArgumentParser(add_help=False) 116 progress_parent = self.parents['progress'] = argparse.ArgumentParser(add_help=False)
117 if progressbar: 117 if progressbar:
118 progress_parent.add_argument("-P", "--progress", action="store_true", help=_("Show progress bar")) 118 progress_parent.add_argument("-P", "--progress", action="store_true", help=_("Show progress bar"))
119 119
231 231
232 if not self.profile: 232 if not self.profile:
233 error(_("The profile [%s] doesn't exist") % self.args.profile) 233 error(_("The profile [%s] doesn't exist") % self.args.profile)
234 self.quit(1) 234 self.quit(1)
235 235
236 if self.args.connect: #if connection is asked, we connect the profile 236 if self.args.connect is not None: # if connection is asked, we connect the profile
237 self.bridge.asyncConnect(self.profile, callback, cant_connect) 237 self.bridge.asyncConnect(self.profile, self.args.connect, lambda dummy: callback(), cant_connect)
238 self._auto_loop = True 238 self._auto_loop = True
239 return 239 return
240 240
241 elif not self.bridge.isConnected(self.profile): 241 elif not self.bridge.isConnected(self.profile):
242 error(_(u"Profile [%(profile)s] is not connected, please connect it before using jp, or use --connect option") % { "profile": self.profile }) 242 error(_(u"Profile [%(profile)s] is not connected, please connect it before using jp, or use --connect option") % { "profile": self.profile })