def main_cli(): config = None snarks = [] try: # If common's backend prompt funcs were to be replaced # (i.e., for GUI popups), that'd happen here. # Import the config module as an object that can # be passed around, and suppress creation of pyc clutter. # sys.dont_write_bytecode = True config = __import__("config") sys.dont_write_bytecode = False config = common.Changeling(config) # A copy w/o module baggage. logging.info("Calling %s parser..." % config.parser_name) snarks = snarkutils.parse_snarks(config) if (len(snarks) == 0): raise common.CompileSubsException("No messages were parsed.") snarkutils.process_snarks(config, snarks) if (len(snarks) == 0): raise common.CompileSubsException("After processing, no messages were left.") logging.info("Calling %s exporter..." % config.exporter_name) snarkutils.export_snarks(config, snarks) logging.info("Done.") except (common.CompileSubsException) as err: # Parser or Exporter failed in an uninteresting way. logging.error(str(err)) sys.exit(1) except (Exception) as err: logging.exception(err) sys.exit(1)
def threaded_code(snarks_wrapper=self._snarks_wrapper, config=config, keep_alive_func=None, sleep_func=None): # Don't touch snarks_wrapper until back in the main thread. try: logging.info("Calling %s parser..." % config.parser_name) wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Calling %s parser..." % config.parser_name}) snarks = snarkutils.parse_snarks(config, keep_alive_func=keep_alive_func, sleep_func=sleep_func) if (len(snarks) == 0): raise common.CompileSubsException("No messages were parsed.") snarkutils.gui_preprocess_snarks(config, snarks) snarkutils.gui_fudge_users(config, snarks) if (len(snarks) == 0): raise common.CompileSubsException("After preprocessing, no messages were left.") logging.info("Parsing succeeded.") wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Parsing succeeded."}) def main_code(snarks_wrapper=snarks_wrapper, snarks=snarks): snarks_wrapper.checkout(self.__class__.__name__) snarks_wrapper.set_snarks(snarks) snarks_wrapper.commit() event = common.SnarksEvent([common.SnarksEvent.FLAG_SNARKS]) snarks_wrapper.fire_snarks_event(event) wx.CallAfter(main_code) except (common.CompileSubsException) as err: # Parser failed in an uninteresting way. logging.error(str(err)) wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: %s" % str(err)}) except (Exception) as err: logging.exception(err) wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: The parser failed in an unexpected way."})