blob: 45a881953f02665d8f69526f0732e1df3e39ad76 [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Modifies a list of input paths to produce a list of output paths.
The user can specify a list of paths as well as specific path transformations
(e.g. replace directory or replace extension) and this script will return a
list of processed output paths.
import argparse
import os
import sys
import textwrap
def ConvertPaths(input_paths, output_directory, output_prefix,
output_extension, forward_slashes):
"""The script's core function."""
def ConvertPath(path):
output_path = path
if output_directory:
output_path = os.path.join(output_directory,
if output_prefix:
output_path = os.path.join(os.path.dirname(output_path),
output_prefix + os.path.basename(output_path))
if output_extension:
output_path = (os.path.splitext(output_path)[0] +
os.extsep + output_extension)
if forward_slashes:
output_path = output_path.replace('\\', '/')
return output_path
# If an element in the list of input paths contains a space, treat that as
# a separater for more input paths and expand the list of input paths.
# Gyp does not make it easy to marshall paramaters into a Python script so
# this functionality is for working around that problem.
expanded_input_paths = []
for x in input_paths:
expanded_input_paths += x.split(' ')
return [ConvertPath(x) for x in expanded_input_paths]
def DoMain(argv):
parser = argparse.ArgumentParser(
parser.add_argument('-d', '--output_directory',
help=('If specified, will replace all input path '
'directories with the one specified by this '
parser.add_argument('-e', '--output_extension',
help=('If specified, will replace all input path '
'extensions with the one specified by this '
parser.add_argument('-p', '--output_prefix',
help=('If specified, will prepend the string '
'specified in the parameter to the filename.'))
parser.add_argument('-s', '--forward_slashes',
help=('Set this flag if you would like all output '
'paths to contain forward slashes, even on '
'Windows. This is useful if you are calling this '
'from Gyp which expects forward slashes.'))
help=('A list of paths that will be modified as '
'specified by the other options.'),
args = parser.parse_args(argv)
return ' '.join(ConvertPaths(args.input_paths,
if __name__ == '__main__':
print DoMain(sys.argv[1:])