summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrelease/update-manpages28
-rw-r--r--tests/test_update_manpages.py27
l---------tests/update_manpages.py1
3 files changed, 49 insertions, 7 deletions
diff --git a/release/update-manpages b/release/update-manpages
index d619cf0b..739cedb1 100755
--- a/release/update-manpages
+++ b/release/update-manpages
@@ -83,11 +83,6 @@ def main(argv):
83 with multiprocessing.Pool() as pool: 83 with multiprocessing.Pool() as pool:
84 pool.map(partial(worker, cwd=tempdir, check=True), cmdlist) 84 pool.map(partial(worker, cwd=tempdir, check=True), cmdlist)
85 85
86 regex = (
87 (r'(It was generated by help2man) [0-9.]+', '\g<1>.'),
88 (r'^\.IP\n(.*:)\n', '.SS \g<1>\n'),
89 (r'^\.PP\nDescription', '.SH DETAILS'),
90 )
91 for tmp_path in MANDIR.glob('*.1.tmp'): 86 for tmp_path in MANDIR.glob('*.1.tmp'):
92 path = tmp_path.parent / tmp_path.stem 87 path = tmp_path.parent / tmp_path.stem
93 old_data = path.read_text() if path.exists() else '' 88 old_data = path.read_text() if path.exists() else ''
@@ -95,8 +90,7 @@ def main(argv):
95 data = tmp_path.read_text() 90 data = tmp_path.read_text()
96 tmp_path.unlink() 91 tmp_path.unlink()
97 92
98 for pattern, replacement in regex: 93 data = replace_regex(data)
99 data = re.sub(pattern, replacement, data, flags=re.M)
100 94
101 # If the only thing that changed was the date, don't refresh. This avoids 95 # If the only thing that changed was the date, don't refresh. This avoids
102 # a lot of noise when only one file actually updates. 96 # a lot of noise when only one file actually updates.
@@ -106,5 +100,25 @@ def main(argv):
106 path.write_text(data) 100 path.write_text(data)
107 101
108 102
103def replace_regex(data):
104 """Replace semantically null regexes in the data.
105
106 Args:
107 data: manpage text.
108
109 Returns:
110 Updated manpage text.
111 """
112 regex = (
113 (r'(It was generated by help2man) [0-9.]+', '\g<1>.'),
114 (r'^\033\[[0-9;]*m([^\033]*)\033\[m', '\g<1>'),
115 (r'^\.IP\n(.*:)\n', '.SS \g<1>\n'),
116 (r'^\.PP\nDescription', '.SH DETAILS'),
117 )
118 for pattern, replacement in regex:
119 data = re.sub(pattern, replacement, data, flags=re.M)
120 return data
121
122
109if __name__ == '__main__': 123if __name__ == '__main__':
110 sys.exit(main(sys.argv[1:])) 124 sys.exit(main(sys.argv[1:]))
diff --git a/tests/test_update_manpages.py b/tests/test_update_manpages.py
new file mode 100644
index 00000000..f0ef72af
--- /dev/null
+++ b/tests/test_update_manpages.py
@@ -0,0 +1,27 @@
1# Copyright 2022 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Unittests for the update_manpages module."""
16
17import unittest
18import tests.update_manpages as um
19
20
21class UpdateManpagesTest(unittest.TestCase):
22 """Tests the update-manpages code."""
23
24 def test_replace_regex(self):
25 """Check that replace_regex works."""
26 data = '\n\033[1mSummary\033[m\n'
27 self.assertEqual(um.replace_regex(data),'\nSummary\n')
diff --git a/tests/update_manpages.py b/tests/update_manpages.py
new file mode 120000
index 00000000..40bbdea7
--- /dev/null
+++ b/tests/update_manpages.py
@@ -0,0 +1 @@
update-manpages \ No newline at end of file