nodes: 0, module; 1, function_definition; 2, function_name:print_sorted_device_list; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, identifier:device_list; 14, None; 15, identifier:sort_key; 16, string; 17, comment:"""
              Takes in a sort key and prints the device list according to that sort.
  
              Default sorts on serial number.
  
              Current supported sort options are:
                  - name
                  - sn
                  - portals_aliases
  
              Can take optional device object list.
          """; 18, assignment; 19, assignment; 20, comparison_operator:sort_key == 'sn'; 21, block; 22, elif_clause; 23, elif_clause; 24, else_clause; 25, call; 26, string_content:sn; 27, identifier:dev_list; 28, conditional_expression:device_list if device_list is not None else self.get_all_devices_in_portal(); 29, identifier:sorted_dev_list; 30, list; 31, identifier:sort_key; 32, string; 33, expression_statement; 34, expression_statement; 35, for_statement; 36, comparison_operator:sort_key == 'name'; 37, block; 38, comparison_operator:sort_key == 'portals_aliases'; 39, block; 40, block; 41, attribute; 42, argument_list; 43, identifier:device_list; 44, comparison_operator:device_list is not None; 45, call; 46, string_content:sn; 47, assignment; 48, assignment; 49, identifier:key; 50, identifier:sort_keys; 51, block; 52, identifier:sort_key; 53, string; 54, expression_statement; 55, expression_statement; 56, for_statement; 57, identifier:sort_key; 58, string; 59, expression_statement; 60, expression_statement; 61, for_statement; 62, expression_statement; 63, expression_statement; 64, identifier:self; 65, identifier:print_device_list; 66, keyword_argument; 67, identifier:device_list; 68, None; 69, attribute; 70, argument_list; 71, identifier:sort_keys; 72, list_comprehension; 73, identifier:sort_keys; 74, call; 75, expression_statement; 76, string_content:name; 77, assignment; 78, assignment; 79, identifier:key; 80, identifier:sort_keys; 81, block; 82, string_content:portals_aliases; 83, assignment; 84, assignment; 85, identifier:key; 86, identifier:sort_keys; 87, block; 88, call; 89, assignment; 90, identifier:device_list; 91, identifier:sorted_dev_list; 92, identifier:self; 93, identifier:get_all_devices_in_portal; 94, subscript; 95, for_in_clause; 96, if_clause; 97, identifier:sorted; 98, argument_list; 99, call; 100, identifier:sort_keys; 101, list_comprehension; 102, identifier:sort_keys; 103, call; 104, expression_statement; 105, identifier:sort_keys; 106, list_comprehension; 107, identifier:sort_keys; 108, call; 109, expression_statement; 110, identifier:print; 111, argument_list; 112, identifier:sort_keys; 113, None; 114, identifier:k; 115, identifier:sort_key; 116, identifier:k; 117, identifier:dev_list; 118, comparison_operator:k[sort_key] is not None; 119, identifier:sort_keys; 120, attribute; 121, argument_list; 122, subscript; 123, line_continuation:\; 124, for_in_clause; 125, if_clause; 126, identifier:sorted; 127, argument_list; 128, call; 129, subscript; 130, for_in_clause; 131, if_clause; 132, identifier:sorted; 133, argument_list; 134, call; 135, call; 136, subscript; 137, None; 138, identifier:sorted_dev_list; 139, identifier:extend; 140, list_comprehension; 141, subscript; 142, identifier:sort_key; 143, identifier:k; 144, identifier:dev_list; 145, comparison_operator:k['info']['description'][sort_key] is not None; 146, identifier:sort_keys; 147, attribute; 148, argument_list; 149, identifier:k; 150, identifier:sort_key; 151, identifier:k; 152, identifier:dev_list; 153, comparison_operator:k[sort_key] is not None; 154, identifier:sort_keys; 155, attribute; 156, argument_list; 157, attribute; 158, argument_list; 159, identifier:k; 160, identifier:sort_key; 161, identifier:d; 162, for_in_clause; 163, if_clause; 164, subscript; 165, string; 166, subscript; 167, None; 168, identifier:sorted_dev_list; 169, identifier:extend; 170, list_comprehension; 171, subscript; 172, None; 173, identifier:sorted_dev_list; 174, identifier:extend; 175, list_comprehension; 176, string:"Sort key {!r} not recognized."; 177, identifier:format; 178, identifier:sort_key; 179, identifier:d; 180, identifier:dev_list; 181, comparison_operator:d['sn'] == key; 182, identifier:k; 183, string; 184, string_content:description; 185, subscript; 186, identifier:sort_key; 187, identifier:d; 188, for_in_clause; 189, line_continuation:\; 190, if_clause; 191, identifier:k; 192, identifier:sort_key; 193, identifier:d; 194, for_in_clause; 195, if_clause; 196, subscript; 197, identifier:key; 198, string_content:info; 199, subscript; 200, string; 201, identifier:d; 202, identifier:dev_list; 203, comparison_operator:d['info']['description'][sort_key] == key; 204, identifier:d; 205, identifier:dev_list; 206, comparison_operator:d[sort_key] == key; 207, identifier:d; 208, string; 209, identifier:k; 210, string; 211, string_content:description; 212, subscript; 213, identifier:key; 214, subscript; 215, identifier:key; 216, string_content:sn; 217, string_content:info; 218, subscript; 219, identifier:sort_key; 220, identifier:d; 221, identifier:sort_key; 222, subscript; 223, string; 224, identifier:d; 225, string; 226, string_content:description; 227, string_content:info
code: def print_sorted_device_list(self, device_list=None, sort_key='sn'):
          """
              Takes in a sort key and prints the device list according to that sort.
  
              Default sorts on serial number.
  
              Current supported sort options are:
                  - name
                  - sn
                  - portals_aliases
  
              Can take optional device object list.
          """
          dev_list = device_list if device_list is not None else self.get_all_devices_in_portal()
          sorted_dev_list = []
          if sort_key == 'sn':
              sort_keys = [ k[sort_key] for k in dev_list if k[sort_key] is not None ]
              sort_keys = sorted(sort_keys)
              for key in sort_keys:
                  sorted_dev_list.extend([ d for d in dev_list if d['sn'] == key ])
  
          elif sort_key == 'name':
              sort_keys = [ k['info']['description'][sort_key]\
                      for k in dev_list if k['info']['description'][sort_key] is not None ]
              sort_keys = sorted(sort_keys)
              for key in sort_keys:
                  sorted_dev_list.extend( [ d for d in dev_list\
                                              if d['info']['description'][sort_key] == key
                                          ]
                  )
  
          elif sort_key == 'portals_aliases':
              sort_keys = [ k[sort_key] for k in dev_list if k[sort_key] is not None ]
              sort_keys = sorted(sort_keys)
              for key in sort_keys:
                  sorted_dev_list.extend([ d for d in dev_list if d[sort_key] == key ])
  
          else:
              print("Sort key {!r} not recognized.".format(sort_key))
              sort_keys = None
  
          self.print_device_list(device_list=sorted_dev_list)