Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: build/config/mac/plist_util.py

Issue 2715543002: Merge Arrays in plist_util.py (Closed)
Patch Set: update comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import argparse 5 import argparse
6 import plistlib 6 import plistlib
7 import os 7 import os
8 import re 8 import re
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 subprocess.check_call(['plutil', '-convert', format, '-o', path, name]) 134 subprocess.check_call(['plutil', '-convert', format, '-o', path, name])
135 finally: 135 finally:
136 os.unlink(name) 136 os.unlink(name)
137 137
138 138
139 def MergePList(plist1, plist2): 139 def MergePList(plist1, plist2):
140 """Merges |plist1| with |plist2| recursively. 140 """Merges |plist1| with |plist2| recursively.
141 141
142 Creates a new dictionary representing a Property List (.plist) files by 142 Creates a new dictionary representing a Property List (.plist) files by
143 merging the two dictionary |plist1| and |plist2| recursively (only for 143 merging the two dictionary |plist1| and |plist2| recursively (only for
144 dictionary values). 144 dictionary values). List value will be concatenated.
145 145
146 Args: 146 Args:
147 plist1: a dictionary representing a Property List (.plist) file 147 plist1: a dictionary representing a Property List (.plist) file
148 plist2: a dictionary representing a Property List (.plist) file 148 plist2: a dictionary representing a Property List (.plist) file
149 149
150 Returns: 150 Returns:
151 A new dictionary representing a Property List (.plist) file by merging 151 A new dictionary representing a Property List (.plist) file by merging
152 |plist1| with |plist2|. If any value is a dictionary, they are merged 152 |plist1| with |plist2|. If any value is a dictionary, they are merged
153 recursively, otherwise |plist2| value is used. 153 recursively, otherwise |plist2| value is used. If values are list, they
154 are concatenated.
154 """ 155 """
155 if not isinstance(plist1, dict) or not isinstance(plist2, dict): 156 if not isinstance(plist1, dict) or not isinstance(plist2, dict):
156 if plist2 is not None: 157 if plist2 is not None:
157 return plist2 158 return plist2
158 else: 159 else:
159 return plist1 160 return plist1
160 result = {} 161 result = {}
161 for key in set(plist1) | set(plist2): 162 for key in set(plist1) | set(plist2):
162 if key in plist2: 163 if key in plist2:
163 value = plist2[key] 164 value = plist2[key]
164 else: 165 else:
165 value = plist1[key] 166 value = plist1[key]
166 if isinstance(value, dict): 167 if isinstance(value, dict):
167 value = MergePList(plist1.get(key, None), plist2.get(key, None)) 168 value = MergePList(plist1.get(key, None), plist2.get(key, None))
169 if isinstance(value, list):
170 value = plist1.get(key, []) + plist2.get(key, [])
168 result[key] = value 171 result[key] = value
169 return result 172 return result
170 173
171 174
172 class Action(object): 175 class Action(object):
173 """Class implementing one action supported by the script.""" 176 """Class implementing one action supported by the script."""
174 177
175 @classmethod 178 @classmethod
176 def Register(cls, subparsers): 179 def Register(cls, subparsers):
177 parser = subparsers.add_parser(cls.name, help=cls.help) 180 parser = subparsers.add_parser(cls.name, help=cls.help)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 245
243 for action in [MergeAction, SubstituteAction]: 246 for action in [MergeAction, SubstituteAction]:
244 action.Register(subparsers) 247 action.Register(subparsers)
245 248
246 args = parser.parse_args() 249 args = parser.parse_args()
247 args.func(args) 250 args.func(args)
248 251
249 252
250 if __name__ == '__main__': 253 if __name__ == '__main__':
251 sys.exit(Main()) 254 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698