From 535c4fbc309d821cf6dd2229ad481f21b32099e9 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 8 Dec 2015 14:13:20 -0500 Subject: [PATCH] tools: Add `--patch` argument to patch_updater.py --- tools/patch_updater.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/patch_updater.py b/tools/patch_updater.py index 63b6b59f6..aa1681c98 100644 --- a/tools/patch_updater.py +++ b/tools/patch_updater.py @@ -2,7 +2,7 @@ # reserved. Use of this source code is governed by a BSD-style license that # can be found in the LICENSE file. -from optparse import OptionParser +from optparse import Option, OptionParser, OptionValueError import os import re import sys @@ -42,13 +42,30 @@ disc = """ This utility updates existing patch files. """ -parser = OptionParser(description=disc) +# Support options with multiple arguments. +class MultipleOption(Option): + ACTIONS = Option.ACTIONS + ("extend",) + STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",) + TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",) + ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",) + + def take_action(self, action, dest, opt, value, values, parser): + if action == "extend": + values.ensure_value(dest, []).append(value) + else: + Option.take_action(self, action, dest, opt, value, values, parser) + +parser = OptionParser(option_class=MultipleOption, + description=disc) parser.add_option('--resave', action='store_true', dest='resave', default=False, help='re-save existing patch files to pick up manual changes') parser.add_option('--revert', action='store_true', dest='revert', default=False, help='revert all changes from existing patch files') +parser.add_option('--patch', + action='extend', dest='patch', type='string', default=[], + help='optional patch name to process (multiples allowed)') (options, args) = parser.parse_args() if options.resave and options.revert: @@ -78,6 +95,10 @@ patches = scope["patches"] # Read each individual patch file. patches_dir = os.path.join(patch_dir, 'patches') for patch in patches: + # If specific patch names are specified only process those patches. + if options.patch and not patch['name'] in options.patch: + continue + sys.stdout.write('\n') patch_file = os.path.join(patches_dir, patch['name']+'.patch')