tools/userland-mangler
author Norm Jacobs <Norm.Jacobs@Oracle.COM>
Mon, 01 Aug 2011 15:44:19 -0700
changeset 448 e07a264a6e3d
parent 379 c6a17bba1da3
child 452 ef9282f63da3
permissions -rwxr-xr-x
7067302 no more CDDL'ng in Userland
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     1
#!/usr/bin/python2.6
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
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    22
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    40
attribute_table_header = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    41
.SH ATTRIBUTES
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    42
See
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    43
.BR attributes (5)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    44
for descriptions of the following attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    45
.sp
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    46
.TS
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    47
box;
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    48
cbp-1 | cbp-1
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    49
l | l .
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    50
ATTRIBUTE TYPE	ATTRIBUTE VALUE """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    51
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    52
attribute_table_availability = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    53
=
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    54
Availability	%s"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    55
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    56
attribute_table_stability = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    57
=
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    58
Stability	%s"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    59
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    60
attribute_table_footer = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    61
.TE 
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    62
.PP
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    63
"""
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    64
def attributes_section_text(availability, stability):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    65
	result = ''
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    66
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    67
	# is there anything to do?
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    68
	if availability is not None or stability is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    69
		result = attribute_table_header
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    70
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:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    72
			result += (attribute_table_availability % availability)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    73
		if stability is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    74
			result += (attribute_table_stability % stability.capitalize())
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    75
		result += attribute_table_footer
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
	return result
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    78
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    79
notes_header = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    80
.SH NOTES
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    81
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    82
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    83
notes_community = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    84
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
    85
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    86
notes_source = """
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    87
This software was built from source available at http://opensolaris.org/.  The original community source was downloaded from  %s
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    88
"""
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    89
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    90
def notes_section_text(header_seen, community, source):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    91
	result = ''
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    92
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    93
	# is there anything to do?
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    94
	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
    95
		if header_seen == False:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    96
			result += notes_header
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    97
		if source is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    98
			result += (notes_source % source)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
    99
		if community is not None:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   100
			result += (notes_community % community)
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
	return 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
so_re = re.compile('^\.so.+$', re.MULTILINE)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   105
section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   106
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   107
# mangler.man.stability = (mangler.man.stability)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   108
# mangler.man.availability = (pkg.fmri)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   109
# mangler.man.source_url = (pkg.source_url)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   110
# mangler.man.upstream_url = (pkg.upstream_url)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   111
#
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   112
def mangle_manpage(manifest, action, text):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   113
	# manpages must have a taxonomy defined
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   114
	stability = action.attrs.pop('mangler.man.stability', None)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   115
	if stability is None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   116
		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
   117
		sys.exit(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   118
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   119
	attributes_written = False
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   120
	notes_seen = False
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
	if 'pkg.fmri' in manifest.attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   123
		fmri = pkg.fmri.PkgFmri(manifest.attributes['pkg.fmri'])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   124
		availability = fmri.pkg_name
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   125
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   126
	community = None
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   127
	if 'info.upstream_url' in manifest.attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   128
		community = manifest.attributes['info.upstream_url']
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   129
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   130
	source = None
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   131
	if 'info.source_url' in manifest.attributes:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   132
		source = manifest.attributes['info.source_url']
379
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   133
	elif 'info.repository_url' in manifest.attributes:
c6a17bba1da3 7038754 vim 7.3
Danek Duvall <danek.duvall@oracle.com>
parents: 181
diff changeset
   134
		source = manifest.attributes['info.repository_url']
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   135
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   136
	# skip reference only pages
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   137
	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
   138
		return text
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   139
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   140
	# 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
   141
	result = "'\\\" te\n"
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   142
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   143
	# write the orginal data
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   144
	for line in text.split('\n'):
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   145
		match = section_re.match(line)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   146
		if match is not None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   147
			section = match.group(1)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   148
			if section in ['SEE ALSO', 'NOTES']:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   149
				if attributes_written == False:
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   150
					result += attributes_section_text(
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   151
								 availability,
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   152
								 stability)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   153
					attributes_written = True
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   154
				if section == 'NOTES':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   155
					notes_seen = True
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   156
		result += ("%s\n" % line)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   157
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   158
	if attributes_written == False:
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   159
		result += attributes_section_text(availability, stability)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   160
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   161
	result += notes_section_text(notes_seen, community, source)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   162
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   163
	return result
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
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   166
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   167
# mangler.elf.strip = (true|false)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   168
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   169
def mangle_elf(manifest, action, src, dest):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   170
	pass
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   171
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   172
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   173
# mangler.script.file-magic =
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   174
#
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   175
def mangle_script(manifest, action, text):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   176
	return text
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   177
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   178
#
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   179
# mangler.strip_cddl = false
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   180
#
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   181
def mangle_cddl(manifest, action, text):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   182
	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
   183
	if strip_cddl is 'false':
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   184
		return text
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   185
	cddl_re = re.compile('^[^\n]*CDDL HEADER START.+CDDL HEADER END[^\n]*$',
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   186
			     re.MULTILINE|re.DOTALL)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   187
	return cddl_re.sub('', text)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   188
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   189
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
   190
	if elf.is_elf_object(src):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   191
		mangle_elf(manifest, action, src, dest)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   192
	else:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   193
		# 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
   194
		ifp = open(src, 'r')
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   195
		text = ifp.read()
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   196
		ifp.close()
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   197
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   198
		# remove the CDDL from files
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   199
		result = mangle_cddl(manifest, action, text)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   200
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   201
		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
   202
		 	result = mangle_manpage(manifest, action, result)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   203
		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
   204
			result = mangle_script(manifest, action, result)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   205
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   206
		if text != result:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   207
			destdir = os.path.dirname(dest)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   208
			if not os.path.exists(destdir):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   209
				os.makedirs(destdir)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   210
			with open(dest, 'w') as ofp:
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   211
			    ofp.write(result)
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   212
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   213
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   214
# mangler.bypass = (true|false)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   215
#
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   216
def mangle_paths(manifest, search_paths, destination):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   217
	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
   218
		bypass = action.attrs.pop('mangler.bypass', 'false').lower()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   219
		if bypass == 'true':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   220
			continue
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   221
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   222
		path = None
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   223
		if 'path' in action.attrs:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   224
			path = action.attrs['path']
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   225
		if action.hash and action.hash != 'NOHASH':
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   226
			path = action.hash
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   227
		if not path:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   228
			continue
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   229
448
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   230
		if not os.path.exists(destination):
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   231
			os.makedirs(destination)
e07a264a6e3d 7067302 no more CDDL'ng in Userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 379
diff changeset
   232
181
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   233
		dest = os.path.join(destination, path)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   234
		for directory in search_paths:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   235
			if directory != destination:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   236
				src = os.path.join(directory, path)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   237
				if os.path.exists(src):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   238
					mangle_path(manifest, action, src, dest)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   239
					break
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   240
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   241
def load_manifest(manifest_file):
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   242
	manifest = pkg.manifest.Manifest()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   243
	manifest.set_content(pathname=manifest_file)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   244
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   245
	return manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   246
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   247
def usage():
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   248
	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
   249
	sys.exit(1)
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 main():
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   252
	import getopt
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   253
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   254
	# FLUSH STDOUT 
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   255
	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
   256
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   257
	search_paths = []
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   258
	destination = None
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   259
	manifests = []
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   260
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   261
	try:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   262
		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
   263
			["destination=", "search-directory=", "manifest="])
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   264
	except getopt.GetoptError, err:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   265
		print str(err)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   266
		usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   267
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   268
	for opt, arg in opts:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   269
		if opt in [ "-D", "--destination" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   270
			destination = arg
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   271
		elif opt in [ "-d", "--search-directory" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   272
			search_paths.append(arg)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   273
		elif opt in [ "-m", "--manifest" ]:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   274
			try:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   275
				manifest = load_manifest(arg)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   276
			except IOError, err:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   277
				print "oops, %s: %s" % (arg, str(err))
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   278
				usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   279
			else:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   280
				manifests.append(manifest)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   281
		else:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   282
			usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   283
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   284
	if destination == None:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   285
		usage()
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   286
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   287
	for manifest in manifests:
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   288
		mangle_paths(manifest, search_paths, destination)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   289
		print manifest
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   290
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   291
	sys.exit(0)
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   292
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   293
if __name__ == "__main__":
87e11e685b1f 7003927 userland should postprocess packaged files
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   294
	main()