17 # fields enclosed by brackets "[]" replaced with your own identifying |
17 # fields enclosed by brackets "[]" replaced with your own identifying |
18 # information: Portions Copyright [yyyy] [name of copyright owner] |
18 # information: Portions Copyright [yyyy] [name of copyright owner] |
19 # |
19 # |
20 # CDDL HEADER END |
20 # CDDL HEADER END |
21 # |
21 # |
22 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
22 # Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
23 # |
23 # |
24 # |
24 # |
25 # userland-mangler - a file mangling utility |
25 # userland-mangler - a file mangling utility |
26 # |
26 # |
27 # A simple program to mangle files to conform to Solaris WOS or Consoldation |
27 # A simple program to mangle files to conform to Solaris WOS or Consoldation |
113 |
113 |
114 return result |
114 return result |
115 |
115 |
116 so_re = re.compile('^\.so.+$', re.MULTILINE) |
116 so_re = re.compile('^\.so.+$', re.MULTILINE) |
117 section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE) |
117 section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE) |
|
118 TH_re = re.compile('\.TH\s+(?:"[^"]+"|\S+)\s+(\S+)', re.IGNORECASE) |
118 # |
119 # |
119 # mangler.man.stability = (mangler.man.stability) |
120 # mangler.man.stability = (mangler.man.stability) |
120 # mangler.man.modified_date = (mangler.man.modified-date) |
121 # mangler.man.modified_date = (mangler.man.modified-date) |
121 # mangler.man.availability = (pkg.fmri) |
122 # mangler.man.availability = (pkg.fmri) |
122 # mangler.man.source-url = (pkg.source-url) |
123 # mangler.man.source-url = (pkg.source-url) |
123 # mangler.man.upstream-url = (pkg.upstream-url) |
124 # mangler.man.upstream-url = (pkg.upstream-url) |
|
125 # mangler.man.rewrite-section = ('true'/'false') default 'true' |
124 # |
126 # |
125 def mangle_manpage(manifest, action, text): |
127 def mangle_manpage(manifest, action, text): |
126 # manpages must have a taxonomy defined |
128 # manpages must have a taxonomy defined |
127 stability = action.attrs.pop('mangler.man.stability', None) |
129 stability = action.attrs.pop('mangler.man.stability', None) |
128 if stability is None: |
130 if stability is None: |
129 sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action) |
131 sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action) |
130 sys.exit(1) |
132 sys.exit(1) |
131 |
133 |
132 # manpages may have a 'modified date' |
134 # manpages may have a 'modified date' |
133 modified_date = action.attrs.pop('mangler.man.modified-date', None) |
135 modified_date = action.attrs.pop('mangler.man.modified-date', None) |
|
136 |
|
137 |
|
138 # Rewrite the section in the .TH line to match the section in which |
|
139 # we're delivering it. |
|
140 rewrite_sect = action.attrs.pop('mangler.man.rewrite-section', 'true') |
134 |
141 |
135 attributes_written = False |
142 attributes_written = False |
136 notes_seen = False |
143 notes_seen = False |
137 |
144 |
138 if 'pkg.fmri' in manifest.attributes: |
145 if 'pkg.fmri' in manifest.attributes: |
168 stability, |
175 stability, |
169 modified_date) |
176 modified_date) |
170 attributes_written = True |
177 attributes_written = True |
171 if section == 'NOTES': |
178 if section == 'NOTES': |
172 notes_seen = True |
179 notes_seen = True |
|
180 |
|
181 match = TH_re.match(line) |
|
182 if match and rewrite_sect.lower() == "true": |
|
183 # Use the section defined by the filename, rather than |
|
184 # the directory in which it sits. |
|
185 sect = os.path.splitext(action.attrs["path"])[1][1:] |
|
186 line = line[:match.span(1)[0]] + sect + \ |
|
187 line[match.span(1)[1]:] |
|
188 |
173 result += ("%s\n" % line) |
189 result += ("%s\n" % line) |
174 |
190 |
175 if attributes_written == False: |
191 if attributes_written == False: |
176 result += attributes_section_text(availability, stability, |
192 result += attributes_section_text(availability, stability, |
177 modified_date) |
193 modified_date) |