From: Michael Tremer Date: Mon, 28 Sep 2020 15:35:24 +0000 (+0000) Subject: collectd: Rewrite script according to modern Python standards X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97d4c051bc6c3f02bef16c04e57d3c40ff13fe62;p=telemetry.git collectd: Rewrite script according to modern Python standards Signed-off-by: Michael Tremer --- diff --git a/src/collectyd b/src/collectyd index 4a75907..2927172 100755 --- a/src/collectyd +++ b/src/collectyd @@ -2,7 +2,7 @@ ############################################################################### # # # collecty - A system statistics collection daemon for IPFire # -# Copyright (C) 2012 IPFire development team # +# Copyright (C) 2020 IPFire development team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -19,26 +19,32 @@ # # ############################################################################### -import optparse -import sys - +import argparse import collecty.daemon -# Parse command line options. -op = optparse.OptionParser(usage="usage: %prog [options]") -op.add_option("-d", "--debug", action="store_true", default=False, - help="Enable debug logging.") -(options, args) = op.parse_args() +from collecty.i18n import _ + +def main(): + parser = argparse.ArgumentParser( + description=_("Collecty Daemon"), + ) + + # Global configuration flags + parser.add_argument("--debug", action="store_true", + help=_("Enable debug output"), + ) -# Initialize the settings for this Collecty instance. -settings = { - "debug" : options.debug, -} + # Parse CLI arguments + args = parser.parse_args() -# Initialize the application. -c = collecty.daemon.Daemon(**settings) + # Initialise the daemon + daemon = collecty.daemon.Daemon(debug=args.debug) -# Run. -c.run() + # Run it + try: + daemon.run() + except KeyboardInterrupt: + pass -sys.exit(0) +# Call main function +main()