From 8f3073cc3352819c6802bd1b3f1374d867771879 Mon Sep 17 00:00:00 2001 From: Josef Friedrich Date: Fri, 19 Jan 2024 15:35:04 +0100 Subject: [PATCH] Convert clean subcommand to --clean option in the NG cli --- README.rst | 15 ++++++--------- autocomplete.bash | 3 ++- autocomplete.tcsh | 2 +- autocomplete.zsh | 1 + docs/cli.rst | 15 ++++++--------- mscxyz/cli.py | 18 ++++++++---------- mscxyz/settings.py | 1 + tests/test_style.py | 37 +++++++++++++++++++------------------ 8 files changed, 44 insertions(+), 48 deletions(-) diff --git a/README.rst b/README.rst index 25a8fa9..e913a04 100644 --- a/README.rst +++ b/README.rst @@ -282,8 +282,8 @@ CLI Usage [-r LYRICS_REMAP] [-F] [--rename] [-f RENAME_FORMAT] [-A] [-a] [-n] [-K FIELDS] [-t RENAME_TARGET] [-L] [-g | --mscz | --mscx] - [-s ] [-Y ] [--s3] [--s4] - [--list-fonts] [--text-font ] + [-s ] [--clean] [-Y ] [--s3] + [--s4] [--list-fonts] [--text-font ] [--title-font ] [--musical-symbol-font ] [--musical-text-font ] @@ -327,13 +327,6 @@ CLI Usage must be installed and the script must know the location of the binary file. - clean: - Clean and reset the formating of the "*.mscx" file - - -Y , --style-file - Load a "*.mss" style file and include the contents of this - file. - meta: Deal with meta data informations stored in the MuseScore file. MuseScore can store meta data informations in different places: @@ -699,6 +692,10 @@ CLI Usage -s , --style Set a single style value. For example: --style pageWidth 8.5 + --clean Clean and reset the formating of the "*.mscx" file + -Y , --style-file + Load a "*.mss" style file and include the contents of this + file. --s3, --styles-v3 List all possible version 3 styles. --s4, --styles-v4 List all possible version 4 styles. --list-fonts List all font related styles. diff --git a/autocomplete.bash b/autocomplete.bash index a658f71..96a078c 100644 --- a/autocomplete.bash +++ b/autocomplete.bash @@ -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-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_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' '--clean' '-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 @@ -66,6 +66,7 @@ _shtab_musescore_manager___mscz_nargs=0 _shtab_musescore_manager___mscx_nargs=0 _shtab_musescore_manager__s_nargs=2 _shtab_musescore_manager___style_nargs=2 +_shtab_musescore_manager___clean_nargs=0 _shtab_musescore_manager___s3_nargs=0 _shtab_musescore_manager___styles_v3_nargs=0 _shtab_musescore_manager___s4_nargs=0 diff --git a/autocomplete.tcsh b/autocomplete.tcsh index 1c92821..89b4ac3 100644 --- a/autocomplete.tcsh +++ b/autocomplete.tcsh @@ -3,7 +3,7 @@ complete musescore-manager \ - '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/--/(alphanum ascii backup clean 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/' \ diff --git a/autocomplete.zsh b/autocomplete.zsh index 3460ad6..2151f9f 100644 --- a/autocomplete.zsh +++ b/autocomplete.zsh @@ -48,6 +48,7 @@ _shtab_musescore_manager_options=( "--mscz[Take only \"\*.mscz\" files into account.]" "--mscx[Take only \"\*.mscx\" files into account.]" "*"{-s,--style}"[Set a single style value. For example\: --style pageWidth 8.5]:style_value:" + "--clean[Clean and reset the formating of the \"\*.mscx\" file]" {-Y,--style-file}"[Load a \"\*.mss\" style file and include the contents of this file.]:style_file:_files" {--s3,--styles-v3}"[List all possible version 3 styles.]" {--s4,--styles-v4}"[List all possible version 4 styles.]" diff --git a/docs/cli.rst b/docs/cli.rst index 7c4ba21..7b0bfdc 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -15,8 +15,8 @@ Comande line interface [-r LYRICS_REMAP] [-F] [--rename] [-f RENAME_FORMAT] [-A] [-a] [-n] [-K FIELDS] [-t RENAME_TARGET] [-L] [-g | --mscz | --mscx] - [-s ] [-Y ] [--s3] [--s4] - [--list-fonts] [--text-font ] + [-s ] [--clean] [-Y ] [--s3] + [--s4] [--list-fonts] [--text-font ] [--title-font ] [--musical-symbol-font ] [--musical-text-font ] @@ -60,13 +60,6 @@ Comande line interface must be installed and the script must know the location of the binary file. - clean: - Clean and reset the formating of the "*.mscx" file - - -Y , --style-file - Load a "*.mss" style file and include the contents of this - file. - meta: Deal with meta data informations stored in the MuseScore file. MuseScore can store meta data informations in different places: @@ -432,6 +425,10 @@ Comande line interface -s , --style Set a single style value. For example: --style pageWidth 8.5 + --clean Clean and reset the formating of the "*.mscx" file + -Y , --style-file + Load a "*.mss" style file and include the contents of this + file. --s3, --styles-v3 List all possible version 3 styles. --s4, --styles-v4 List all possible version 4 styles. --list-fonts List all font related styles. diff --git a/mscxyz/cli.py b/mscxyz/cli.py index e0368e5..200c08a 100644 --- a/mscxyz/cli.py +++ b/mscxyz/cli.py @@ -155,15 +155,6 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: # groups in alphabetical order ############################################################################### -############################################################################### -# clean -############################################################################### - -group_clean = parser.add_argument_group( - "clean", - 'Clean and reset the formating of the "*.mscx" file', -) - ############################################################################### # export ############################################################################### @@ -530,8 +521,15 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: help="Set a single style value. For example: --style pageWidth 8.5", ) +group_style.add_argument( + "--clean", + dest="style_clean", + action="store_true", + help='Clean and reset the formating of the "*.mscx" file', +) + file_completers.append( - group_clean.add_argument( + group_style.add_argument( "-Y", "--style-file", dest="style_file", diff --git a/mscxyz/settings.py b/mscxyz/settings.py index db7def6..61c15f5 100644 --- a/mscxyz/settings.py +++ b/mscxyz/settings.py @@ -67,6 +67,7 @@ class DefaultArguments: # style style_value: list[tuple[str, str]] = [] + style_clean: bool = False style_file: Optional[TextIOWrapper] = None style_styles_v3: bool = False style_styles_v4: bool = False diff --git a/tests/test_style.py b/tests/test_style.py index a607763..646e9ab 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -317,10 +317,18 @@ def test_method_set_all(styles: str) -> None: class TestClean: - def _test_clean(self, version: int = 2) -> None: - tmp: str = helper.get_file("formats.mscx", version) - Cli("clean", tmp, legacy=True).execute() - cleaned: str = helper.read_file(tmp) + def test_clean(self) -> None: + c = Cli("clean", legacy=True).append_score("formats.mscz").execute() + + uncleaned: str = c.pre.read_as_text() + assert "" in uncleaned + assert "" in uncleaned + # assert "" in uncleaned + assert "" in uncleaned + + cleaned: str = c.post.read_as_text() assert "" not in cleaned assert "" not in cleaned @@ -328,21 +336,14 @@ def _test_clean(self, version: int = 2) -> None: assert "" not in cleaned assert "" not in cleaned - def test_clean(self) -> None: - self._test_clean(version=2) - self._test_clean(version=3) - - def _test_clean_add_style(self, version: int = 2) -> None: - tmp = helper.get_file("simple.mscx", version) - Cli( - "clean", "--style", helper.get_score("style.mss", version), tmp, legacy=True - ).execute() - style = helper.read_file(tmp) - assert "77" in style - def test_clean_add_style(self) -> None: - self._test_clean_add_style(version=2) - self._test_clean_add_style(version=3) + score = ( + Cli("clean", "--style", helper.get_score("style.mss", 2), legacy=True) + .append_score("simple.mscx", 2) + .score() + ) + style = score.read_as_text() + assert "77" in style def test_load_style_file() -> None: