Ejemplo n.º 1
0
    def _GetProcessedAction(self,
                            owner,
                            description,
                            obsolete,
                            not_user_triggered=NO_VALUE,
                            new_actions=[],
                            comment=NO_VALUE):
        """Forms an actions XML string and returns it after processing.

    It parses the original XML string, adds new user actions (if there is any),
    and pretty prints it.

    Args:
      owner: the owner tag to be inserted in the original XML string.
      description: the description tag to be inserted in the original XML
        string.
      obsolete: the obsolete tag to be inserted in the original XML string.
      new_actions: optional. List of new user actions' names to be inserted.
      comment: the comment tag to be inserted in the original XML string.

    Returns:
      An updated and pretty-printed action XML string.
    """
        # Form the actions.xml mock content based on the input parameters.
        current_xml = ACTIONS_XML.format(owners=owner,
                                         description=description,
                                         obsolete=obsolete,
                                         comment=comment,
                                         not_user_triggered=not_user_triggered)
        actions_dict, comments, suffixes = extract_actions.ParseActionFile(
            current_xml)
        for action_name in new_actions:
            actions_dict[action_name] = action_utils.Action(
                action_name, None, [])
        return extract_actions.PrettyPrint(actions_dict, comments, suffixes)
Ejemplo n.º 2
0
def UpdateXml(original_xml):
  actions_dict, comment_nodes, suffixes = ParseActionFile(original_xml)

  actions = set()
  AddComputedActions(actions)
  AddWebUIActions(actions)
  AddDevToolsActions(actions)

  AddLiteralActions(actions)

  # print("Scanned {0} number of files".format(number_of_files_total))
  # print("Found {0} entries".format(len(actions)))

  AddAutomaticResetBannerActions(actions)
  AddBookmarkManagerActions(actions)
  AddChromeOSActions(actions)
  AddExtensionActions(actions)
  AddHistoryPageActions(actions)
  AddPDFPluginActions(actions)

  for action_name in actions:
    if action_name not in actions_dict:
      actions_dict[action_name] = action_utils.Action(action_name, None, [])

  return PrettyPrint(actions_dict, comment_nodes, suffixes)
Ejemplo n.º 3
0
def ParseActionFile(file_content):
    """Parse the XML data currently stored in the file.

  Args:
    file_content: a string containing the action XML file content.

  Returns:
    (actions, actions_dict) actions is a set with all user actions' names.
    actions_dict is a dict from user action name to Action object.
  """
    dom = minidom.parseString(file_content)

    comment_nodes = []
    # Get top-level comments. It is assumed that all comments are placed before
    # <actions> tag. Therefore the loop will stop if it encounters a non-comment
    # node.
    for node in dom.childNodes:
        if node.nodeType == minidom.Node.COMMENT_NODE:
            comment_nodes.append(node)
        else:
            break

    actions_dict = {}
    # Get each user action data.
    for action_dom in dom.getElementsByTagName('action'):
        action_name = action_dom.getAttribute('name')
        not_user_triggered = bool(
            action_dom.getAttribute('not_user_triggered'))

        owners = _ExtractText(action_dom, 'owner')
        # There is only one description for each user action. Get the first element
        # of the returned list.
        description_list = _ExtractText(action_dom, 'description')
        if len(description_list) > 1:
            logging.error(
                'user actions "%s" has more than one descriptions. Exactly '
                'one description is needed for each user action. Please '
                'fix.', action_name)
            sys.exit(1)
        description = description_list[0] if description_list else None
        # There is at most one obsolete tag for each user action.
        obsolete_list = _ExtractText(action_dom, 'obsolete')
        if len(obsolete_list) > 1:
            logging.error(
                'user actions "%s" has more than one obsolete tag. At most '
                'one obsolete tag can be added for each user action. Please'
                ' fix.', action_name)
            sys.exit(1)
        obsolete = obsolete_list[0] if obsolete_list else None
        actions_dict[action_name] = action_utils.Action(
            action_name, description, owners, not_user_triggered, obsolete)

    try:
        action_utils.CreateActionsFromSuffixes(
            actions_dict, dom.getElementsByTagName('action-suffix'))
    except action_utils.Error as e:
        sys.exit(1)

    return set(actions_dict.keys()), actions_dict, comment_nodes