From c489220d295b64f54d6b66a37a77dc80a21d09e0 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Mon, 4 Mar 2013 19:34:02 +0100 Subject: [PATCH] Bug 737849 - Add a -o/--output option to Preprocessor.py. r=ted --- config/Preprocessor.py | 13 +++++++++++++ js/src/config/Preprocessor.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/config/Preprocessor.py b/config/Preprocessor.py index 9523390f7134..f3061f255b9f 100644 --- a/config/Preprocessor.py +++ b/config/Preprocessor.py @@ -12,6 +12,7 @@ import os import os.path import re from optparse import OptionParser +import errno # hack around win32 mangling our line endings # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443 @@ -151,6 +152,15 @@ class Preprocessor: p = self.getCommandLineParser() (options, args) = p.parse_args(args=args) includes = options.I + if options.output: + dir = os.path.dirname(options.output) + if dir and not os.path.exists(dir): + try: + os.makedirs(dir) + except OSError as error: + if error.errno != errno.EEXIST: + raise + self.out = open(options.output, 'w') if defaultToStdin and len(args) == 0: args = [sys.stdin] includes.extend(args) @@ -195,6 +205,9 @@ class Preprocessor: metavar="VAR", help='Undefine a variable') p.add_option('-F', action='callback', callback=handleF, type="string", metavar="FILTER", help='Enable the specified filter') + p.add_option('-o', '--output', type="string", default=None, + metavar="FILENAME", help='Output to the specified file '+ + 'instead of stdout') p.add_option('--line-endings', action='callback', callback=handleLE, type="string", metavar="[cr|lr|crlf]", help='Use the specified line endings [Default: OS dependent]') diff --git a/js/src/config/Preprocessor.py b/js/src/config/Preprocessor.py index 9523390f7134..f3061f255b9f 100644 --- a/js/src/config/Preprocessor.py +++ b/js/src/config/Preprocessor.py @@ -12,6 +12,7 @@ import os import os.path import re from optparse import OptionParser +import errno # hack around win32 mangling our line endings # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443 @@ -151,6 +152,15 @@ class Preprocessor: p = self.getCommandLineParser() (options, args) = p.parse_args(args=args) includes = options.I + if options.output: + dir = os.path.dirname(options.output) + if dir and not os.path.exists(dir): + try: + os.makedirs(dir) + except OSError as error: + if error.errno != errno.EEXIST: + raise + self.out = open(options.output, 'w') if defaultToStdin and len(args) == 0: args = [sys.stdin] includes.extend(args) @@ -195,6 +205,9 @@ class Preprocessor: metavar="VAR", help='Undefine a variable') p.add_option('-F', action='callback', callback=handleF, type="string", metavar="FILTER", help='Enable the specified filter') + p.add_option('-o', '--output', type="string", default=None, + metavar="FILENAME", help='Output to the specified file '+ + 'instead of stdout') p.add_option('--line-endings', action='callback', callback=handleLE, type="string", metavar="[cr|lr|crlf]", help='Use the specified line endings [Default: OS dependent]')