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
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.
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
))
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))
52 if not os
.path
.isfile(thf_command
):
53 print('{} not found. Skipping.'.format(thf_command
))
56 with io
.open(thf
, 'r', encoding
='UTF-8') as fd
:
60 new_help_data
= subprocess
.check_output((thf_command
, thf_flag
), stderr
=null_fd
)
61 except subprocess
.CalledProcessError
as 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
))
75 print('Updating {} {}'.format(thf_command
, thf_flag
))
76 with io
.open(thf
, 'w', encoding
='UTF-8') as fd
:
79 print('{} {} output unchanged.'.format(thf_command
, thf_flag
))
81 if __name__
== '__main__':