]> git.ipfire.org Git - collecty.git/commitdiff
collectd: Rewrite script according to modern Python standards
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2020 15:35:24 +0000 (15:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2020 15:35:24 +0000 (15:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collectyd

index 4a7590754571535e414b76b62c8630e1e28b3631..2927172bf369a990ab4c7900c594f025ba6d72f8 100755 (executable)
@@ -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        #
 #                                                                             #
 ###############################################################################
 
-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()