comparison frontends/src/jp/base.py @ 2309:c7a72b75232b

jp (shell): shell command (REPL mode), first draft: This command launch jp in REPL mode, allowing do normal jp commands with some facilities. Command can be selected with "cmd" (e.g. "cmd blog"). An argument can be fixed with "use" (e.g. "use output fancy"). Command is launched with "do", or directly with its name if it doesn't conflict with a shell command. Arguments completion is still TODO (only shell commands are completed so far).
author Goffi <goffi@goffi.org>
date Thu, 06 Jul 2017 20:28:25 +0200
parents 637886ac35f6
children eaff25529c53
comparison
equal deleted inserted replaced
2308:0b21d87c91cf 2309:c7a72b75232b
163 log.error(u"Can't import {} bridge".format(bridge_name)) 163 log.error(u"Can't import {} bridge".format(bridge_name))
164 sys.exit(1) 164 sys.exit(1)
165 165
166 self.bridge = bridge_module.Bridge() 166 self.bridge = bridge_module.Bridge()
167 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) 167 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb)
168 # _no_exit is used in shell mode because SystemExit can't
169 # catched when loop is in use
170 self._no_exit = False
168 171
169 def _bridgeCb(self): 172 def _bridgeCb(self):
170 self.parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, 173 self.parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
171 description=DESCRIPTION) 174 description=DESCRIPTION)
172 self._make_parents() 175 self._make_parents()
400 else: 403 else:
401 for class_name in class_names: 404 for class_name in class_names:
402 cls = getattr(module, class_name) 405 cls = getattr(module, class_name)
403 cls(self) 406 cls(self)
404 407
405 def run(self, args=None): 408 def run(self, args=None, namespace=None):
406 self.args = self.parser.parse_args(args) 409 self.args = self.parser.parse_args(args, namespace=None)
407 try: 410 try:
408 self.args.func() 411 self.args.func()
409 if self._need_loop or self._auto_loop: 412 if self._need_loop or self._auto_loop:
410 self._start_loop() 413 self._start_loop()
411 except KeyboardInterrupt: 414 except KeyboardInterrupt:
440 else: 443 else:
441 for callback, args, kwargs in callbacks_list: 444 for callback, args, kwargs in callbacks_list:
442 callback(*args, **kwargs) 445 callback(*args, **kwargs)
443 446
444 self.stop_loop() 447 self.stop_loop()
445 sys.exit(errcode) 448 if not self._no_exit:
449 sys.exit(errcode)
446 450
447 def check_jids(self, jids): 451 def check_jids(self, jids):
448 """Check jids validity, transform roster name to corresponding jids 452 """Check jids validity, transform roster name to corresponding jids
449 453
450 @param profile: profile name 454 @param profile: profile name