userland-mangler revision 379
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# CDDL HEADER START
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# The contents of this file are subject to the terms of the
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# Common Development and Distribution License (the "License").
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# You may not use this file except in compliance with the License.
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# See the License for the specific language governing permissions
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# and limitations under the License.
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# When distributing Covered Code, include this CDDL HEADER in each
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# If applicable, add the following below this CDDL HEADER, with the
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# fields enclosed by brackets "[]" replaced with your own identifying
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# information: Portions Copyright [yyyy] [name of copyright owner]
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# CDDL HEADER END
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# userland-mangler - a file mangling utility
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence# A simple program to mangle files to conform to Solaris WOS or Consoldation
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington# requirements.
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington.SH ATTRIBUTES
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington.BR attributes (5)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonfor descriptions of the following attributes:
01d202be8fb07c010388eada31635e40ae3bffe5Brian WellingtonATTRIBUTE TYPE ATTRIBUTE VALUE """
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian WellingtonAvailability %s"""
01d202be8fb07c010388eada31635e40ae3bffe5Brian WellingtonStability %s"""
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondef write_attributes_section(ofp, availability, stability):
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # is there anything to do?
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if availability is None and stability is None:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # append the ATTRIBUTES section
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ofp.write(attribute_table_availability % availability)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ofp.write(attribute_table_stability % stability.capitalize())
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian WellingtonFurther information about this software can be found on the open source community website at %s.
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian WellingtonThis software was built from source available at http://opensolaris.org/. The original community source was downloaded from %s
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtondef write_notes_section(ofp, header_seen, community, source):
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # is there anything to do?
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # append the NOTES section
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtonsection_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# mangler.man.stability = (mangler.man.stability)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington# mangler.man.upstream_url = (pkg.upstream_url)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtondef mangle_manpage(manifest, action, src, dest):
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # manpages must have a taxonomy defined
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington stability = action.attrs.pop('mangler.man.stability', None)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington fmri = pkg.fmri.PkgFmri(manifest.attributes['pkg.fmri'])
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if 'info.upstream_url' in manifest.attributes:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington community = manifest.attributes['info.upstream_url']
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if 'info.source_url' in manifest.attributes:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington source = manifest.attributes['info.source_url']
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington elif 'info.repository_url' in manifest.attributes:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington source = manifest.attributes['info.repository_url']
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # create a directory to write to
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # read the source document
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # skip reference only pages
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # open a destination
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington # tell man that we want tables (and eqn)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # write the orginal data
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington write_attributes_section(ofp, availability, stability)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington write_notes_section(ofp, notes_seen, community, source)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtondef mangle_elf(manifest, action, src, dest):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtondef mangle_script(manifest, action, src, dest):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtondef mangle_path(manifest, action, src, dest):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington mangle_manpage(manifest, action, src, dest)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington elif 'mode' in action.attrs and int(action.attrs['mode'], 8) & 0111 != 0:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondef mangle_paths(manifest, search_paths, destination):
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington for action in manifest.gen_actions_by_type("file"):
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington bypass = action.attrs.pop('mangler.bypass', 'false').lower()
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if action.hash and action.hash != 'NOHASH':
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington manifest.set_content(pathname=manifest_file)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington print "Usage: %s [-m|--manifest (file)] [-d|--search-directory (dir)] [-D|--destination (dir)] " % (sys.argv[0].split('/')[-1])
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # FLUSH STDOUT
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington opts, args = getopt.getopt(sys.argv[1:], "D:d:m:",
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ["destination=", "search-directory=", "manifest="])
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington elif opt in [ "-d", "--search-directory" ]: