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

Side by Side Diff: tools/deep_memory_profiler/lib/policy.py

Issue 698183002: Add 'path' member in policies.json to specify policy file path Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import re 8 import re
9 9
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 region[1]['vma']['writable'] + 246 region[1]['vma']['writable'] +
247 region[1]['vma']['executable'] + 247 region[1]['vma']['executable'] +
248 region[1]['vma']['private'])) and 248 region[1]['vma']['private'])) and
249 (not rule.sharedwith or 249 (not rule.sharedwith or
250 not pageframe or sharedwith in rule.sharedwith)): 250 not pageframe or sharedwith in rule.sharedwith)):
251 return rule.name 251 return rule.name
252 252
253 assert False 253 assert False
254 254
255 @staticmethod 255 @staticmethod
256 def load(filename, filetype): 256 def load(path, filename, filetype):
257 """Loads a policy file of |filename| in a |format|. 257 """Loads a policy file of |filename| in a |format|.
258 258
259 Args: 259 Args:
260 filename: A filename to be loaded. 260 filename: A filename to be loaded.
261 filetype: A string to specify a type of the file. Only 'json' is 261 filetype: A string to specify a type of the file. Only 'json' is
262 supported for now. 262 supported for now.
263 263
264 Returns: 264 Returns:
265 A loaded Policy object. 265 A loaded Policy object.
266 """ 266 """
267 with open(os.path.join(BASE_PATH, filename)) as policy_f: 267 if not path:
268 path = BASE_PATH
269 elif path[0] == '.':
270 path = os.path.join(BASE_PATH, path)
271 with open(os.path.join(path, filename)) as policy_f:
268 return Policy.parse(policy_f, filetype) 272 return Policy.parse(policy_f, filetype)
269 273
270 @staticmethod 274 @staticmethod
271 def parse(policy_f, filetype): 275 def parse(policy_f, filetype):
272 """Parses a policy file content in a |format|. 276 """Parses a policy file content in a |format|.
273 277
274 Args: 278 Args:
275 policy_f: An IO object to be loaded. 279 policy_f: An IO object to be loaded.
276 filetype: A string to specify a type of the file. Only 'json' is 280 filetype: A string to specify a type of the file. Only 'json' is
277 supported for now. 281 supported for now.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 with open(POLICIES_JSON_PATH, mode='r') as policies_f: 399 with open(POLICIES_JSON_PATH, mode='r') as policies_f:
396 default_policy_directory = json.load(policies_f) 400 default_policy_directory = json.load(policies_f)
397 return default_policy_directory 401 return default_policy_directory
398 402
399 @staticmethod 403 @staticmethod
400 def _load_policies(directory): 404 def _load_policies(directory):
401 LOGGER.info('Loading policy files.') 405 LOGGER.info('Loading policy files.')
402 policies = {} 406 policies = {}
403 for label in directory: 407 for label in directory:
404 LOGGER.info(' %s: %s' % (label, directory[label]['file'])) 408 LOGGER.info(' %s: %s' % (label, directory[label]['file']))
405 loaded = Policy.load(directory[label]['file'], directory[label]['format']) 409 path = None
410 if 'path' in directory[label]:
411 path = directory[label]['path']
412 loaded = Policy.load(path, directory[label]['file'], directory[label]['for mat'])
406 if loaded: 413 if loaded:
407 policies[label] = loaded 414 policies[label] = loaded
408 return PolicySet(policies) 415 return PolicySet(policies)
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