chrome/browser/resources/PRESUBMIT.py
def CheckUserActionUpdate(input_api, output_api, action_xml_path):
  """Checks if any new user action has been added."""
  if any('actions.xml' == input_api.os_path.basename(f) for f in
         input_api.change.LocalPaths()):
    # If actions.xml is already included in the changelist, the PRESUBMIT
    # for actions.xml will do a more complete presubmit check.
    return []

  file_filter = lambda f: f.LocalPath().endswith('.html')
  action_re = r'(^|\s+)metric\s*=\s*"([^ ]*)"'
  current_actions = None
  for f in input_api.AffectedFiles(file_filter=file_filter):
    for line_num, line in f.ChangedContents():
      match = input_api.re.search(action_re, line)
      if match:
        # Loads contents in tools/metrics/actions/actions.xml to memory. It's
        # loaded only once.
        if not current_actions:
          with open(action_xml_path) as actions_f:
            current_actions = actions_f.read()

        metric_name = match.group(2)
        is_boolean = IsBoolean(f.NewContents(), metric_name, input_api)

        # Search for the matched user action name in |current_actions|.
        if not IsActionPresent(current_actions, metric_name, is_boolean):
          return [output_api.PresubmitPromptWarning(
            'File %s line %d: %s is missing in '
            'tools/metrics/actions/actions.xml. Please run '
            'tools/metrics/actions/extract_actions.py to update.'
            % (f.LocalPath(), line_num, metric_name), [])]
  return []
Checks if any new user action has been added.
Checks if any new user action has been added.
Checks if any new user action has been added .
def CheckUserActionUpdate(input_api, output_api, action_xml_path):
  if any('actions.xml' == input_api.os_path.basename(f) for f in
         input_api.change.LocalPaths()):
    return []
  file_filter = lambda f: f.LocalPath().endswith('.html')
  action_re = r'(^|\s+)metric\s*=\s*"([^ ]*)"'
  current_actions = None
  for f in input_api.AffectedFiles(file_filter=file_filter):
    for line_num, line in f.ChangedContents():
      match = input_api.re.search(action_re, line)
      if match:
        if not current_actions:
          with open(action_xml_path) as actions_f:
            current_actions = actions_f.read()
        metric_name = match.group(2)
        is_boolean = IsBoolean(f.NewContents(), metric_name, input_api)
        if not IsActionPresent(current_actions, metric_name, is_boolean):
          return [output_api.PresubmitPromptWarning(
            'File %s line %d: %s is missing in '
            'tools/metrics/actions/actions.xml. Please run '
            'tools/metrics/actions/extract_actions.py to update.'
            % (f.LocalPath(), line_num, metric_name), [])]
  return []
def CheckUserActionUpdate ( input_api , output_api , action_xml_path ) : if any ( 'actions.xml' == input_api . os_path . basename ( f ) for f in input_api . change . LocalPaths ( ) ) : return [ ] file_filter = lambda f : f . LocalPath ( ) . endswith ( '.html' ) action_re = r'(^|\s+)metric\s*=\s*"([^ ]*)"' current_actions = None for f in input_api . AffectedFiles ( file_filter = file_filter ) : for line_num , line in f . ChangedContents ( ) : match = input_api . re . search ( action_re , line ) if match : if not current_actions : with open ( action_xml_path ) as actions_f : current_actions = actions_f . read ( ) metric_name = match . group ( 2 ) is_boolean = IsBoolean ( f . NewContents ( ) , metric_name , input_api ) if not IsActionPresent ( current_actions , metric_name , is_boolean ) : return [ output_api . PresubmitPromptWarning ( 'File %s line %d: %s is missing in ' 'tools/metrics/actions/actions.xml. Please run ' 'tools/metrics/actions/extract_actions.py to update.' % ( f . LocalPath ( ) , line_num , metric_name ) , [ ] ) ] return [ ]
Checks if any new user action has been added.
Checks if any new user action has been added .
"""Checks if any new user action has been added.""" # If actions.xml is already included in the changelist, the PRESUBMIT # for actions.xml will do a more complete presubmit check. # Loads contents in tools/metrics/actions/actions.xml to memory. It's # loaded only once. # Search for the matched user action name in |current_actions|.
input_api
output_api
action_xml_path