[Git][NTPsec/ntpsec][master] Use a 'title' file if present in the output directory.

Gary E. Miller gitlab at mg.gitlab.com
Fri Sep 9 01:24:46 UTC 2016


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


Commits:
59dc7e80 by Gary E. Miller at 2016-09-08T18:22:56-07:00
Use a 'title' file if present in the output directory.

I run 8 copies of ntpviz, now I can tell them apart.

- - - - -


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
@@ -105,8 +105,9 @@ 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.
 
-When an index is generated, ntpviz will look for two files in the
-output directory.  Neither file need be present, and both files may
+When an index is generated, ntpviz will look for three files in the
+output directory.  None of the files need be present, and the
+'header' and 'footer' files may contain arbitrary html.
 contain aribtrary HTML.
 
 The first file is named 'header'.  The contents of that file will be
@@ -120,6 +121,9 @@ added almost at the bottom of the body on the generated index.
 It is suggested that notes on the server be included in the footer
 file: OS, versions, CPU speed, etc.  You may also put links there.
 
+The thrid file is named 'title' and must be a single line of text.  This
+text will be used as the HTML title of the generated index.
+
 The code includes various sanity checks and will bail out with a message to
 standard error on, for example, missing logfile data required for a plot.
 


=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -820,6 +820,19 @@ at 0s. Typical 90% ranges may be: local serial GPS 200 ms; local LAN peer
 """,
         }
 
+    start_time = datetime.datetime.utcnow()
+    start_time_str = start_time.strftime("%c")
+
+    # if title file, get title from it
+    title_f = os.path.join(outdir, "title")
+    title = 'ntpviz'
+    if os.path.isfile(title_f):
+        try:
+            title_file = open( title_f, 'r')
+            title = title_file.read()
+        except IOError:
+            pass
+
     index_header = '''\
 <!DOCTYPE html>
 <html lang="en">
@@ -827,7 +840,7 @@ at 0s. Typical 90% ranges may be: local serial GPS 200 ms; local LAN peer
 <meta charset="UTF-8">
 <meta http-equiv="refresh" content="1800">
 <meta name="expires" content="0">
-<title>ntpviz plot</title>
+<title>%(title)s</title>
 <style>
 dt {
     font-weight: bold;
@@ -845,11 +858,10 @@ dd {
 <img src="ntpsec-logo.png" alt="NTPsec" style="float:left;margin:5px 50px;">
 </a>
 <div>
-<h1 style="margin-bottom:10px;">NTP Stats</h1>
-'''
+<h1 style="margin-bottom:10px;">%(title)s</h1>
+Report generated: %(start_time_str)s UTC <br>
+''' % locals()
 
-    start_time = datetime.datetime.utcnow()
-    index_header += 'Report generated: %s UTC <br>' % start_time.strftime("%c")
 
     # Ugh.  Not clear what to do in the multiplot case
     if len(statlist) == 1:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/59dc7e803b2c2c1aaf68d395fbb7649a9ea79f9c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160909/6cd86027/attachment.html>


More information about the vc mailing list