Add verbose mode to docs loading and tweak defaults
authorMagnus Hagander <magnus@hagander.net>
Wed, 11 Aug 2021 12:44:35 +0000 (14:44 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 11 Aug 2021 12:46:35 +0000 (14:46 +0200)
Instead of printing every single page loaded, print the start of the
process and the statitics by default.

The existing --quiet parameter continues to work to make the process
completely quiet.

Add a new parameter --verbose that makes it run in the old way, printing
everything.

tools/docs/docload.py

index 427a93458cf7b79142db98e7b26cedd9d2938d38..5ececcb6b7b8b2f008eb576bc5477f1f8d909478 100755 (executable)
@@ -21,6 +21,8 @@ BOOTSTRAP_FIGURE_CLASS = r'<div\1class="figure col-xl-8 col-lg-10 col-md-12"'
 pagecount = 0
 # if set to "True" -- mutes any output from the script. Controlled by an option
 quiet = False
+# if set to "True" -- outputs extra much data (row-per-file)
+verbose = False
 # regular expression used to search and extract the title on a given piece of
 # documentation, for further use in the application
 re_titlematch = re.compile(r'<title\s*>([^<]+)</title\s*>', re.IGNORECASE)
@@ -76,8 +78,8 @@ def load_doc_file(filename, f, c):
     # in order to ensure they are able to display responsively
     contents = re_figure_match.sub(BOOTSTRAP_FIGURE_CLASS, contents)
 
-    # if not in quiet mode, output the (filename, title) pair of the docpage that is being processed
-    if not quiet:
+    # in verbose mode, output the (filename, title) pair of the docpage that is being processed
+    if verbose:
         print("--- file: %s (%s) ---" % (filename, title))
 
     # run libtidy on the content
@@ -99,7 +101,9 @@ def load_svg_file(filename, f, c):
 # Main execution
 parser = OptionParser(usage="usage: %prog [options] <version> <tarfile>")
 parser.add_option("-q", "--quiet", action="store_true", dest="quiet",
-                  help="Run quietly")
+                  help="Run quietly (no output at all)")
+parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                  help="Run verbosely")
 (options, args) = parser.parse_args()
 
 if len(args) != 2:
@@ -107,6 +111,12 @@ if len(args) != 2:
     sys.exit(1)
 
 quiet = options.quiet
+verbose = options.verbose
+
+if verbose and quiet:
+    print("Can't be both verbose and quiet at the same time!")
+    sys.exit(1)
+
 ver = sys.argv[1]
 tarfilename = sys.argv[2]
 
@@ -124,6 +134,9 @@ tf = tarfile.open(tarfilename)
 
 connection = psycopg2.connect(config.get('db', 'dsn'))
 
+if not quiet:
+    print("Starting load of documentation for version %s." % (ver, ))
+
 curs = connection.cursor()
 # Verify that the version exists, and what we're loading
 curs.execute("SELECT current FROM core_version WHERE tree=%(v)s", {'v': ver})
@@ -237,4 +250,4 @@ connection.commit()
 connection.close()
 
 if not quiet:
-    print("Done (%i pages)." % pagecount)
+    print("Done loading docs version %s (%i pages)." % (ver, pagecount))