Exemple #1
0
 def load_config(p):
     """We need direct access to the underlying configparser, so we don't load via Config."""
     cp = Config._create_parser()
     with open(p, 'r') as ini:
         cp.readfp(ini)
     return cp
def check_config_file(path):
    cp = Config._create_parser()
    with open(path, 'r') as ini:
        cp.readfp(ini)

    print('Checking config file at {} for unmigrated keys.'.format(path),
          file=sys.stderr)

    def section(s):
        return cyan('[{}]'.format(s))

    for src, dst in migrations.items():
        check_option(cp, src, dst)

    # Special-case handling of per-task subsystem options, so we can sweep them up in all
    # sections easily.

    def check_task_subsystem_options(subsystem_sec,
                                     options_map,
                                     sections=None):
        sections = sections or cp.sections()
        for src_sec in ['DEFAULT'] + sections:
            dst_sec = subsystem_sec if src_sec == 'DEFAULT' else '{}.{}'.format(
                subsystem_sec, src_sec)
            for src_key, dst_key in options_map.items():
                check_option(cp, (src_sec, src_key), (dst_sec, dst_key))

    artifact_cache_options_map = {
        'read_from_artifact_cache': 'read',
        'write_to_artifact_cache': 'write',
        'overwrite_cache_artifacts': 'overwrite',
        'read_artifact_caches': 'read_from',
        'write_artifact_caches': 'write_to',
        'cache_compression': 'compression_level',
    }
    check_task_subsystem_options('cache', artifact_cache_options_map)

    jvm_options_map = {
        'jvm_options': 'options',
        'args': 'program_args',
        'debug': 'debug',
        'debug_port': 'debug_port',
        'debug_args': 'debug_args',
    }
    jvm_options_sections = [
        'repl.scala', 'test.junit', 'run.jvm', 'bench', 'doc.javadoc',
        'doc.scaladoc'
    ]
    check_task_subsystem_options('jvm',
                                 jvm_options_map,
                                 sections=jvm_options_sections)

    # Check that all values are parseable.
    for sec in ['DEFAULT'] + cp.sections():
        for key, value in cp.items(sec):
            value = value.strip()
            if value.startswith('['):
                try:
                    custom_types.list_option(value)
                except ParseError:
                    print('Value of {key} in section {section} is not a valid '
                          'JSON list.'.format(key=green(key),
                                              section=section(sec)))
            elif value.startswith('{'):
                try:
                    custom_types.dict_option(value)
                except ParseError:
                    print('Value of {key} in section {section} is not a valid '
                          'JSON object.'.format(key=green(key),
                                                section=section(sec)))
Exemple #3
0
 def load_config(p):
     """We need direct access to the underlying configparser, so we don't load via Config."""
     cp = Config._create_parser()
     with open(p, "r") as ini:
         cp.readfp(ini)
     return cp
Exemple #4
0
def check_config_file(path):
  cp = Config._create_parser()
  with open(path, 'r') as ini:
    cp.readfp(ini)

  print('Checking config file at {} for unmigrated keys.'.format(path), file=sys.stderr)

  def section(s):
    return cyan('[{}]'.format(s))

  for src, dst in migrations.items():
    check_option(cp, src, dst)

  # Special-case handling of per-task subsystem options, so we can sweep them up in all
  # sections easily.

  def check_task_subsystem_options(subsystem_sec, options_map, sections=None):
    sections = sections or cp.sections()
    for src_sec in ['DEFAULT'] + sections:
      dst_sec = subsystem_sec if src_sec == 'DEFAULT' else '{}.{}'.format(subsystem_sec, src_sec)
      for src_key, dst_key in options_map.items():
        check_option(cp, (src_sec, src_key), (dst_sec, dst_key))

  artifact_cache_options_map = {
    'read_from_artifact_cache': 'read',
    'write_to_artifact_cache': 'write',
    'overwrite_cache_artifacts': 'overwrite',
    'read_artifact_caches': 'read_from',
    'write_artifact_caches': 'write_to',
    'cache_compression': 'compression_level',
  }
  check_task_subsystem_options('cache', artifact_cache_options_map)

  jvm_options_map = {
    'jvm_options': 'options',
    'args': 'program_args',
    'debug': 'debug',
    'debug_port': 'debug_port',
    'debug_args': 'debug_args',
  }
  jvm_options_sections = [
    'repl.scala', 'test.junit', 'run.jvm', 'bench', 'doc.javadoc', 'doc.scaladoc'
  ]
  check_task_subsystem_options('jvm', jvm_options_map, sections=jvm_options_sections)

  # Check that all values are parseable.
  for sec in ['DEFAULT'] + cp.sections():
    for key, value in cp.items(sec):
      value = value.strip()
      if value.startswith('['):
        try:
          custom_types.list_option(value)
        except ParseError:
          print('Value of {key} in section {section} is not a valid '
                'JSON list.'.format(key=green(key), section=section(sec)))
      elif value.startswith('{'):
        try:
          custom_types.dict_option(value)
        except ParseError:
          print('Value of {key} in section {section} is not a valid '
                'JSON object.'.format(key=green(key), section=section(sec)))