testing/variations/PRESUBMIT.py
def PrettyPrint(contents):
  """Pretty prints a fieldtrial configuration.

  Args:
    contents: File contents as a string.

  Returns:
    Pretty printed file contents.
  """

  # We have a preferred ordering of the fields (e.g. platforms on top). This
  # code loads everything into OrderedDicts and then tells json to dump it out.
  # The JSON dumper will respect the dict ordering.
  #
  # The ordering is as follows:
  # {
  #     'StudyName Alphabetical': [
  #         {
  #             'platforms': [sorted platforms]
  #             'groups': [
  #                 {
  #                     name: ...
  #                     forcing_flag: "forcing flag string"
  #                     params: {sorted dict}
  #                     enable_features: [sorted features]
  #                     disable_features: [sorted features]
  #                     (Unexpected extra keys will be caught by the validator)
  #                 }
  #             ],
  #             ....
  #         },
  #         ...
  #     ]
  #     ...
  # }
  config = json.loads(contents)
  ordered_config = OrderedDict()
  for key in sorted(config.keys()):
    study = copy.deepcopy(config[key])
    ordered_study = []
    for experiment_config in study:
      ordered_experiment_config = OrderedDict([('platforms',
                                                experiment_config['platforms']),
                                               ('experiments', [])])
      for experiment in experiment_config['experiments']:
        ordered_experiment = OrderedDict()
        for index in range(0, 10):
          comment_key = '//' + str(index)
          if comment_key in experiment:
            ordered_experiment[comment_key] = experiment[comment_key]
        ordered_experiment['name'] = experiment['name']
        if 'forcing_flag' in experiment:
          ordered_experiment['forcing_flag'] = experiment['forcing_flag']
        if 'params' in experiment:
          ordered_experiment['params'] = OrderedDict(
              sorted(experiment['params'].items(), key=lambda t: t[0]))
        if 'enable_features' in experiment:
          ordered_experiment['enable_features'] = \
              sorted(experiment['enable_features'])
        if 'disable_features' in experiment:
          ordered_experiment['disable_features'] = \
              sorted(experiment['disable_features'])
        ordered_experiment_config['experiments'].append(ordered_experiment)
        if 'min_os_version' in experiment:
          ordered_experiment['min_os_version'] = experiment['min_os_version']
      ordered_study.append(ordered_experiment_config)
    ordered_config[key] = ordered_study
  return json.dumps(
      ordered_config, sort_keys=False, indent=4, separators=(',', ': ')) + '\n'
Pretty prints a fieldtrial configuration.

  Args:
    contents: File contents as a string.

  Returns:
    Pretty printed file contents.
  
Pretty prints a fieldtrial configuration.
Pretty prints a fieldtrial configuration .
def PrettyPrint(contents):
   The ordering is as follows:
   {
       'StudyName Alphabetical': [
           {
               'platforms': [sorted platforms]
               'groups': [
                   {
                       name: ...
                       forcing_flag: "forcing flag string"
                       params: {sorted dict}
                       enable_features: [sorted features]
                       disable_features: [sorted features]
                       (Unexpected extra keys will be caught by the validator)
                   }
               ],
               ....
           },
           ...
       ]
       ...
   }
  config = json.loads(contents)
  ordered_config = OrderedDict()
  for key in sorted(config.keys()):
    study = copy.deepcopy(config[key])
    ordered_study = []
    for experiment_config in study:
      ordered_experiment_config = OrderedDict([('platforms',
                                                experiment_config['platforms']),
                                               ('experiments', [])])
      for experiment in experiment_config['experiments']:
        ordered_experiment = OrderedDict()
        for index in range(0, 10):
          comment_key = '//' + str(index)
          if comment_key in experiment:
            ordered_experiment[comment_key] = experiment[comment_key]
        ordered_experiment['name'] = experiment['name']
        if 'forcing_flag' in experiment:
          ordered_experiment['forcing_flag'] = experiment['forcing_flag']
        if 'params' in experiment:
          ordered_experiment['params'] = OrderedDict(
              sorted(experiment['params'].items(), key=lambda t: t[0]))
        if 'enable_features' in experiment:
          ordered_experiment['enable_features'] = \
              sorted(experiment['enable_features'])
        if 'disable_features' in experiment:
          ordered_experiment['disable_features'] = \
              sorted(experiment['disable_features'])
        ordered_experiment_config['experiments'].append(ordered_experiment)
        if 'min_os_version' in experiment:
          ordered_experiment['min_os_version'] = experiment['min_os_version']
      ordered_study.append(ordered_experiment_config)
    ordered_config[key] = ordered_study
  return json.dumps(
      ordered_config, sort_keys=False, indent=4, separators=(',', ': ')) + '\n'
def PrettyPrint ( contents ) : config = json . loads ( contents ) ordered_config = OrderedDict ( ) for key in sorted ( config . keys ( ) ) : study = copy . deepcopy ( config [ key ] ) ordered_study = [ ] for experiment_config in study : ordered_experiment_config = OrderedDict ( [ ( 'platforms' , experiment_config [ 'platforms' ] ) , ( 'experiments' , [ ] ) ] ) for experiment in experiment_config [ 'experiments' ] : ordered_experiment = OrderedDict ( ) for index in range ( 0 , 10 ) : comment_key = '//' + str ( index ) if comment_key in experiment : ordered_experiment [ comment_key ] = experiment [ comment_key ] ordered_experiment [ 'name' ] = experiment [ 'name' ] if 'forcing_flag' in experiment : ordered_experiment [ 'forcing_flag' ] = experiment [ 'forcing_flag' ] if 'params' in experiment : ordered_experiment [ 'params' ] = OrderedDict ( sorted ( experiment [ 'params' ] . items ( ) , key = lambda t : t [ 0 ] ) ) if 'enable_features' in experiment : ordered_experiment [ 'enable_features' ] = sorted ( experiment [ 'enable_features' ] ) if 'disable_features' in experiment : ordered_experiment [ 'disable_features' ] = sorted ( experiment [ 'disable_features' ] ) ordered_experiment_config [ 'experiments' ] . append ( ordered_experiment ) if 'min_os_version' in experiment : ordered_experiment [ 'min_os_version' ] = experiment [ 'min_os_version' ] ordered_study . append ( ordered_experiment_config ) ordered_config [ key ] = ordered_study return json . dumps ( ordered_config , sort_keys = False , indent = 4 , separators = ( ',' , ': ' ) ) + '\n'
Pretty prints a fieldtrial configuration.
Pretty prints a fieldtrial configuration .
"""Pretty prints a fieldtrial configuration.

  Args:
    contents: File contents as a string.

  Returns:
    Pretty printed file contents.
  """ # We have a preferred ordering of the fields (e.g. platforms on top). This # code loads everything into OrderedDicts and then tells json to dump it out. # The JSON dumper will respect the dict ordering. # # The ordering is as follows: # { #     'StudyName Alphabetical': [ #         { #             'platforms': [sorted platforms] #             'groups': [ #                 { #                     name: ... #                     forcing_flag: "forcing flag string" #                     params: {sorted dict} #                     enable_features: [sorted features] #                     disable_features: [sorted features] #                     (Unexpected extra keys will be caught by the validator) #                 } #             ], #             .... #         }, #         ... #     ] #     ... # }
Pretty printed file contents.
Pretty printed file contents .
contents
File contents as a string.
File contents as a string .