tools/userland-mangler
changeset 988 6c55a0653898
parent 464 08f94c414553
child 1477 5e1a845aef5f
child 2855 576d5a7857b7
equal deleted inserted replaced
987:810b92005f34 988:6c55a0653898
    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, Oracle and/or its affiliates. All rights reserved.
    22 # Copyright (c) 2011, 2012, 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
    34 
    34 
    35 import pkg.fmri
    35 import pkg.fmri
    36 import pkg.manifest
    36 import pkg.manifest
    37 import pkg.actions
    37 import pkg.actions
    38 import pkg.elf as elf
    38 import pkg.elf as elf
       
    39 
       
    40 attribute_oracle_table_header = """
       
    41 .\\\" Oracle has added the ARC stability level to this manual page"""
    39 
    42 
    40 attribute_table_header = """
    43 attribute_table_header = """
    41 .SH ATTRIBUTES
    44 .SH ATTRIBUTES
    42 See
    45 See
    43 .BR attributes (5)
    46 .BR attributes (5)
    59 
    62 
    60 attribute_table_footer = """
    63 attribute_table_footer = """
    61 .TE 
    64 .TE 
    62 .PP
    65 .PP
    63 """
    66 """
    64 def attributes_section_text(availability, stability):
    67 def attributes_section_text(availability, stability, modified_date):
    65 	result = ''
    68 	result = ''
    66 
    69 
    67 	# is there anything to do?
    70 	# is there anything to do?
    68 	if availability is not None or stability is not None:
    71 	if availability is not None or stability is not None:
    69 		result = attribute_table_header
    72 		result = attribute_oracle_table_header
       
    73 		if modified_date is not None:
       
    74 			result += ("\n.\\\" on %s" % modified_date)
       
    75 		result += attribute_table_header
    70 
    76 
    71 		if availability is not None:
    77 		if availability is not None:
    72 			result += (attribute_table_availability % availability)
    78 			result += (attribute_table_availability % availability)
    73 		if stability is not None:
    79 		if stability is not None:
    74 			result += (attribute_table_stability % stability.capitalize())
    80 			result += (attribute_table_stability % stability.capitalize())
    75 		result += attribute_table_footer
    81 		result += attribute_table_footer
    76 
    82 
    77 	return result
    83 	return result
       
    84 
       
    85 notes_oracle_comment = """
       
    86 .\\\" Oracle has added source availability information to this manual page"""
    78 
    87 
    79 notes_header = """
    88 notes_header = """
    80 .SH NOTES
    89 .SH NOTES
    81 """
    90 """
    82 
    91 
    85 """
    94 """
    86 notes_source = """
    95 notes_source = """
    87 This software was built from source available at http://opensolaris.org/.  The original community source was downloaded from  %s
    96 This software was built from source available at http://opensolaris.org/.  The original community source was downloaded from  %s
    88 """
    97 """
    89 
    98 
    90 def notes_section_text(header_seen, community, source):
    99 def notes_section_text(header_seen, community, source, modified_date):
    91 	result = ''
   100 	result = ''
    92 
   101 
    93 	# is there anything to do?
   102 	# is there anything to do?
    94 	if community is not None or source is not None:
   103 	if community is not None or source is not None:
    95 		if header_seen == False:
   104 		if header_seen == False:
    96 			result += notes_header
   105 			result += notes_header
       
   106 		result += notes_oracle_comment
       
   107 		if modified_date is not None:
       
   108 			result += ("\n.\\\" on %s" % modified_date)
    97 		if source is not None:
   109 		if source is not None:
    98 			result += (notes_source % source)
   110 			result += (notes_source % source)
    99 		if community is not None:
   111 		if community is not None:
   100 			result += (notes_community % community)
   112 			result += (notes_community % community)
   101 
   113 
   103 
   115 
   104 so_re = re.compile('^\.so.+$', re.MULTILINE)
   116 so_re = re.compile('^\.so.+$', re.MULTILINE)
   105 section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
   117 section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
   106 #
   118 #
   107 # mangler.man.stability = (mangler.man.stability)
   119 # mangler.man.stability = (mangler.man.stability)
       
   120 # mangler.man.modified_date = (mangler.man.modified-date)
   108 # mangler.man.availability = (pkg.fmri)
   121 # mangler.man.availability = (pkg.fmri)
   109 # mangler.man.source-url = (pkg.source-url)
   122 # mangler.man.source-url = (pkg.source-url)
   110 # mangler.man.upstream-url = (pkg.upstream-url)
   123 # mangler.man.upstream-url = (pkg.upstream-url)
   111 #
   124 #
   112 def mangle_manpage(manifest, action, text):
   125 def mangle_manpage(manifest, action, text):
   113 	# manpages must have a taxonomy defined
   126 	# manpages must have a taxonomy defined
   114 	stability = action.attrs.pop('mangler.man.stability', None)
   127 	stability = action.attrs.pop('mangler.man.stability', None)
   115 	if stability is None:
   128 	if stability is None:
   116 		sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action)
   129 		sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action)
   117 		sys.exit(1)
   130 		sys.exit(1)
       
   131 
       
   132 	# manpages may have a 'modified date'
       
   133 	modified_date = action.attrs.pop('mangler.man.modified-date', None)
   118 
   134 
   119 	attributes_written = False
   135 	attributes_written = False
   120 	notes_seen = False
   136 	notes_seen = False
   121 
   137 
   122 	if 'pkg.fmri' in manifest.attributes:
   138 	if 'pkg.fmri' in manifest.attributes:
   147 			section = match.group(1)
   163 			section = match.group(1)
   148 			if section in ['SEE ALSO', 'NOTES']:
   164 			if section in ['SEE ALSO', 'NOTES']:
   149 				if attributes_written == False:
   165 				if attributes_written == False:
   150 					result += attributes_section_text(
   166 					result += attributes_section_text(
   151 								 availability,
   167 								 availability,
   152 								 stability)
   168 								 stability,
       
   169 								 modified_date)
   153 					attributes_written = True
   170 					attributes_written = True
   154 				if section == 'NOTES':
   171 				if section == 'NOTES':
   155 					notes_seen = True
   172 					notes_seen = True
   156 		result += ("%s\n" % line)
   173 		result += ("%s\n" % line)
   157 
   174 
   158 	if attributes_written == False:
   175 	if attributes_written == False:
   159 		result += attributes_section_text(availability, stability)
   176 		result += attributes_section_text(availability, stability,
   160 
   177 		    modified_date)
   161 	result += notes_section_text(notes_seen, community, source)
   178 
       
   179 	result += notes_section_text(notes_seen, community, source,
       
   180 	    modified_date)
   162 
   181 
   163 	return result
   182 	return result
   164 
   183 
   165 
   184 
   166 #
   185 #