Skip to content

Commit

Permalink
Convert clean subcommand to --clean option in the NG cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 19, 2024
1 parent 1299468 commit 8f3073c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 48 deletions.
15 changes: 6 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ CLI Usage
[-r LYRICS_REMAP] [-F] [--rename] [-f RENAME_FORMAT]
[-A] [-a] [-n] [-K FIELDS] [-t RENAME_TARGET] [-L]
[-g <glob-pattern> | --mscz | --mscx]
[-s <style-name> <value>] [-Y <file>] [--s3] [--s4]
[--list-fonts] [--text-font <font-face>]
[-s <style-name> <value>] [--clean] [-Y <file>] [--s3]
[--s4] [--list-fonts] [--text-font <font-face>]
[--title-font <font-face>]
[--musical-symbol-font <font-face>]
[--musical-text-font <font-face>]
Expand Down Expand Up @@ -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 <file>, --style-file <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:

Expand Down Expand Up @@ -699,6 +692,10 @@ CLI Usage

-s <style-name> <value>, --style <style-name> <value>
Set a single style value. For example: --style pageWidth 8.5
--clean Clean and reset the formating of the "*.mscx" file
-Y <file>, --style-file <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.
Expand Down
3 changes: 2 additions & 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-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
Expand Down Expand Up @@ -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
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-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/' \
Expand Down
1 change: 1 addition & 0 deletions autocomplete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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.]"
Expand Down
15 changes: 6 additions & 9 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <glob-pattern> | --mscz | --mscx]
[-s <style-name> <value>] [-Y <file>] [--s3] [--s4]
[--list-fonts] [--text-font <font-face>]
[-s <style-name> <value>] [--clean] [-Y <file>] [--s3]
[--s4] [--list-fonts] [--text-font <font-face>]
[--title-font <font-face>]
[--musical-symbol-font <font-face>]
[--musical-text-font <font-face>]
Expand Down Expand Up @@ -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 <file>, --style-file <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:

Expand Down Expand Up @@ -432,6 +425,10 @@ Comande line interface

-s <style-name> <value>, --style <style-name> <value>
Set a single style value. For example: --style pageWidth 8.5
--clean Clean and reset the formating of the "*.mscx" file
-Y <file>, --style-file <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.
Expand Down
18 changes: 8 additions & 10 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
###############################################################################
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions mscxyz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 19 additions & 18 deletions tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,32 +317,33 @@ 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 "<font" in uncleaned
assert "<b>" in uncleaned
assert "<i>" in uncleaned
# assert "<pos" in uncleaned
assert "<LayoutBreak>" in uncleaned
assert "<StemDirection>" in uncleaned

cleaned: str = c.post.read_as_text()
assert "<font" not in cleaned
assert "<b>" not in cleaned
assert "<i>" not in cleaned
assert "<pos" not in cleaned
assert "<LayoutBreak>" not in cleaned
assert "<StemDirection>" 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 "<staffUpperBorder>77</staffUpperBorder>" 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 "<staffUpperBorder>77</staffUpperBorder>" in style


def test_load_style_file() -> None:
Expand Down

0 comments on commit 8f3073c

Please sign in to comment.