tools/traffic_annotation/scripts/update_annotations_doc.py
def _create_annotation_request(self, traffic_annotation, index, color=False):
    """Returns the request (dict) for inserting the annotations table. Refer to
    the template document for a visual.

    Args:
      traffic_annotation: generator_utils.TrafficAnnotation
        The TrafficAnnotation object with all the relevant information, e.g.
        unique_id, description, etc.
      index: int
        Where the annotation should be added in the document.
      color: bool
        If True, make the table blue, otherwise white.
    """
    # Hardcoded due to intrinsic of tables in Google Docs API.
    idx = 8
    offset = 2

    # Create the 1x2 table -- col 1 contains the unique_id placeholder, col 2
    # contains the remaining placeholders, e.g. trigger, description, etc.
    padding_req, _ = self._create_text_request("\n", index)
    reqs = [padding_req]
    reqs.append({
        "insertTable": {
            "rows": 1,
            "columns": 2,
            "location": {"index": index}
        }
    })

    # Writing the annotation's relevant information directly to the table,
    # within the left cell |left_text| and the right cell |right_text|.
    left_text = traffic_annotation.unique_id
    right_text = "{}\nTrigger: {}\nData: {}\nSettings: {}\nPolicy: {}".format(
        traffic_annotation.description, traffic_annotation.trigger,
        traffic_annotation.data, traffic_annotation.settings,
        traffic_annotation.policy)

    # +4 hardcoded due to intrinsic of tables in Google Docs API.
    start_index = index + 4
    left_req, left_increment = self._create_text_request(left_text, start_index)
    right_req, right_increment = self._create_text_request(
        right_text, start_index + left_increment + offset)

    reqs.append(left_req)
    reqs.append(right_req)

    end_index = index + left_increment + right_increment + idx

    # This sizes the table correctly such as making the right cell's width
    # greater than that of the left cell.
    col_properties = [{
        "columnIndices": [0],
        "width": 153
    }, {
        "columnIndices": [1],
        "width": 534
    }]
    for properties in col_properties:
      reqs.append({
          "updateTableColumnProperties": {
              "tableStartLocation": {"index": index + 1},
              "columnIndices": properties["columnIndices"],
              "fields": "*",
              "tableColumnProperties": {
                  "widthType": "FIXED_WIDTH",
                  "width": {
                      "magnitude": properties["width"],
                      "unit": "PT"
                  }
              }
          }
      })

    # Changing the table's color and ensuring that the borders are "turned off"
    # (really they're given the same color as the background).
    color = self.BLUE if color else self.WHITE
    color_and_border_req = {
        "updateTableCellStyle": {
            "tableStartLocation": {"index": index + 1},
            "fields": "*",
            "tableCellStyle": {
                "rowSpan": 1,
                "columnSpan": 1,
                "backgroundColor": {
                    "color": {
                        "rgbColor": color
                    }
                }
            }
        }
    }
    # make the table borders 'invisible' and adjust the padding to site text in
    # the cell correctly.
    for direction in ["Left", "Right", "Top", "Bottom"]:
      color_and_border_req["updateTableCellStyle"]["tableCellStyle"][
          "border" + direction] = {
              "color": {"color": {"rgbColor": color}},
              "width": {"unit": "PT"},
              "dashStyle": "SOLID"
          }
      color_and_border_req["updateTableCellStyle"]["tableCellStyle"][
          "padding" + direction] = {"magnitude": 1.44, "unit": "PT"}
    reqs.append(color_and_border_req)

    # Text formatting (normal text, linespacing, etc.) adds space below the
    # lines within a cell.
    reqs.append({
        "updateParagraphStyle": {
            "range": {
                "startIndex": start_index,
                "endIndex": end_index - 1
            },
            "paragraphStyle": {
                "namedStyleType": "NORMAL_TEXT",
                "lineSpacing": 100,
                "direction": "LEFT_TO_RIGHT",
                "spacingMode": "NEVER_COLLAPSE",
                "spaceBelow": {"magnitude": 4, "unit": "PT"},
                "avoidWidowAndOrphan": False
            },
            "fields": "*"
        }
    })
    reqs.append(
        self._format_text(start_index, end_index - 1, Placeholder.ANNOTATION))
    return reqs, end_index - index
Returns the request (dict) for inserting the annotations table. Refer to
    the template document for a visual.

    Args:
      traffic_annotation: generator_utils.TrafficAnnotation
        The TrafficAnnotation object with all the relevant information, e.g.
        unique_id, description, etc.
      index: int
        Where the annotation should be added in the document.
      color: bool
        If True, make the table blue, otherwise white.
    
Returns the request (dict) for inserting the annotations table. Refer to
the template document for a visual.
Returns the request ( dict ) for inserting the annotations table . Refer to the template document for a visual .
def _create_annotation_request(self, traffic_annotation, index, color=False):
    idx = 8
    offset = 2
    padding_req, _ = self._create_text_request("\n", index)
    reqs = [padding_req]
    reqs.append({
        "insertTable": {
            "rows": 1,
            "columns": 2,
            "location": {"index": index}
        }
    })
    left_text = traffic_annotation.unique_id
    right_text = "{}\nTrigger: {}\nData: {}\nSettings: {}\nPolicy: {}".format(
        traffic_annotation.description, traffic_annotation.trigger,
        traffic_annotation.data, traffic_annotation.settings,
        traffic_annotation.policy)
    start_index = index + 4
    left_req, left_increment = self._create_text_request(left_text, start_index)
    right_req, right_increment = self._create_text_request(
        right_text, start_index + left_increment + offset)
    reqs.append(left_req)
    reqs.append(right_req)
    end_index = index + left_increment + right_increment + idx
    col_properties = [{
        "columnIndices": [0],
        "width": 153
    }, {
        "columnIndices": [1],
        "width": 534
    }]
    for properties in col_properties:
      reqs.append({
          "updateTableColumnProperties": {
              "tableStartLocation": {"index": index + 1},
              "columnIndices": properties["columnIndices"],
              "fields": "*",
              "tableColumnProperties": {
                  "widthType": "FIXED_WIDTH",
                  "width": {
                      "magnitude": properties["width"],
                      "unit": "PT"
                  }
              }
          }
      })
    color = self.BLUE if color else self.WHITE
    color_and_border_req = {
        "updateTableCellStyle": {
            "tableStartLocation": {"index": index + 1},
            "fields": "*",
            "tableCellStyle": {
                "rowSpan": 1,
                "columnSpan": 1,
                "backgroundColor": {
                    "color": {
                        "rgbColor": color
                    }
                }
            }
        }
    }
    for direction in ["Left", "Right", "Top", "Bottom"]:
      color_and_border_req["updateTableCellStyle"]["tableCellStyle"][
          "border" + direction] = {
              "color": {"color": {"rgbColor": color}},
              "width": {"unit": "PT"},
              "dashStyle": "SOLID"
          }
      color_and_border_req["updateTableCellStyle"]["tableCellStyle"][
          "padding" + direction] = {"magnitude": 1.44, "unit": "PT"}
    reqs.append(color_and_border_req)
    reqs.append({
        "updateParagraphStyle": {
            "range": {
                "startIndex": start_index,
                "endIndex": end_index - 1
            },
            "paragraphStyle": {
                "namedStyleType": "NORMAL_TEXT",
                "lineSpacing": 100,
                "direction": "LEFT_TO_RIGHT",
                "spacingMode": "NEVER_COLLAPSE",
                "spaceBelow": {"magnitude": 4, "unit": "PT"},
                "avoidWidowAndOrphan": False
            },
            "fields": "*"
        }
    })
    reqs.append(
        self._format_text(start_index, end_index - 1, Placeholder.ANNOTATION))
    return reqs, end_index - index
def _create_annotation_request ( self , traffic_annotation , index , color = False ) : idx = 8 offset = 2 padding_req , _ = self . _create_text_request ( "\n" , index ) reqs = [ padding_req ] reqs . append ( { "insertTable" : { "rows" : 1 , "columns" : 2 , "location" : { "index" : index } } } ) left_text = traffic_annotation . unique_id right_text = "{}\nTrigger: {}\nData: {}\nSettings: {}\nPolicy: {}" . format ( traffic_annotation . description , traffic_annotation . trigger , traffic_annotation . data , traffic_annotation . settings , traffic_annotation . policy ) start_index = index + 4 left_req , left_increment = self . _create_text_request ( left_text , start_index ) right_req , right_increment = self . _create_text_request ( right_text , start_index + left_increment + offset ) reqs . append ( left_req ) reqs . append ( right_req ) end_index = index + left_increment + right_increment + idx col_properties = [ { "columnIndices" : [ 0 ] , "width" : 153 } , { "columnIndices" : [ 1 ] , "width" : 534 } ] for properties in col_properties : reqs . append ( { "updateTableColumnProperties" : { "tableStartLocation" : { "index" : index + 1 } , "columnIndices" : properties [ "columnIndices" ] , "fields" : "*" , "tableColumnProperties" : { "widthType" : "FIXED_WIDTH" , "width" : { "magnitude" : properties [ "width" ] , "unit" : "PT" } } } } ) color = self . BLUE if color else self . WHITE color_and_border_req = { "updateTableCellStyle" : { "tableStartLocation" : { "index" : index + 1 } , "fields" : "*" , "tableCellStyle" : { "rowSpan" : 1 , "columnSpan" : 1 , "backgroundColor" : { "color" : { "rgbColor" : color } } } } } for direction in [ "Left" , "Right" , "Top" , "Bottom" ] : color_and_border_req [ "updateTableCellStyle" ] [ "tableCellStyle" ] [ "border" + direction ] = { "color" : { "color" : { "rgbColor" : color } } , "width" : { "unit" : "PT" } , "dashStyle" : "SOLID" } color_and_border_req [ "updateTableCellStyle" ] [ "tableCellStyle" ] [ "padding" + direction ] = { "magnitude" : 1.44 , "unit" : "PT" } reqs . append ( color_and_border_req ) reqs . append ( { "updateParagraphStyle" : { "range" : { "startIndex" : start_index , "endIndex" : end_index - 1 } , "paragraphStyle" : { "namedStyleType" : "NORMAL_TEXT" , "lineSpacing" : 100 , "direction" : "LEFT_TO_RIGHT" , "spacingMode" : "NEVER_COLLAPSE" , "spaceBelow" : { "magnitude" : 4 , "unit" : "PT" } , "avoidWidowAndOrphan" : False } , "fields" : "*" } } ) reqs . append ( self . _format_text ( start_index , end_index - 1 , Placeholder . ANNOTATION ) ) return reqs , end_index - index
Returns the request (dict) for inserting the annotations table.
Returns the request ( dict ) for inserting the annotations table .
"""Returns the request (dict) for inserting the annotations table. Refer to
    the template document for a visual.

    Args:
      traffic_annotation: generator_utils.TrafficAnnotation
        The TrafficAnnotation object with all the relevant information, e.g.
        unique_id, description, etc.
      index: int
        Where the annotation should be added in the document.
      color: bool
        If True, make the table blue, otherwise white.
    """ # Hardcoded due to intrinsic of tables in Google Docs API. # Create the 1x2 table -- col 1 contains the unique_id placeholder, col 2 # contains the remaining placeholders, e.g. trigger, description, etc. # Writing the annotation's relevant information directly to the table, # within the left cell |left_text| and the right cell |right_text|. # +4 hardcoded due to intrinsic of tables in Google Docs API. # This sizes the table correctly such as making the right cell's width # greater than that of the left cell. # Changing the table's color and ensuring that the borders are "turned off" # (really they're given the same color as the background). # make the table borders 'invisible' and adjust the padding to site text in # the cell correctly. # Text formatting (normal text, linespacing, etc.) adds space below the # lines within a cell.
self
traffic_annotation
generator_utils.TrafficAnnotation
The TrafficAnnotation object with all the relevant information, e.g.
unique_id, description, etc.
generator_utils . TrafficAnnotation The TrafficAnnotation object with all the relevant information e . g . unique_id description etc .
index
int
Where the annotation should be added in the document.
int Where the annotation should be added in the document .
color
bool
If True, make the table blue, otherwise white.
bool If True make the table blue otherwise white .