userland-mangler revision 379
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#!/usr/bin/python2.6
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley#
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# CDDL HEADER START
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley#
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#
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# or http://www.opensolaris.org/os/licensing.
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# See the License for the specific language governing permissions
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley# and limitations under the License.
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley#
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]
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# CDDL HEADER END
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# userland-mangler - a file mangling utility
99910383666b1942a64a9b76eb5b7c0c04b23162Andreas Gustafsson#
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence# A simple program to mangle files to conform to Solaris WOS or Consoldation
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington# requirements.
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonimport os
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonimport sys
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtonimport re
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtonimport pkg.fmri
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtonimport pkg.manifest
71f5ad0517325eb32ecbee112206277c6277af87Brian Wellingtonimport pkg.actions
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonimport pkg.elf as elf
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonattribute_table_header = """
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington.SH ATTRIBUTES
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian WellingtonSee
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington.BR attributes (5)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonfor descriptions of the following attributes:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington.sp
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington.TS
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonbox;
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtoncbp-1 | cbp-1
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonl | l .
01d202be8fb07c010388eada31635e40ae3bffe5Brian WellingtonATTRIBUTE TYPE ATTRIBUTE VALUE """
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonattribute_table_availability = """
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington=
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian WellingtonAvailability %s"""
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonattribute_table_stability = """
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington=
01d202be8fb07c010388eada31635e40ae3bffe5Brian WellingtonStability %s"""
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtonattribute_table_footer = """
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington.TE
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington.PP
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington"""
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 return
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # append the ATTRIBUTES section
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ofp.write(attribute_table_header)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if availability is not None:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ofp.write(attribute_table_availability % availability)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if stability is not None:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ofp.write(attribute_table_stability % stability.capitalize())
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ofp.write(attribute_table_footer)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtonnotes_header = """
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington.SH NOTES
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington"""
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtonnotes_community = """
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian WellingtonFurther information about this software can be found on the open source community website at %s.
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington"""
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtonnotes_source = """
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian WellingtonThis software was built from source available at http://opensolaris.org/. The original community source was downloaded from %s
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington"""
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtondef write_notes_section(ofp, header_seen, community, source):
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # is there anything to do?
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if community is None and source is None:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington return
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # append the NOTES section
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if header_seen == False:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ofp.write(notes_header)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if source is not None:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ofp.write(notes_source % source)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if community is not None:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ofp.write(notes_community % community)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtonsection_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# mangler.man.stability = (mangler.man.stability)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington# mangler.man.availability = (pkg.fmri)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington# mangler.man.source_url = (pkg.source_url)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington# mangler.man.upstream_url = (pkg.upstream_url)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington#
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 if stability is None:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington sys.stderr.write("ERROR: manpage action missing mangler.man.stability: %s" % action)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington sys.exit(1)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington attributes_written = False
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington notes_seen = False
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if 'pkg.fmri' in manifest.attributes:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington fmri = pkg.fmri.PkgFmri(manifest.attributes['pkg.fmri'])
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington availability = fmri.pkg_name
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington community = None
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if 'info.upstream_url' in manifest.attributes:
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington community = manifest.attributes['info.upstream_url']
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington source = None
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
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # create a directory to write to
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington destdir = os.path.dirname(dest)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if not os.path.exists(destdir):
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington os.makedirs(destdir)
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # read the source document
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ifp = open(src, "r")
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington lines = ifp.readlines()
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington ifp.close()
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington # skip reference only pages
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington if lines[0].startswith(".so "):
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington return
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # open a destination
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ofp = open(dest, "w+")
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington # tell man that we want tables (and eqn)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington ofp.write("'\\\" te\n")
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # write the orginal data
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington for line in lines:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington match = section_re.match(line)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if match is not None:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington section = match.group(1)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if section in ['SEE ALSO', 'NOTES']:
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if attributes_written == False:
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington write_attributes_section(ofp,
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington availability,
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington stability)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington attributes_written = True
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if section == 'NOTES':
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington notes_seen = True
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ofp.write(line)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if attributes_written == False:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington write_attributes_section(ofp, availability, stability)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington write_notes_section(ofp, notes_seen, community, source)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ofp.close()
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington# mangler.elf.strip = (true|false)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington#
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtondef mangle_elf(manifest, action, src, dest):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington pass
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington# mangler.script.file-magic =
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington#
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtondef mangle_script(manifest, action, src, dest):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington pass
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtondef mangle_path(manifest, action, src, dest):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if 'facet.doc.man' in action.attrs:
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington mangle_manpage(manifest, action, src, dest)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington elif 'mode' in action.attrs and int(action.attrs['mode'], 8) & 0111 != 0:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if elf.is_elf_object(src):
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington mangle_elf(manifest, action, src, dest)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington else:
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington mangle_script(manifest, action, src, dest)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington# mangler.bypass = (true|false)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington#
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 bypass == 'true':
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington continue
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington path = None
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if 'path' in action.attrs:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington path = action.attrs['path']
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if action.hash and action.hash != 'NOHASH':
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington path = action.hash
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if not path:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington continue
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington dest = os.path.join(destination, path)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington for directory in search_paths:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if directory != destination:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington src = os.path.join(directory, path)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if os.path.exists(src):
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington mangle_path(manifest, action, src, dest)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington break
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondef load_manifest(manifest_file):
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington manifest = pkg.manifest.Manifest()
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington manifest.set_content(pathname=manifest_file)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington return manifest
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondef usage():
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington print "Usage: %s [-m|--manifest (file)] [-d|--search-directory (dir)] [-D|--destination (dir)] " % (sys.argv[0].split('/')[-1])
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington sys.exit(1)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondef main():
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington import getopt
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington # FLUSH STDOUT
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington search_paths = []
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington destination = None
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington manifests = []
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington try:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington opts, args = getopt.getopt(sys.argv[1:], "D:d:m:",
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington ["destination=", "search-directory=", "manifest="])
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington except getopt.GetoptError, err:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington print str(err)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington usage()
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington for opt, arg in opts:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington if opt in [ "-D", "--destination" ]:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington destination = arg
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington elif opt in [ "-d", "--search-directory" ]:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington search_paths.append(arg)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington elif opt in [ "-m", "--manifest" ]:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington try:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington manifest = load_manifest(arg)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington except IOError, err:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington print "oops, %s: %s" % (arg, str(err))
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington usage()
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington else:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington manifests.append(manifest)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington else:
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington usage()
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if destination == None:
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington usage()
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington for manifest in manifests:
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington mangle_paths(manifest, search_paths, destination)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington print manifest
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington sys.exit(0)
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellingtonif __name__ == "__main__":
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington main()
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington