def main(dataPath, datacollector, display): """Main function of the odb2collector. :param String dataPath: Directory where the data will be stored. :param DataCollector datacollector: DataCollector instance used. :param Display display: Display instance used to show messages. """ ## Numer of bytes stored loggedBytes = 0 ## Initiate the compressor gzip = Compressor() gzip.start() logEnding = CONFIGURATION["logending"] while True: message = [ "Logged %skB" % (loggedBytes / 1024) ] print "\n".join(message) display.write_message(message) datafile = "%s/%s.%s" % (dataPath, _getCurrentTime(), logEnding) loggedBytes += datacollector.write_data_log( datafile, nbrOfOBDFrames=1000, messagesPerTimestamp=20 ) print "Collected data log..." gzip.add_file_for_compression(datafile)
def main(dataPath, datacollector, display): """Main function of the odb2collector. :param String dataPath: Directory where the data will be stored. :param DataCollector datacollector: DataCollector instance used. :param Display display: Display instance used to show messages. """ ## Numer of bytes stored loggedBytes = 0 ## Initiate the compressor gzip = Compressor() gzip.start() logEnding = CONFIGURATION["logending"] while True: message = ["Logged %skB" % (loggedBytes / 1024)] print "\n".join(message) display.write_message(message) datafile = "%s/%s.%s" % (dataPath, _getCurrentTime(), logEnding) loggedBytes += datacollector.write_data_log(datafile, nbrOfOBDFrames=1000, messagesPerTimestamp=20) print "Collected data log..." gzip.add_file_for_compression(datafile)
def main(): try: init_options() except OptionsError as e: sys.stderr.write("Error: {0}\n\n".format(e)) sys.stderr.write(usage()) sys.stderr.write("\n"); sys.stderr.flush() sys.exit(os.EX_CONFIG) if options.main.generate_config: print(generate_sample_config()) # XXX: this doesn't yet work properly because of groper sys.exit() conf_root = os.path.dirname(os.path.abspath(options.main.config)) facility_db = FacilityDB() try: facility_db.load_config(normalize_path(options.main.facilities_config, conf_root)) except (IOError) as e: sys.stderr.write("Error reading {0}: {1}\n".format(options.main.facilities_config, e)) sys.stderr.flush() sys.exit(os.EX_CONFIG) except (FacilityError, configparser.Error) as e: sys.stderr.write("{0} contains errors:\n\n".format(options.main.facilities_config)) if hasattr(e, 'lineno'): e = 'Error on line {0}: {1}'.format(e.lineno, e.message.split("\n")[0].strip()) sys.stderr.write("{0}\n\n".format(e)) sys.stderr.write("Exiting now.\n") sys.stderr.flush() sys.exit(os.EX_CONFIG) if options.main.check_config: sys.exit() # We are just checking the config file, so exit here. cache_config_checksum() create_dirs() if options.main.daemon: daemonize() if options.main.user: drop_privileges(options.main.user) if options.main.pidfile: write_pid(options.main.pidfile) atexit.register(exit_handler) setup_logging() try: logging.getLogger().info("Starting loghogd.") compressor = Compressor() compressor.find_uncompressed(options.main.logdir, r'.+\.log\..+') writer = Writer(facility_db, compressor, options.main.logdir) processor = Processor(facility_db, writer) server = Server(processor.on_message, conf_root) signal_handler = make_shutdown_handler(server, writer, compressor) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGHUP, make_reload_handler(facility_db, writer)) except Exception as e: logging.getLogger().error(e) logging.getLogger().error('Exiting abnormally due to an error at startup.') sys.exit(os.EX_CONFIG) try: compressor.start() server.run() except Exception as e: logging.getLogger().exception(e) logging.getLogger().error('Exiting abnormally due to an error at runtime.') shutdown(None, server, writer, compressor) sys.exit(os.EX_SOFTWARE) logging.getLogger().info('Shutdown complete. Exiting.')
def main(): try: init_options() except OptionsError as e: sys.stderr.write("Error: {0}\n\n".format(e)) sys.stderr.write(usage()) sys.stderr.write("\n") sys.stderr.flush() sys.exit(os.EX_CONFIG) if options.main.generate_config: print(generate_sample_config() ) # XXX: this doesn't yet work properly because of groper sys.exit() conf_root = os.path.dirname(os.path.abspath(options.main.config)) facility_db = FacilityDB() try: facility_db.load_config( normalize_path(options.main.facilities_config, conf_root)) except (IOError) as e: sys.stderr.write("Error reading {0}: {1}\n".format( options.main.facilities_config, e)) sys.stderr.flush() sys.exit(os.EX_CONFIG) except (FacilityError, configparser.Error) as e: sys.stderr.write("{0} contains errors:\n\n".format( options.main.facilities_config)) if hasattr(e, 'lineno'): e = 'Error on line {0}: {1}'.format( e.lineno, e.message.split("\n")[0].strip()) sys.stderr.write("{0}\n\n".format(e)) sys.stderr.write("Exiting now.\n") sys.stderr.flush() sys.exit(os.EX_CONFIG) if options.main.check_config: sys.exit() # We are just checking the config file, so exit here. cache_config_checksum() create_dirs() if options.main.daemon: daemonize() if options.main.user: drop_privileges(options.main.user) if options.main.pidfile: write_pid(options.main.pidfile) atexit.register(exit_handler) setup_logging() try: logging.getLogger().info("Starting loghogd.") compressor = Compressor() compressor.find_uncompressed(options.main.logdir, r'.+\.log\..+') writer = Writer(facility_db, compressor, options.main.logdir) processor = Processor(facility_db, writer) server = Server(processor.on_message, conf_root) signal_handler = make_shutdown_handler(server, writer, compressor) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGHUP, make_reload_handler(facility_db, writer)) except Exception as e: logging.getLogger().error(e) logging.getLogger().error( 'Exiting abnormally due to an error at startup.') sys.exit(os.EX_CONFIG) try: compressor.start() server.run() except Exception as e: logging.getLogger().exception(e) logging.getLogger().error( 'Exiting abnormally due to an error at runtime.') shutdown(None, server, writer, compressor) sys.exit(os.EX_SOFTWARE) logging.getLogger().info('Shutdown complete. Exiting.')