Skip to content

Commit a946415

Browse files
Implement --clean-meta in ng-cli
1 parent 1183080 commit a946415

File tree

7 files changed

+65
-21
lines changed

7 files changed

+65
-21
lines changed

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,9 @@ CLI Usage
386386
- vbox_subtitle
387387
- vbox_title
388388

389-
-c META_CLEAN, --clean META_CLEAN
390-
Clean the meta data fields. Possible values: „all“ or
389+
-c META_CLEAN, --clean-meta META_CLEAN
390+
Clean the meta data fields. Possible values: „all“ or a
391+
comma separated list of fields, for example:
391392
„field_one,field_two“.
392393
-D, --delete-duplicates
393394
Deletes combined_lyricist if this field is equal to

autocomplete.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44

5-
_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')
5+
_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')
66

77
_shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files
88
_shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files

autocomplete.tcsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
complete musescore-manager \
6-
'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)/' \
6+
'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)/' \
77
'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)/' \
88
'n/--print-completion/(bash zsh tcsh)/' \
99
'n/-C/f/' \

autocomplete.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _shtab_musescore_manager_options=(
2323
{-e,--executable}"[Path of the musescore executable.]:general_executable:_files"
2424
"*"{-v,--verbose}"[Make commands more verbose. You can specifiy multiple arguments (. g.\: -vvv) to make the command more verbose.]"
2525
{-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)"
26-
{-c,--clean}"[Clean the meta data fields. Possible values\: \„all\“ or \„field_one,field_two\“.]:meta_clean:"
26+
{-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:"
2727
{-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.]"
2828
"*"{-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:"
2929
{-j,--json}"[Additionally write the meta data to a json file.]"

docs/cli.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ Comande line interface
150150
- vbox_subtitle
151151
- vbox_title
152152

153-
-c META_CLEAN, --clean META_CLEAN
154-
Clean the meta data fields. Possible values: „all“ or
153+
-c META_CLEAN, --clean-meta META_CLEAN
154+
Clean the meta data fields. Possible values: „all“ or a
155+
comma separated list of fields, for example:
155156
„field_one,field_two“.
156157
-D, --delete-duplicates
157158
Deletes combined_lyricist if this field is equal to

mscxyz/cli.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,10 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:
255255

256256
group_meta.add_argument(
257257
"-c",
258-
"--clean",
258+
"--clean-meta",
259259
dest="meta_clean",
260-
help="Clean the meta data fields. Possible values: „all“ or "
260+
help="Clean the meta data fields. Possible values: „all“ or a comma separated "
261+
"list of fields, for example: "
261262
"„field_one,field_two“.",
262263
)
263264

@@ -810,8 +811,10 @@ def list_styles(version: int) -> None:
810811
# score = Score(file)
811812
# if __no_error(lxml.etree.XMLSyntaxError, score.errors):
812813
# pre: dict[str, str] = score.meta.interface.export_to_dict()
813-
# if args.meta_clean:
814-
# score.meta.clean_metadata(fields_spec=args.meta_clean)
814+
815+
if args.meta_clean:
816+
score.meta.clean_metadata(fields_spec=args.meta_clean)
817+
815818
# if args.meta_json:
816819
# score.meta.export_json()
817820
if args.meta_dist:

tests/test_meta.py

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,25 +576,63 @@ def test_distribute_field_exception_unmatched(self) -> None:
576576

577577

578578
class TestOptionClean:
579+
@pytest.mark.legacy
580+
def test_clean_all_legacy(self) -> None:
581+
c = (
582+
Cli("meta", "--clean", "all", legacy=True)
583+
.append_score("meta-all-values.mscz")
584+
.execute()
585+
)
586+
i = c.post.meta.interface_read_write
587+
for field in i.fields:
588+
assert getattr(i, field) is None, field
589+
579590
def test_clean_all(self) -> None:
580-
tmp = helper.get_score("meta-all-values.mscx")
581-
Cli("meta", "--clean", "all", tmp, legacy=True).execute()
582-
score = helper.reload(tmp)
583-
i = score.meta.interface_read_write
591+
c = Cli("--clean-meta", "all").append_score("meta-all-values.mscz").execute()
592+
i = c.post.meta.interface_read_write
584593
for field in i.fields:
585594
assert getattr(i, field) is None, field
586595

596+
@pytest.mark.legacy
597+
def test_clean_single_field_legacy(self) -> None:
598+
c = (
599+
Cli("meta", "--clean", "vbox_title", legacy=True)
600+
.append_score("meta-all-values.mscz")
601+
.execute()
602+
)
603+
i = c.post.meta.interface_read_write
604+
assert i.vbox_title is None, "vbox_title"
605+
assert i.vbox_composer == "vbox_composer", "vbox_composer"
606+
587607
def test_clean_single_field(self) -> None:
588-
tmp = helper.get_score("meta-all-values.mscx")
589-
Cli("meta", "--clean", "vbox_title", tmp, legacy=True).execute()
590-
i = reload(tmp)
608+
c = (
609+
Cli("--clean-meta", "vbox_title")
610+
.append_score("meta-all-values.mscz")
611+
.execute()
612+
)
613+
i = c.post.meta.interface_read_write
591614
assert i.vbox_title is None, "vbox_title"
592615
assert i.vbox_composer == "vbox_composer", "vbox_composer"
593616

617+
@pytest.mark.legacy
618+
def test_clean_some_fields_legacy(self) -> None:
619+
c = (
620+
Cli("meta", "--clean", "vbox_title,vbox_composer", legacy=True)
621+
.append_score("meta-all-values.mscz")
622+
.execute()
623+
)
624+
i = c.post.meta.interface_read_write
625+
assert i.vbox_title is None, "vbox_title"
626+
assert i.vbox_composer is None, "vbox_composer"
627+
assert i.vbox_subtitle == "vbox_subtitle", "vbox_subtitle"
628+
594629
def test_clean_some_fields(self) -> None:
595-
tmp = helper.get_score("meta-all-values.mscx")
596-
Cli("meta", "--clean", "vbox_title,vbox_composer", tmp, legacy=True).execute()
597-
i = reload(tmp)
630+
c = (
631+
Cli("--clean-meta", "vbox_title,vbox_composer")
632+
.append_score("meta-all-values.mscz")
633+
.execute()
634+
)
635+
i = c.post.meta.interface_read_write
598636
assert i.vbox_title is None, "vbox_title"
599637
assert i.vbox_composer is None, "vbox_composer"
600638
assert i.vbox_subtitle == "vbox_subtitle", "vbox_subtitle"
@@ -879,6 +917,7 @@ def test_multiple_times(self) -> None:
879917
assert i.vbox_title == "vt"
880918
assert i.vbox_composer == "vc"
881919

920+
@pytest.mark.legacy
882921
def test_with_templating_legacy(self) -> None:
883922
c = (
884923
Cli(

0 commit comments

Comments
 (0)