Skip to content

Commit

Permalink
New option --remove-origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Feb 11, 2024
1 parent a0d9b22 commit bc8ba94
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ test_quick:
test_gui:
poetry run pytest -m "gui"

test_all:
poetry run pytest

test_real_binary:
pytest _test_real-binary.py

Expand Down
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,11 @@ CLI Usage

usage: musescore-manager [-h] [--print-completion {bash,zsh,tcsh}]
[-C <file-path>] [-b] [-d] [--catch-errors] [-m]
[-e FILE_PATH] [-E <extension>] [--compress] [-V] [-v]
[-k | --color | --no-color] [--diff] [--print-xml]
[-c <fields>] [-D] [-i <source-fields> <format-string>]
[-j] [-l <log-file> <format-string>] [-y]
[-e FILE_PATH] [-E <extension>] [--compress]
[--remove-origin] [-V] [-v] [-k | --color | --no-color]
[--diff] [--print-xml] [-c <fields>] [-D]
[-i <source-fields> <format-string>] [-j]
[-l <log-file> <format-string>] [-y]
[-S <field> <format-string>]
[--metatag <field> <value>] [--vbox <field> <value>]
[--title <string>] [--subtitle <string>]
Expand Down Expand Up @@ -697,6 +698,9 @@ CLI Usage
the binary file.
--compress Save an uncompressed MuseScore file (*.mscx) as a compressed
file (*.mscz).
--remove-origin Delete the uncompressed original MuseScore file (*.mscx) if
it has been successfully converted to a compressed file
(*.mscz).

info:
Print informations about the score and the CLI interface itself.
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' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-E' '--export' '--compress' '-V' '--version' '-v' '--verbose' '-k' '--color' '--no-color' '--diff' '--print-xml' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '--list-fields' '--list-functions' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--reset-small-staffs' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even')
_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-E' '--export' '--compress' '--remove-origin' '-V' '--version' '-v' '--verbose' '-k' '--color' '--no-color' '--diff' '--print-xml' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '--list-fields' '--list-functions' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--reset-small-staffs' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even')

_shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files
Expand Down Expand Up @@ -30,6 +30,7 @@ _shtab_musescore_manager__m_nargs=0
_shtab_musescore_manager___mscore_nargs=0
_shtab_musescore_manager___save_in_mscore_nargs=0
_shtab_musescore_manager___compress_nargs=0
_shtab_musescore_manager___remove_origin_nargs=0
_shtab_musescore_manager__V_nargs=0
_shtab_musescore_manager___version_nargs=0
_shtab_musescore_manager__v_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/--/(a4 alphanum ascii backup catch-errors clean clean-meta color composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-fields list-files list-fonts list-functions log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-color no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion print-xml remap remap-lyrics rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \
'c/--/(a4 alphanum ascii backup catch-errors clean clean-meta color composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-fields list-files list-fonts list-functions log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-color no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion print-xml remap remap-lyrics remove-origin rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \
'c/-/(- A C D E F K L S V Y a b c d e 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 @@ -21,6 +21,7 @@ _shtab_musescore_manager_options=(
{-e,--executable}"[Path of the musescore executable.]:general_executable:_files"
{-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)"
"--compress[Save an uncompressed MuseScore file (\*.mscx) as a compressed file (\*.mscz).]"
"--remove-origin[Delete the uncompressed original MuseScore file (\*.mscx) if it has been successfully converted to a compressed file (\*.mscz).]"
"(- : *)"{-V,--version}"[show program\'s version number and exit]"
"*"{-v,--verbose}"[Make commands more verbose. You can specifiy multiple arguments (. g.\: -vvv) to make the command more verbose.]"
{-k,--color,--no-color}"[Colorize the command line print statements. (default\: True)]:info_color:"
Expand Down
12 changes: 8 additions & 4 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Comande line interface

usage: musescore-manager [-h] [--print-completion {bash,zsh,tcsh}]
[-C <file-path>] [-b] [-d] [--catch-errors] [-m]
[-e FILE_PATH] [-E <extension>] [--compress] [-V] [-v]
[-k | --color | --no-color] [--diff] [--print-xml]
[-c <fields>] [-D] [-i <source-fields> <format-string>]
[-j] [-l <log-file> <format-string>] [-y]
[-e FILE_PATH] [-E <extension>] [--compress]
[--remove-origin] [-V] [-v] [-k | --color | --no-color]
[--diff] [--print-xml] [-c <fields>] [-D]
[-i <source-fields> <format-string>] [-j]
[-l <log-file> <format-string>] [-y]
[-S <field> <format-string>]
[--metatag <field> <value>] [--vbox <field> <value>]
[--title <string>] [--subtitle <string>]
Expand Down Expand Up @@ -74,6 +75,9 @@ Comande line interface
the binary file.
--compress Save an uncompressed MuseScore file (*.mscx) as a compressed
file (*.mscz).
--remove-origin Delete the uncompressed original MuseScore file (*.mscx) if
it has been successfully converted to a compressed file
(*.mscz).

info:
Print informations about the score and the CLI interface itself.
Expand Down
22 changes: 17 additions & 5 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ def setup_parser() -> argparse.ArgumentParser:
help="Save an uncompressed MuseScore file (*.mscx) as a compressed file (*.mscz).",
)

export.add_argument(
"--remove-origin",
dest="export_remove_origin",
action="store_true",
help="Delete the uncompressed original MuseScore file (*.mscx) if it has been "
"successfully converted to a compressed file (*.mscz).",
)

###############################################################################
# info
###############################################################################
Expand Down Expand Up @@ -820,7 +828,7 @@ def list_styles(version: int) -> None:
score.make_snapshot()

if args.export_compress:
score = Score(score.export.compress())
score = Score(score.export.compress(args.export_remove_origin))

# style

Expand Down Expand Up @@ -995,20 +1003,24 @@ def list_styles(version: int) -> None:
if manipulate_meta:
score.fields.diff(args)

# export

if args.export_extension:
score.export.to_extension(args.export_extension)
# info

if args.info_diff:
score.print_diff()

if args.info_print_xml:
print(score.xml_string)

# save

if not args.general_dry_run:
score.save()

# export

if args.export_extension:
score.export.to_extension(args.export_extension)

# rename

if args.rename_rename:
Expand Down
7 changes: 5 additions & 2 deletions mscxyz/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ def to_extension(self, extension: str = "pdf") -> Path:
)
return dest

def compress(self) -> Path:
def compress(self, remove_origin: bool = False) -> Path:
"""Compress the score.
:return: The path of the new compressed score or the path of the score itself
if it is already compressed.
"""
if not self.score.is_uncompressed:
return self.score.path
return self.to_extension("mscz")
new_path = self.to_extension("mscz")
if remove_origin:
self.score.path.unlink()
return new_path

def reload(self, save: bool = False) -> Export:
"""
Expand Down
1 change: 1 addition & 0 deletions mscxyz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DefaultArguments:
# export
export_extension: Optional[str] = None
export_compress: bool = False
export_remove_origin: bool = False

# info
info_verbose: int = 0
Expand Down
9 changes: 9 additions & 0 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ def test_export_fails(self) -> None:
def test_compress() -> None:
score = Cli("--compress").append_score("simple.mscx", 3).score()
dest = str(score.path).replace(".mscx", ".mscz")
assert score.exists()
assert Path(dest).exists()


@pytest.mark.slow
def test_remove_origin() -> None:
score = Cli("--compress", "--remove-origin").append_score("simple.mscx", 3).score()
dest = str(score.path).replace(".mscx", ".mscz")
assert not score.exists()
assert Path(dest).exists()

0 comments on commit bc8ba94

Please sign in to comment.