[Git][NTPsec/ntpsec][master] ntviz: @OPTIONFILE improvements.

Gary E. Miller gitlab at mg.gitlab.com
Sat Oct 15 21:34:50 UTC 2016


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
347eac0f by Gary E. Miller at 2016-10-15T14:30:56-07:00
ntviz: @OPTIONFILE improvements.

The OPTIONFILE format is now more flexible.  Comments are
allowed, starting with an octothorpe (#).  Blank lines are
ignored, Multiple options per line allowed.  And last but not
least, option and parameter can now be separated by a space.

- - - - -


2 changed files:

- docs/includes/ntpviz-body.txt
- ntpstats/ntpviz


Changes:

=====================================
docs/includes/ntpviz-body.txt
=====================================
--- a/docs/includes/ntpviz-body.txt
+++ b/docs/includes/ntpviz-body.txt
@@ -5,8 +5,9 @@
 [[synop]]
 == SYNOPSIS ==
 [verse]
-{ntpviz} [-d statsdir] [-g] [-n name] [-p period]
+{ntpviz} [-d LOGDIR] [-g] [-n name] [-p DAYS]
          [-s starttime] [-e endtime]
+         [-o OUTDIR]
          [ -c | --clip ]
          [--local-offset |
           --local-error |
@@ -21,9 +22,8 @@
           --peer-jitters=hosts |
           --peer-offsets=hosts |
          ]
-         [-o outdir]
          [-D N]
-         [@optionfile]
+         [@OPTIONFILE]
 
 == DESCRIPTION ==
 
@@ -36,10 +36,16 @@ subset of comparative plots for multiple directories.
 
 === Basic Options ===
 
--d DIRECTORY or --datadir DIRECTORY::
+-d LOGDIR or --datadir LOGDIR::
     Specifies one or more logfile directories to examine; the default is
     the single directory /var/log/ntpstats.
 
+-o OUTDIR or --outdir OUTDIR::
+    Set the directory for all output to be OUTDIR.  If OUTDIR does
+    not exist it is created.  The default OUTDIR is 'ntpgraphs'.
+    Warning: existing PNG files and index.html in the output directory
+    will be clobbered.
+
 -n STR or --name STR::
     Set the sitename shown in the plot title, and is effective only for the
     single-directory case. The default is the basename of the log directory.
@@ -128,10 +134,7 @@ The following plots are available:
    is a fatal error for any of these names not to appear in peerstats.
 
 If no individual plot is specified, all plots and an index HTML page
-are generated into a new output directory.  Normally this directory is
-named 'ntpgraphs', but the name can be changed with the -o option.
-Warning: existing PNG files and index.html in this directory will be
-clobbered.
+are generated into a the output directory.
 
 When an index is generated, ntpviz will look for two files in the
 output directory.  None of the files need be present, and the
@@ -154,21 +157,26 @@ standard error on, for example, missing logfile data required for a plot.
 
 === Argument File ===
 
-All command line options can also be placed into a command file.  The
-command file name is prefixed on the command line with an ampersand (@).
+Any command line options can also be placed into a command file.  The
+command file name (OPTIONFILE) is prefixed on the command line with an
+ampersand (@).
+
+Each line in the command file should contain just one option.  Multiple
+options per line are allowed, but discouraged.  Blank lines are allowed.
+
+Comments can be added, and start with an octothorpe (#).
 
-Each line in the command file must contain just one option.  When an
-option takes a parameter, the option and parameter must be separated by
-an equal sign (=).
+When an option takes a parameter, the option and parameter must be
+separated by an equal sign (=) or a space.
 
 These two ways to invoke ntpviz are equivalent:
 
     $ ntpviz --period 1 --outdir day
 
-    $ ntpviz @day/config
     $ cat day/config
     --period=1
     --outdir=day
+    $ ntpviz @day/config
 
 == REQUIREMENTS ==
 


=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -24,9 +24,28 @@ Python by ESR, concept and GNUPLOT code by Dan Drown.
 from __future__ import print_function, division
 
 import argparse
+import re
 import atexit, binascii, collections, os, socket, sys, time
 from ntp.statfiles import *
 
+# overload ArgumentParser
+class MyArgumentParser(argparse.ArgumentParser):
+
+    def convert_arg_line_to_args(self, arg_line):
+        '''Make options file more tolerant'''
+        # strip out trailing comments
+        arg_line = re.sub('\s+#.*$', '', arg_line)
+
+        # ignore blank lines
+        if 0 == len(arg_line):
+            return []
+        # ignore comment lines
+        if '#' == arg_line[0]:
+            return []
+
+        return arg_line.split()
+
+
 def print_profile():
     """called by atexit() on normal exit to print profile data"""
     pr.disable()
@@ -936,7 +955,7 @@ AADRxQAAxBEAAA==
 
 if __name__ == '__main__':
 
-    parser = argparse.ArgumentParser(description="ntpd stats visualizer",
+    parser = MyArgumentParser(description="ntpd stats visualizer",
                 fromfile_prefix_chars='@',
                 epilog = """
 You can place command line options in a file, one per line.



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/347eac0f36b498cf65073d5e4f9f1aae06eff97b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161015/670a4057/attachment.html>


More information about the vc mailing list