From 6de9a9258207ca38d320cc0bc3c3653deef12d7d Mon Sep 17 00:00:00 2001 From: Marc Joliet Date: Thu, 26 Sep 2013 17:15:53 +0200 Subject: Change the way xz/lzma man pages are detected This avoids the use of the global and puts the diagnostic message in a self-contained location. --- share/tools/create_manpage_completions.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'share') diff --git a/share/tools/create_manpage_completions.py b/share/tools/create_manpage_completions.py index f12d5c14..41fae2ed 100755 --- a/share/tools/create_manpage_completions.py +++ b/share/tools/create_manpage_completions.py @@ -20,7 +20,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND import string, sys, re, os.path, bz2, gzip, traceback, getopt, errno, codecs from deroff import Deroffer -lzma_printed_msg = False lzma_available = True try: try: @@ -715,7 +714,7 @@ def parse_manpage_at_path(manpage_path, output_directory): filename = os.path.basename(manpage_path) # Clear diagnostics - global diagnostic_indent, lzma_printed_msg + global diagnostic_indent diagnostic_output[:] = [] diagnostic_indent = 0 @@ -733,11 +732,6 @@ def parse_manpage_at_path(manpage_path, output_directory): if IS_PY3: manpage = manpage.decode('latin-1') elif manpage_path.endswith('.xz') or manpage_path.endswith('.lzma'): if not lzma_available: - if not lzma_printed_msg: - add_diagnostic('A man page is compressed with lzma or xz, but the "lzma" module is not available.' - ' Skipping. (This message is only printed on the first occurrence.)', - NOT_VERBOSE) - lzma_printed_msg = True return fd = lzma.LZMAFile(str(manpage_path), 'r') manpage = fd.read() @@ -841,6 +835,15 @@ def parse_and_output_man_pages(paths, output_directory, show_progress): last_progress_string_length = 0 if show_progress and not WRITE_TO_STDOUT: print("Parsing man pages and writing completions to {0}".format(output_directory)) + + man_page_suffixes = set([os.path.splitext(m)[1][1:] for m in paths]) + lzma_xz_occurs = "xz" in man_page_suffixes or "lzma" in man_page_suffixes + if lzma_xz_occurs and not lzma_available: + add_diagnostic('At least one man page is compressed with lzma or xz, but the "lzma" module is not available.' + ' Any man page compressed with either will be skipped.', + NOT_VERBOSE) + flush_diagnostics(sys.stderr) + for manpage_path in paths: index += 1 -- cgit v1.2.3