def BuildUniverse(
    use_simplified_universe: bool = False,
    modified_types_filepath: str = None,
) -> presubmit_validate_types_lib.ConfigUniverse:
    """Generates the ontology universe.

  Args:
    use_simplified_universe: boolean to quick load minimal universe instead of
      full ontology
    modified_types_filepath: filepath to the modified ontology types

  Returns:
    Generated universe object.
  """
    if use_simplified_universe:
        yaml_files = None
        universe = universe_helper.create_simplified_universe()
    elif modified_types_filepath:
        modified_ontology_exists = path.exists(modified_types_filepath)
        if not modified_ontology_exists:
            print(f'Specified filepath [{modified_types_filepath}] '
                  'modified ontology does not exist')
            return None

        modified_types_filepath = path.expanduser(modified_types_filepath)

        external_file_lib.Validate(filter_text=None,
                                   changed_directory=modified_types_filepath,
                                   original_directory=constants.ONTOLOGY_ROOT,
                                   interactive=False)
        yaml_files = external_file_lib.RecursiveDirWalk(
            modified_types_filepath)
    else:
        default_ontology_exists = path.exists(constants.ONTOLOGY_ROOT)
        if not default_ontology_exists:
            print(f'Specified filepath [{constants.ONTOLOGY_ROOT}] '
                  'for default ontology does not exist')
            return None
        # use default location for ontology files
        yaml_files = external_file_lib.RecursiveDirWalk(
            constants.ONTOLOGY_ROOT)

    if yaml_files:
        config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
        universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe
def BuildUniverse(
    modified_types_filepath: str = None
) -> presubmit_validate_types_lib.ConfigUniverse:
    """Generates the ontology universe.

  Args:
    modified_types_filepath: filepath to the modified ontology types

  Returns:
    Generated universe object.
  """
    if modified_types_filepath:
        modified_ontology_exists = path.exists(modified_types_filepath)
        if not modified_ontology_exists:
            print('Specified filepath [{0}] modified ontology does not exist'.
                  format(modified_types_filepath))
            return None

        modified_types_filepath = path.expanduser(modified_types_filepath)

        external_file_lib.Validate(filter_text=None,
                                   changed_directory=modified_types_filepath,
                                   original_directory=constants.ONTOLOGY_ROOT,
                                   interactive=False)
        yaml_files = external_file_lib.RecursiveDirWalk(
            modified_types_filepath)
    else:
        default_ontology_exists = path.exists(constants.ONTOLOGY_ROOT)
        if not default_ontology_exists:
            print(
                'Specified filepath [{0}] for default ontology does not exist'.
                format(constants.ONTOLOGY_ROOT))
            return None
        # use default location for ontology files
        yaml_files = external_file_lib.RecursiveDirWalk(
            constants.ONTOLOGY_ROOT)

    config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
    universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe
Beispiel #3
0
def main(args):
    filter_text = None
    if len(args) >= 2:
        command = args[1]
        commands = command.split(':')
        if len(commands) == 2:
            if commands[0] == 'match':
                filter_text = commands[1].strip()

    changed = FLAGS.changed
    if changed is not None:
        changed = path.expanduser(FLAGS.changed)

    print('Starting Yaml Validator!')
    external_file_lib.Validate(filter_text, path.expanduser(FLAGS.original),
                               changed)
Beispiel #4
0
def main(parsed_args):
    filter_text = None
    if len(sys.argv[1:]) >= 2:
        command = sys.argv[1]
        commands = command.split(':')
        if len(commands) == 2:
            if commands[0] == 'match':
                filter_text = commands[1].strip()

    modified_types_filepath = parsed_args.modified_types_filepath
    if modified_types_filepath is not None:
        modified_types_filepath = path.expanduser(
            parsed_args.modified_types_filepath)

    print('Starting Yaml Validator!')
    external_file_lib.Validate(filter_text,
                               path.expanduser(args.original),
                               modified_types_filepath,
                               interactive=eval(parsed_args.interactive))
def BuildUniverse(modified_types_filepath=None):
    """Generates the ontology universe.

  Args:
    modified_types_filepath: filepath to the modified ontology types

  Returns:
    Generated universe object.
  """

    if modified_types_filepath:
        modified_ontology_exists = path.exists(modified_types_filepath)
        if not modified_ontology_exists:
            print('Specified filepath for modified ontology does not exist')
            return None

        modified_types_filepath = path.expanduser(modified_types_filepath)

        external_file_lib.Validate(filter_text=None,
                                   changed_directory=modified_types_filepath,
                                   original_directory=path.join(
                                       '..', '..', '..', 'ontology', 'yaml',
                                       'resources'),
                                   interactive=False)
        yaml_files = external_file_lib.RecursiveDirWalk(
            modified_types_filepath)
    else:
        # use default location for ontology files
        yaml_files = external_file_lib.RecursiveDirWalk(
            path.join('..', '..', '..', 'ontology', 'yaml', 'resources'))

    config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
    universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe