Skip to content

Refactor REMOVE_VERSIONS m4 macros #1223

@ndp-opendap

Description

@ndp-opendap

Overview

This is a ticket to refactor our REMOVE_VERSIONS m4 macro and make the associated changes to the baseline files.

It currently has two behaviors we want to alter/add:

  1. When we replace the dmrpp:version attribute and value we do so in a way that makes the resulting XML file incorrectly formed. This should be fixed.
  2. The value of the dmrVersion attribute recently changed from 1.0 to 2.0. All of the dmr/dap baselines were changed to 2.0. Rather than doing that we should also add a replacement clause to remove the dmrVersion value.

Corollary: We might also consider making this operation a bash script saved as bes/bin/remove_versions and utilizing it from there rather than have it's programmatic expression be in multiple m4 file. Single Source of Truth and all that. This would also allow us to have a more understandable invocation without the m4 [ ] shenanigans, and we could write unit tests as functions in the script file. Just sayin...

Current macro:

m4_define([REMOVE_VERSIONS], [dnl
  awk '{
    gsub(/<Value>[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?<\/Value>/, "<Value>removed version</Value>");
    gsub(/<Value>[[a-zA-Z._]+]-[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?<\/Value>/, "<Value>removed version</Value>");
    gsub(/dmrpp:version="[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?"/, "removed dmrpp:version");
    print
  }' < $1 > $1.awk
  mv $1.awk $1
])

Item 1

Change the current dmrpp:version removal to one that doesn't produce incorrectly formed XML as the result

    gsub(/dmrpp:version="[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?"/, "removed dmrpp:version");

Would become:

    gsub(/dmrpp:version="[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?"/, "dmrpp:version= \"removed\"");

Item 2

Add support for removing the dmrVersion attribute value:

    gsub(/dmrVersion="[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?"/, "dmrVersion = \"removed\"");

Result

m4_define([REMOVE_VERSIONS], [dnl
  awk '{
    gsub(/<Value>[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?<\/Value>/, "<Value>removed version</Value>");
    gsub(/<Value>[[a-zA-Z._]+]-[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?<\/Value>/, "<Value>removed version</Value>");
    gsub(/dmrpp:version="[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?"/, "dmrpp:version= \"removed\"");
    gsub(/dmrVersion="[[0-9]+]\.[[0-9]+]\.[[0-9]+](-[[0-9]+])?"/, "dmrVersion = \"removed\"");
    print
  }' < $1 > $1.awk
  mv $1.awk $1
])

Consequences

Many baselines will need to be updated.

☝️hannahilea ☝️@jgallagher59701 ☝️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions