Revert "drsuapi_dissect_element_DsGetNCChangesCtr6TS_ctr6 dissect_krb5_PAC_NDRHEADERBLOB"
[wireshark-sm.git] / tools / update-tools-help.py
blob9651828a98646c51c374692f05b26e1dda5a6ee0
1 #!/usr/bin/env python3
3 # update-tools-help.py - Update the command line help output in doc/wsug_src.
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # SPDX-License-Identifier: GPL-2.0-or-later
10 '''Update tools help
12 For each file that matches doc/wsug_src/<command>-<flag>.txt, run
13 that command and flag. Update the file if the output differs.
14 '''
16 import argparse
17 import difflib
18 import glob
19 import io
20 import os
21 import re
22 import subprocess
23 import sys
25 def main():
26 parser = argparse.ArgumentParser(description='Update Wireshark tools help')
27 parser.add_argument('-p', '--program-path', nargs=1, default=os.path.curdir, help='Path to Wireshark executables.')
28 args = parser.parse_args()
30 this_dir = os.path.dirname(__file__)
31 wsug_src_dir = os.path.join(this_dir, '..', 'doc', 'wsug_src')
33 tools_help_files = glob.glob(os.path.join(wsug_src_dir, '*-*.txt'))
34 tools_help_files.sort()
35 tool_pat = re.compile(r'(\w+)(-\w).txt')
37 # If tshark is present, assume that our other executables are as well.
38 program_path = args.program_path[0]
39 if not os.path.isfile(os.path.join(program_path, 'tshark')):
40 print('tshark not found at {}\n'.format(program_path))
41 parser.print_usage()
42 sys.exit(1)
44 null_fd = open(os.devnull, 'w')
46 for thf in tools_help_files:
47 thf_base = os.path.basename(thf)
48 m = tool_pat.match(thf_base)
49 thf_command = os.path.join(program_path, m.group(1))
50 thf_flag = m.group(2)
52 if not os.path.isfile(thf_command):
53 print('{} not found. Skipping.'.format(thf_command))
54 continue
56 with io.open(thf, 'r', encoding='UTF-8') as fd:
57 cur_help = fd.read()
59 try:
60 new_help_data = subprocess.check_output((thf_command, thf_flag), stderr=null_fd)
61 except subprocess.CalledProcessError as e:
62 if thf_flag == '-h':
63 raise e
65 new_help = new_help_data.decode('UTF-8', 'replace')
67 cur_lines = cur_help.splitlines()
68 new_lines = new_help.splitlines()
69 # Assume we have an extended version. Strip it.
70 cur_lines[0] = re.split(r' \(v\d+\.\d+\.\d+', cur_lines[0])[0]
71 new_lines[0] = re.split(r' \(v\d+\.\d+\.\d+', new_lines[0])[0]
72 diff = list(difflib.unified_diff(cur_lines, new_lines))
74 if (len(diff) > 0):
75 print('Updating {} {}'.format(thf_command, thf_flag))
76 with io.open(thf, 'w', encoding='UTF-8') as fd:
77 fd.write(new_help)
78 else:
79 print('{} {} output unchanged.'.format(thf_command, thf_flag))
81 if __name__ == '__main__':
82 main()