tools/userland-mangler
author Rich Burridge <rich.burridge@oracle.com>
Sat, 09 May 2015 12:45:23 -0700
changeset 4266 bcfdeff915c4
parent 2171 b7344f27cbbc
child 4973 be26c0c14fa7
permissions -rwxr-xr-x
21056705 libgsl needs to deliver both 32-bit and 64-bit gsl-config scripts
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
#
2153
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
    22
# Copyright (c) 2011, 2014, 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
    23
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    24
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    25
# userland-mangler - a file mangling utility
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
#  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
    28
#  requirements.
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    29
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    30
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    31
import os
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    32
import sys
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    33
import re
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    34
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    35
import pkg.fmri
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    36
import pkg.manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    37
import pkg.actions
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    38
import pkg.elf as elf
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    39
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    40
attribute_oracle_table_header = """
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    41
.\\\" 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
    42
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    43
attribute_table_header = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    44
.SH ATTRIBUTES
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    45
See
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    46
.BR attributes (5)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    47
for descriptions of the following attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    48
.sp
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    49
.TS
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    50
box;
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    51
cbp-1 | cbp-1
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    52
l | l .
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    53
ATTRIBUTE TYPE	ATTRIBUTE VALUE """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    54
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    55
attribute_table_availability = """
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
Availability	%s"""
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
attribute_table_stability = """
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
Stability	%s"""
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
attribute_table_footer = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    64
.TE 
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    65
.PP
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    66
"""
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    67
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
    68
	result = ''
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    69
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    70
	# is there anything to do?
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    71
	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
    72
		result = attribute_oracle_table_header
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    73
		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
    74
			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
    75
		result += attribute_table_header
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    76
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    77
		if availability is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    78
			result += (attribute_table_availability % availability)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    79
		if stability 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_stability % stability.capitalize())
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    81
		result += attribute_table_footer
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    82
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    83
	return result
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    84
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    85
notes_oracle_comment = """
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    86
.\\\" 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
    87
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    88
notes_header = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    89
.SH NOTES
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    90
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    91
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    92
notes_community = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    93
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
    94
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    95
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
    96
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
    97
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    98
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
    99
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
   100
	result = ''
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   101
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   102
	# is there anything to do?
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   103
	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
   104
		if header_seen == False:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   105
			result += notes_header
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   106
		result += notes_oracle_comment
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   107
		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
   108
			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
   109
		if source is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   110
			result += (notes_source % source)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   111
		if community is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   112
			result += (notes_community % community)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   113
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   114
	return result
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
so_re = re.compile('^\.so.+$', re.MULTILINE)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   117
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
   118
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
   119
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   120
# 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
   121
# 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
   122
# mangler.man.availability = (pkg.fmri)
464
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   123
# mangler.man.source-url = (pkg.source-url)
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   124
# 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
   125
# 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
   126
#
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   127
def mangle_manpage(manifest, action, text):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   128
	# manpages must have a taxonomy defined
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   129
	stability = action.attrs.pop('mangler.man.stability', None)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   130
	if stability is None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   131
		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
   132
		sys.exit(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   133
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   134
	# 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
   135
	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
   136
1477
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   137
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   138
        # 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
   139
        # we're delivering it.
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   140
        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
   141
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   142
	attributes_written = False
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   143
	notes_seen = False
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   144
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   145
	if 'pkg.fmri' in manifest.attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   146
		fmri = pkg.fmri.PkgFmri(manifest.attributes['pkg.fmri'])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   147
		availability = fmri.pkg_name
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   148
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   149
	community = None
464
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   150
	if 'info.upstream-url' in manifest.attributes:
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   151
		community = manifest.attributes['info.upstream-url']
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   152
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   153
	source = None
464
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   154
	if 'info.source-url' in manifest.attributes:
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   155
		source = manifest.attributes['info.source-url']
08f94c414553 7073736 need to turn _ into -
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 452
diff changeset
   156
	elif 'info.repository-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.repository-url']
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   158
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   159
	# skip reference only pages
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   160
	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
   161
		return text
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   162
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   163
	# 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
   164
	result = "'\\\" te\n"
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   165
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   166
	# write the orginal data
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   167
	for line in text.split('\n'):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   168
		match = section_re.match(line)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   169
		if match is not None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   170
			section = match.group(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   171
			if section in ['SEE ALSO', 'NOTES']:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   172
				if attributes_written == False:
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   173
					result += attributes_section_text(
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   174
								 availability,
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   175
								 stability,
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   176
								 modified_date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   177
					attributes_written = True
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   178
				if section == 'NOTES':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   179
					notes_seen = True
1477
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   180
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   181
                match = TH_re.match(line)
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   182
                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
   183
                        # 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
   184
                        # 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
   185
                        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
   186
                        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
   187
                            line[match.span(1)[1]:]
5e1a845aef5f 15732538 SUNBT7073773 mangler needs to renumber man pages
Rich Burridge <rich.burridge@oracle.com>
parents: 988
diff changeset
   188
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   189
		result += ("%s\n" % line)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   190
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   191
	if attributes_written == False:
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   192
		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
   193
		    modified_date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   194
988
6c55a0653898 7186815 ncftp needs TPNO and license file modifications
Mike Sullivan <Mike.Sullivan@Oracle.COM>
parents: 464
diff changeset
   195
	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
   196
	    modified_date)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   197
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   198
	return result
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   199
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   200
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
# mangler.elf.strip = (true|false)
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
def mangle_elf(manifest, action, src, dest):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   205
	pass
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   206
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   207
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   208
# mangler.script.file-magic =
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   209
#
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   210
def mangle_script(manifest, action, text):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   211
	return text
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   212
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   213
#
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   214
# mangler.strip_cddl = false
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
def mangle_cddl(manifest, action, text):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   217
	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
   218
	if strip_cddl is 'false':
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   219
		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
   220
	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
   221
			     re.MULTILINE|re.DOTALL)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   222
	return cddl_re.sub('', text)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   223
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   224
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
   225
	if elf.is_elf_object(src):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   226
		mangle_elf(manifest, action, src, dest)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   227
	else:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   228
		# 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
   229
		ifp = open(src, 'r')
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   230
		text = ifp.read()
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   231
		ifp.close()
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   232
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   233
		# remove the CDDL from files
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   234
		result = mangle_cddl(manifest, action, text)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   235
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   236
		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
   237
		 	result = mangle_manpage(manifest, action, result)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   238
		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
   239
			result = mangle_script(manifest, action, result)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   240
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   241
		if text != result:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   242
			destdir = os.path.dirname(dest)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   243
			if not os.path.exists(destdir):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   244
				os.makedirs(destdir)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   245
			with open(dest, 'w') as ofp:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   246
			    ofp.write(result)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   247
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   248
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   249
# mangler.bypass = (true|false)
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
def mangle_paths(manifest, search_paths, destination):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   252
	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
   253
		bypass = action.attrs.pop('mangler.bypass', 'false').lower()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   254
		if bypass == 'true':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   255
			continue
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   256
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   257
		path = None
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   258
		if 'path' in action.attrs:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   259
			path = action.attrs['path']
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   260
		if action.hash and action.hash != 'NOHASH':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   261
			path = action.hash
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   262
		if not path:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   263
			continue
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   264
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   265
		if not os.path.exists(destination):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   266
			os.makedirs(destination)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   267
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   268
		dest = os.path.join(destination, path)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   269
		for directory in search_paths:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   270
			if directory != destination:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   271
				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
   272
				if os.path.isfile(src):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   273
					mangle_path(manifest, action, src, dest)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   274
					break
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   275
2153
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   276
def mangle_manifest(manifest):
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   277
	# 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
   278
	# 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
   279
	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
   280
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   281
	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
   282
		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
   283
		break
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   284
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   285
	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
   286
		# 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
   287
		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
   288
			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
   289
				manifest.actions.remove(action)
f64a9f4ada4d 19799164 content free packages shouldn't have a TPNO.
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 1528
diff changeset
   290
		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
   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
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   293
def load_manifest(manifest_file):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   294
	manifest = pkg.manifest.Manifest()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   295
	manifest.set_content(pathname=manifest_file)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   296
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   297
	return manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   298
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   299
def usage():
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   300
	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
   301
	sys.exit(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   302
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   303
def main():
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   304
	import getopt
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   305
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   306
	# FLUSH STDOUT 
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   307
	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
   308
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   309
	search_paths = []
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   310
	destination = None
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   311
	manifests = []
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   312
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   313
	try:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   314
		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
   315
			["destination=", "search-directory=", "manifest="])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   316
	except getopt.GetoptError, err:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   317
		print str(err)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   318
		usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   319
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   320
	for opt, arg in opts:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   321
		if opt in [ "-D", "--destination" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   322
			destination = arg
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   323
		elif opt in [ "-d", "--search-directory" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   324
			search_paths.append(arg)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   325
		elif opt in [ "-m", "--manifest" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   326
			try:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   327
				manifest = load_manifest(arg)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   328
			except IOError, err:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   329
				print "oops, %s: %s" % (arg, str(err))
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   330
				usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   331
			else:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   332
				manifests.append(manifest)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   333
		else:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   334
			usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   335
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   336
	if destination == None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   337
		usage()
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
	for manifest in manifests:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   340
		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
   341
		mangle_manifest(manifest)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   342
		print manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   343
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   344
	sys.exit(0)
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
if __name__ == "__main__":
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   347
	main()