tools/userland-mangler
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Fri, 13 May 2016 17:33:30 -0700
changeset 5983 f10ab5ae99d7
parent 5682 94c0ca64c022
child 7760 4ab84455407c
permissions -rwxr-xr-x
Close of build 99.3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2153
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
     1
#!/usr/bin/python2.7
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     2
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     3
# CDDL HEADER START
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     4
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     8
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    12
# and limitations under the License.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    13
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    19
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    20
# CDDL HEADER END
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    21
#
5682
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5567
diff changeset
    22
94c0ca64c022 15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents: 5567
diff changeset
    23
#
5567
1d593061210b PSARC 2015/428 Normalization of Solaris man page section numbers
John Beck <John.Beck@Oracle.COM>
parents: 5175
diff changeset
    24
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    25
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    26
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    27
# userland-mangler - a file mangling utility
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    28
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    29
#  A simple program to mangle files to conform to Solaris WOS or Consoldation
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    30
#  requirements.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    31
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    32
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    33
import os
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    34
import sys
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    35
import re
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    36
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    37
import pkg.fmri
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    38
import pkg.manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    39
import pkg.actions
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    40
import pkg.elf as elf
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    41
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    42
attribute_oracle_table_header = """
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    43
.\\\" Oracle has added the ARC stability level to this manual page"""
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    44
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    45
attribute_table_header = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    46
.SH ATTRIBUTES
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    47
See
5567
1d593061210b PSARC 2015/428 Normalization of Solaris man page section numbers
John Beck <John.Beck@Oracle.COM>
parents: 5175
diff changeset
    48
.BR attributes (7)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    49
for descriptions of the following attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    50
.sp
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    51
.TS
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    52
box;
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    53
cbp-1 | cbp-1
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    54
l | l .
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    55
ATTRIBUTE TYPE	ATTRIBUTE VALUE """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    56
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    57
attribute_table_availability = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    58
=
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    59
Availability	%s"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    60
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    61
attribute_table_stability = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    62
=
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    63
Stability	%s"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    64
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    65
attribute_table_footer = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    66
.TE 
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    67
.PP
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    68
"""
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    69
def attributes_section_text(availability, stability, modified_date):
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    70
	result = ''
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    71
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    72
	# is there anything to do?
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    73
	if availability is not None or stability is not None:
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    74
		result = attribute_oracle_table_header
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    75
		if modified_date is not None:
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    76
			result += ("\n.\\\" on %s" % modified_date)
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    77
		result += attribute_table_header
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    78
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    79
		if availability is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    80
			result += (attribute_table_availability % availability)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    81
		if stability is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    82
			result += (attribute_table_stability % stability.capitalize())
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    83
		result += attribute_table_footer
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    84
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    85
	return result
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    86
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    87
notes_oracle_comment = """
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    88
.\\\" Oracle has added source availability information to this manual page"""
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    89
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    90
notes_header = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    91
.SH NOTES
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    92
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    93
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    94
notes_community = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    95
Further information about this software can be found on the open source community website at %s.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    96
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    97
notes_source = """
1528
76d0288dce57 16666374 userland misses opensolaris.org very much, but must move on to java.net's love
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 1477
diff changeset
    98
This software was built from source available at https://java.net/projects/solaris-userland.  The original community source was downloaded from  %s
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    99
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   100
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   101
def notes_section_text(header_seen, community, source, modified_date):
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   102
	result = ''
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   103
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   104
	# is there anything to do?
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   105
	if community is not None or source is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   106
		if header_seen == False:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   107
			result += notes_header
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   108
		result += notes_oracle_comment
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   109
		if modified_date is not None:
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   110
			result += ("\n.\\\" on %s" % modified_date)
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   111
		if source is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   112
			result += (notes_source % source)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   113
		if community is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   114
			result += (notes_community % community)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   115
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   116
	return result
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   117
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   118
so_re = re.compile('^\.so.+$', re.MULTILINE)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   119
section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
1477
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   120
TH_re = re.compile('\.TH\s+(?:"[^"]+"|\S+)\s+(\S+)', re.IGNORECASE)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   121
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   122
# mangler.man.stability = (mangler.man.stability)
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   123
# mangler.man.modified_date = (mangler.man.modified-date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   124
# mangler.man.availability = (pkg.fmri)
464
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   125
# mangler.man.source-url = (pkg.source-url)
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   126
# mangler.man.upstream-url = (pkg.upstream-url)
1477
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   127
# mangler.man.rewrite-section = ('true'/'false')   default 'true'
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   128
#
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   129
def mangle_manpage(manifest, action, text):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   130
	# manpages must have a taxonomy defined
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   131
	stability = action.attrs.pop('mangler.man.stability', None)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   132
	if stability is None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   133
		sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   134
		sys.exit(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   135
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   136
	# manpages may have a 'modified date'
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   137
	modified_date = action.attrs.pop('mangler.man.modified-date', None)
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   138
1477
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   139
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   140
        # Rewrite the section in the .TH line to match the section in which
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   141
        # we're delivering it.
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   142
        rewrite_sect = action.attrs.pop('mangler.man.rewrite-section', 'true')
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   143
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   144
	attributes_written = False
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   145
	notes_seen = False
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   146
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   147
	if 'pkg.fmri' in manifest.attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   148
		fmri = pkg.fmri.PkgFmri(manifest.attributes['pkg.fmri'])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   149
		availability = fmri.pkg_name
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   150
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   151
	community = None
464
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   152
	if 'info.upstream-url' in manifest.attributes:
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   153
		community = manifest.attributes['info.upstream-url']
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   154
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   155
	source = None
464
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   156
	if 'info.source-url' in manifest.attributes:
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   157
		source = manifest.attributes['info.source-url']
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   158
	elif 'info.repository-url' in manifest.attributes:
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   159
		source = manifest.attributes['info.repository-url']
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   160
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   161
	# skip reference only pages
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   162
	if so_re.match(text) is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   163
		return text
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   164
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   165
	# tell man that we want tables (and eqn)
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   166
	result = "'\\\" te\n"
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   167
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   168
	# write the orginal data
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   169
	for line in text.split('\n'):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   170
		match = section_re.match(line)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   171
		if match is not None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   172
			section = match.group(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   173
			if section in ['SEE ALSO', 'NOTES']:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   174
				if attributes_written == False:
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   175
					result += attributes_section_text(
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   176
								 availability,
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   177
								 stability,
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   178
								 modified_date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   179
					attributes_written = True
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   180
				if section == 'NOTES':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   181
					notes_seen = True
1477
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   182
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   183
                match = TH_re.match(line)
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   184
                if match and rewrite_sect.lower() == "true":
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   185
                        # Use the section defined by the filename, rather than
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   186
                        # the directory in which it sits.
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   187
                        sect = os.path.splitext(action.attrs["path"])[1][1:]
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   188
                        line = line[:match.span(1)[0]] + sect + \
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   189
                            line[match.span(1)[1]:]
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   190
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   191
		result += ("%s\n" % line)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   192
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   193
	if attributes_written == False:
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   194
		result += attributes_section_text(availability, stability,
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   195
		    modified_date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   196
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   197
	result += notes_section_text(notes_seen, community, source,
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   198
	    modified_date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   199
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   200
	return result
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   201
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   202
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   203
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   204
# mangler.elf.strip = (true|false)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   205
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   206
def mangle_elf(manifest, action, src, dest):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   207
	pass
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   208
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   209
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   210
# mangler.script.file-magic =
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   211
#
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   212
def mangle_script(manifest, action, text):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   213
	return text
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   214
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   215
#
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   216
# mangler.strip_cddl = false
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   217
#
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   218
def mangle_cddl(manifest, action, text):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   219
	strip_cddl = action.attrs.pop('mangler.strip_cddl', 'true')
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   220
	if strip_cddl is 'false':
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   221
		return text
2171
b7344f27cbbc 15766313 SUNBT7129916 ntp man pages have blank space at the top
Jan Noha <jan.noha@oracle.com>
parents: 2153
diff changeset
   222
	cddl_re = re.compile('^[^\n]*CDDL HEADER START.+CDDL HEADER END[^\n]*\n',
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   223
			     re.MULTILINE|re.DOTALL)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   224
	return cddl_re.sub('', text)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   225
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   226
def mangle_path(manifest, action, src, dest):
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   227
	if elf.is_elf_object(src):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   228
		mangle_elf(manifest, action, src, dest)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   229
	else:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   230
		# a 'text' document (script, man page, config file, ...
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   231
		ifp = open(src, 'r')
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   232
		text = ifp.read()
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   233
		ifp.close()
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   234
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   235
		# remove the CDDL from files
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   236
		result = mangle_cddl(manifest, action, text)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   237
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   238
		if 'facet.doc.man' in action.attrs:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   239
		 	result = mangle_manpage(manifest, action, result)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   240
		elif 'mode' in action.attrs and int(action.attrs['mode'], 8) & 0111 != 0:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   241
			result = mangle_script(manifest, action, result)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   242
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   243
		if text != result:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   244
			destdir = os.path.dirname(dest)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   245
			if not os.path.exists(destdir):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   246
				os.makedirs(destdir)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   247
			with open(dest, 'w') as ofp:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   248
			    ofp.write(result)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   249
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   250
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   251
# mangler.bypass = (true|false)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   252
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   253
def mangle_paths(manifest, search_paths, destination):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   254
	for action in manifest.gen_actions_by_type("file"):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   255
		bypass = action.attrs.pop('mangler.bypass', 'false').lower()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   256
		if bypass == 'true':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   257
			continue
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   258
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   259
		path = None
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   260
		if 'path' in action.attrs:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   261
			path = action.attrs['path']
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   262
		if action.hash and action.hash != 'NOHASH':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   263
			path = action.hash
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   264
		if not path:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   265
			continue
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   266
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   267
		if not os.path.exists(destination):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   268
			os.makedirs(destination)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   269
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   270
		dest = os.path.join(destination, path)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   271
		for directory in search_paths:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   272
			if directory != destination:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   273
				src = os.path.join(directory, path)
452
ef9282f63da3 7067302 no more CDDL'ng in Userland ('fix' path check)
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 448
diff changeset
   274
				if os.path.isfile(src):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   275
					mangle_path(manifest, action, src, dest)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   276
					break
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   277
2153
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   278
def mangle_manifest(manifest):
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   279
	# Check for file content and remove tpno data and license actions if
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   280
	# there is no content in the package that can be licensed.
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   281
	manifest_has_file_content = False
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   282
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   283
	for action in manifest.gen_actions_by_type("file"):
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   284
		manifest_has_file_content = True
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   285
		break
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   286
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   287
	if not manifest_has_file_content:
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   288
		# search for and remove 'set name=com.oracle.info.tpno ...'
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   289
		for action in manifest.gen_actions_by_type("set"):
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   290
			if (action.attrs["name"] == "com.oracle.info.tpno"):
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   291
				manifest.actions.remove(action)
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   292
		for action in manifest.gen_actions_by_type("license"):
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   293
			manifest.actions.remove(action)
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   294
4973
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   295
	# Check for pkg.obsolete and if found, remove any depend actions.
5175
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   296
	# Also remove any require dependency on the release/evalauation
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   297
	# package for renamed packages.
4973
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   298
	manifest_is_obsolete = False
5175
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   299
	manifest_is_renamed = False
4973
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   300
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   301
	for action in manifest.gen_actions_by_type("set"):
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   302
		if (action.attrs["name"] == "pkg.obsolete" and
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   303
		    action.attrs["value"] == "true"):
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   304
			manifest_is_obsolete = True
5175
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   305
		if (action.attrs["name"] == "pkg.renamed" and
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   306
		    action.attrs["value"] == "true"):
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   307
			manifest_is_renamed = True
4973
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   308
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   309
	if manifest_is_obsolete:
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   310
		for action in manifest.gen_actions_by_type("depend"):
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   311
			manifest.actions.remove(action)
be26c0c14fa7 21960309 Userland mangler should drop depend actions from obsolete packages
John Beck <John.Beck@Oracle.COM>
parents: 2171
diff changeset
   312
5175
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   313
	if manifest_is_renamed:
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   314
		for action in manifest.gen_actions_by_type("depend"):
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   315
			if (action.attrs["type"] == "require" and
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   316
			    action.attrs["fmri"] == "release/evaluation"):
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   317
				manifest.actions.remove(action)
c63cda9960d4 22265690 require dependency on release/evaluation should be dropped for renamed packages
John Beck <John.Beck@Oracle.COM>
parents: 4973
diff changeset
   318
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   319
def load_manifest(manifest_file):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   320
	manifest = pkg.manifest.Manifest()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   321
	manifest.set_content(pathname=manifest_file)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   322
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   323
	return manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   324
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   325
def usage():
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   326
	print "Usage: %s [-m|--manifest (file)] [-d|--search-directory (dir)] [-D|--destination (dir)] " % (sys.argv[0].split('/')[-1])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   327
	sys.exit(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   328
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   329
def main():
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   330
	import getopt
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   331
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   332
	# FLUSH STDOUT 
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   333
	sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   334
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   335
	search_paths = []
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   336
	destination = None
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   337
	manifests = []
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   338
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   339
	try:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   340
		opts, args = getopt.getopt(sys.argv[1:], "D:d:m:",
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   341
			["destination=", "search-directory=", "manifest="])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   342
	except getopt.GetoptError, err:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   343
		print str(err)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   344
		usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   345
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   346
	for opt, arg in opts:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   347
		if opt in [ "-D", "--destination" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   348
			destination = arg
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   349
		elif opt in [ "-d", "--search-directory" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   350
			search_paths.append(arg)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   351
		elif opt in [ "-m", "--manifest" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   352
			try:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   353
				manifest = load_manifest(arg)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   354
			except IOError, err:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   355
				print "oops, %s: %s" % (arg, str(err))
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   356
				usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   357
			else:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   358
				manifests.append(manifest)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   359
		else:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   360
			usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   361
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   362
	if destination == None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   363
		usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   364
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   365
	for manifest in manifests:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   366
		mangle_paths(manifest, search_paths, destination)
2153
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   367
		mangle_manifest(manifest)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   368
		print manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   369
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   370
	sys.exit(0)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   371
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   372
if __name__ == "__main__":
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   373
	main()