Skip to content

Commit

Permalink
Implement --clean-meta in ng-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 16, 2024
1 parent 1183080 commit a946415
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ CLI Usage
- vbox_subtitle
- vbox_title

-c META_CLEAN, --clean META_CLEAN
Clean the meta data fields. Possible values: „all“ or
-c META_CLEAN, --clean-meta META_CLEAN
Clean the meta data fields. Possible values: „all“ or a
comma separated list of fields, for example:
„field_one,field_two“.
-D, --delete-duplicates
Deletes combined_lyricist if this field is equal to
Expand Down
2 changes: 1 addition & 1 deletion autocomplete.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-V' '--version' '-b' '--backup' '-k' '--colorize' '-C' '--config-file' '-d' '--dry-run' '-m' '--mscore' '--diff' '-e' '--executable' '-v' '--verbose' '-E' '--export' '-c' '--clean' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--combined' '--combined-meta' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-f' '--format' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '-t' '--target' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--margin' '--header' '--no-header' '--footer' '--no-footer')
_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-V' '--version' '-b' '--backup' '-k' '--colorize' '-C' '--config-file' '-d' '--dry-run' '-m' '--mscore' '--diff' '-e' '--executable' '-v' '--verbose' '-E' '--export' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--combined' '--combined-meta' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-f' '--format' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '-t' '--target' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--margin' '--header' '--no-header' '--footer' '--no-footer')

_shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files
Expand Down
2 changes: 1 addition & 1 deletion autocomplete.tcsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


complete musescore-manager \
'c/--/(alphanum ascii backup clean colorize combined combined-meta config-file delete-duplicates diff distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer format glob header help json list-files list-fonts log margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-footer no-header no-whitespace page-size print-completion remap remap-lyrics rename s3 s4 set-field skip-if-empty staff-space style style-file styles-v3 styles-v4 synchronize target text-font title-font vbox vbox-meta verbose version)/' \
'c/--/(alphanum ascii backup clean-meta colorize combined combined-meta config-file delete-duplicates diff distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer format glob header help json list-files list-fonts log margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-footer no-header no-whitespace page-size print-completion remap remap-lyrics rename s3 s4 set-field skip-if-empty staff-space style style-file styles-v3 styles-v4 synchronize target text-font title-font vbox vbox-meta verbose version)/' \
'c/-/(- A C D E F K L S V Y a b c d e f g h i j k l m n r s t v x y)/' \
'n/--print-completion/(bash zsh tcsh)/' \
'n/-C/f/' \
Expand Down
2 changes: 1 addition & 1 deletion autocomplete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _shtab_musescore_manager_options=(
{-e,--executable}"[Path of the musescore executable.]:general_executable:_files"
"*"{-v,--verbose}"[Make commands more verbose. You can specifiy multiple arguments (. g.\: -vvv) to make the command more verbose.]"
{-E,--export}"[Export the scores in a format defined by the extension. The exported file has the same path, only the file extension is different. Further information can be found at the MuseScore website\: https\:\/\/musescore.org\/en\/handbook\/2\/file-formats, https\:\/\/musescore.org\/en\/handbook\/3\/file-export, https\:\/\/musescore.org\/en\/handbook\/4\/file-export. MuseScore must be installed and the script must know the location of the binary file.]:export_extension:(mscz mscx spos mpos pdf svg png wav mp3 ogg flac mid midi kar musicxml xml mxl brf mei)"
{-c,--clean}"[Clean the meta data fields. Possible values\: \„all\“ or \„field_one,field_two\“.]:meta_clean:"
{-c,--clean-meta}"[Clean the meta data fields. Possible values\: \„all\“ or a comma separated list of fields, for example\: \„field_one,field_two\“.]:meta_clean:"
{-D,--delete-duplicates}"[Deletes combined_lyricist if this field is equal to combined_composer. Deletes combined_subtitle if this field is equal tocombined_title. Move combined_subtitle to combimed_title if combined_title is empty.]"
"*"{-i,--distribute-fields}"[Distribute source fields to target fields by applying a format string on the source fields. It is possible to apply multiple --distribute-fields options. \<source-fields\> can be a single field or a comma separated list of fields\: field_one,field_two. The program tries first to match the \<format-string\> on the first source field. If thisfails, it tries the second source field ... and so on.]:meta_dist:"
{-j,--json}"[Additionally write the meta data to a json file.]"
Expand Down
5 changes: 3 additions & 2 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ Comande line interface
- vbox_subtitle
- vbox_title

-c META_CLEAN, --clean META_CLEAN
Clean the meta data fields. Possible values: „all“ or
-c META_CLEAN, --clean-meta META_CLEAN
Clean the meta data fields. Possible values: „all“ or a
comma separated list of fields, for example:
„field_one,field_two“.
-D, --delete-duplicates
Deletes combined_lyricist if this field is equal to
Expand Down
11 changes: 7 additions & 4 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:

group_meta.add_argument(
"-c",
"--clean",
"--clean-meta",
dest="meta_clean",
help="Clean the meta data fields. Possible values: „all“ or "
help="Clean the meta data fields. Possible values: „all“ or a comma separated "
"list of fields, for example: "
"„field_one,field_two“.",
)

Expand Down Expand Up @@ -810,8 +811,10 @@ def list_styles(version: int) -> None:
# score = Score(file)
# if __no_error(lxml.etree.XMLSyntaxError, score.errors):
# pre: dict[str, str] = score.meta.interface.export_to_dict()
# if args.meta_clean:
# score.meta.clean_metadata(fields_spec=args.meta_clean)

if args.meta_clean:
score.meta.clean_metadata(fields_spec=args.meta_clean)

# if args.meta_json:
# score.meta.export_json()
if args.meta_dist:
Expand Down
59 changes: 49 additions & 10 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,25 +576,63 @@ def test_distribute_field_exception_unmatched(self) -> None:


class TestOptionClean:
@pytest.mark.legacy
def test_clean_all_legacy(self) -> None:
c = (
Cli("meta", "--clean", "all", legacy=True)
.append_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface_read_write
for field in i.fields:
assert getattr(i, field) is None, field

def test_clean_all(self) -> None:
tmp = helper.get_score("meta-all-values.mscx")
Cli("meta", "--clean", "all", tmp, legacy=True).execute()
score = helper.reload(tmp)
i = score.meta.interface_read_write
c = Cli("--clean-meta", "all").append_score("meta-all-values.mscz").execute()
i = c.post.meta.interface_read_write
for field in i.fields:
assert getattr(i, field) is None, field

@pytest.mark.legacy
def test_clean_single_field_legacy(self) -> None:
c = (
Cli("meta", "--clean", "vbox_title", legacy=True)
.append_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface_read_write
assert i.vbox_title is None, "vbox_title"
assert i.vbox_composer == "vbox_composer", "vbox_composer"

def test_clean_single_field(self) -> None:
tmp = helper.get_score("meta-all-values.mscx")
Cli("meta", "--clean", "vbox_title", tmp, legacy=True).execute()
i = reload(tmp)
c = (
Cli("--clean-meta", "vbox_title")
.append_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface_read_write
assert i.vbox_title is None, "vbox_title"
assert i.vbox_composer == "vbox_composer", "vbox_composer"

@pytest.mark.legacy
def test_clean_some_fields_legacy(self) -> None:
c = (
Cli("meta", "--clean", "vbox_title,vbox_composer", legacy=True)
.append_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface_read_write
assert i.vbox_title is None, "vbox_title"
assert i.vbox_composer is None, "vbox_composer"
assert i.vbox_subtitle == "vbox_subtitle", "vbox_subtitle"

def test_clean_some_fields(self) -> None:
tmp = helper.get_score("meta-all-values.mscx")
Cli("meta", "--clean", "vbox_title,vbox_composer", tmp, legacy=True).execute()
i = reload(tmp)
c = (
Cli("--clean-meta", "vbox_title,vbox_composer")
.append_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface_read_write
assert i.vbox_title is None, "vbox_title"
assert i.vbox_composer is None, "vbox_composer"
assert i.vbox_subtitle == "vbox_subtitle", "vbox_subtitle"
Expand Down Expand Up @@ -879,6 +917,7 @@ def test_multiple_times(self) -> None:
assert i.vbox_title == "vt"
assert i.vbox_composer == "vc"

@pytest.mark.legacy
def test_with_templating_legacy(self) -> None:
c = (
Cli(
Expand Down

0 comments on commit a946415

Please sign in to comment.