Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 27, 2024
1 parent 8566e25 commit ad0a181
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 36 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ activate_venv:
pin_docs_requirements:
pip-compile --output-file=docs/requirements.txt docs/requirements.in pyproject.toml

# autocomplete:
# musescore-manager --print-completion zsh > autocomplete.zsh
# musescore-manager --print-completion bash > autocomplete.bash
# musescore-manager --print-completion tcsh > autocomplete.tcsh
autocomplete:
poetry run musescore-manager --print-completion zsh > autocomplete.zsh
poetry run musescore-manager --print-completion bash > autocomplete.bash
poetry run musescore-manager --print-completion tcsh > autocomplete.tcsh

install_autocomplete: autocomplete
cp autocomplete.zsh "$(HOME)/.zsh-completions/_musescore-manager"
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ To apply glob patterns on the file paths, the ``--glob`` option can be used.
To selection only *mscz* oder *mscx* files use the options ``--mscz`` or ``--mscx``.
Don’t mix the options ``--mscz`` and ``--mscx`` with the option ``--glob``.

The python package ``mscxyz`` exports a function named ``list_files`` which can
The python package ``mscxyz`` exports a function named ``list_path`` which can
be used to list the paths of MuseScore files. This allows you to list score
paths in a nested folder structure in a similar way to the command line.
This folder structure is used for the following example:
Expand All @@ -99,10 +99,10 @@ This folder structure is used for the following example:

.. code-block:: Python
from mscxyz import list_files, Score
from mscxyz import list_path, Score
score_paths = []
for score_path in list_files(path="/home/xyz/scores", extension="mscz"):
for score_path in list_path(path="/home/xyz/scores", extension="mscz"):
score = Score(score_path)
assert score.path.exists()
assert score.extension == "mscz"
Expand Down
6 changes: 3 additions & 3 deletions README_template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ To apply glob patterns on the file paths, the ``--glob`` option can be used.
To selection only *mscz* oder *mscx* files use the options ``--mscz`` or ``--mscx``.
Don’t mix the options ``--mscz`` and ``--mscx`` with the option ``--glob``.

The python package ``mscxyz`` exports a function named ``list_files`` which can
The python package ``mscxyz`` exports a function named ``list_path`` which can
be used to list the paths of MuseScore files. This allows you to list score
paths in a nested folder structure in a similar way to the command line.
This folder structure is used for the following example:
Expand All @@ -95,10 +95,10 @@ This folder structure is used for the following example:

.. code-block:: Python
from mscxyz import list_files, Score
from mscxyz import list_path, Score
score_paths = []
for score_path in list_files(path="/home/xyz/scores", extension="mscz"):
for score_path in list_path(path="/home/xyz/scores", extension="mscz"):
score = Score(score_path)
assert score.path.exists()
assert score.extension == "mscz"
Expand Down
5 changes: 2 additions & 3 deletions 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' '--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_option_strings=('-h' '--help' '--print-completion' '-V' '--version' '-b' '--backup' '--bail' '-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' '-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 All @@ -23,6 +23,7 @@ _shtab_musescore_manager__V_nargs=0
_shtab_musescore_manager___version_nargs=0
_shtab_musescore_manager__b_nargs=0
_shtab_musescore_manager___backup_nargs=0
_shtab_musescore_manager___bail_nargs=0
_shtab_musescore_manager__k_nargs=0
_shtab_musescore_manager___colorize_nargs=0
_shtab_musescore_manager__d_nargs=0
Expand All @@ -48,8 +49,6 @@ _shtab_musescore_manager___metatag_nargs=2
_shtab_musescore_manager___metatag_meta_nargs=2
_shtab_musescore_manager___vbox_nargs=2
_shtab_musescore_manager___vbox_meta_nargs=2
_shtab_musescore_manager___combined_nargs=2
_shtab_musescore_manager___combined_meta_nargs=2
_shtab_musescore_manager__F_nargs=0
_shtab_musescore_manager___fix_nargs=0
_shtab_musescore_manager___fix_lyrics_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 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 bail clean clean-meta colorize 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
91 changes: 91 additions & 0 deletions autocomplete.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#compdef musescore-manager

# AUTOMATICALLY GENERATED by `shtab`


_shtab_musescore_manager_commands() {
local _commands=(

)
_describe 'musescore-manager commands' _commands
}

_shtab_musescore_manager_options=(
"(- : *)"{-h,--help}"[show this help message and exit]"
"(- : *)--print-completion[print shell completion script]:print_completion:(bash zsh tcsh)"
"(- : *)"{-V,--version}"[show program\'s version number and exit]"
{-b,--backup}"[Create a backup file.]"
"--bail[Stop execution when an exception occurs.]"
{-k,--colorize}"[Colorize the command line print statements.]"
{-C,--config-file}"[Specify a configuration file in the INI format.]:general_config_file:_files"
{-d,--dry-run}"[Simulate the actions.]"
{-m,--mscore}"[Open and save the XML file in MuseScore after manipulating the XML with lxml to avoid differences in the XML structure.]"
"--diff[Show a diff of the XML file before and after the manipulation.]"
{-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-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}"[Write the meta data to a json file. The resulting file has the same path as the input file, only the extension is changed to \“json\”.]"
{-l,--log}"[Write one line per file to a text file. e. g. --log \/tmp\/musescore-manager.log \'\$title \$composer\']:meta_log:"
{-y,--synchronize}"[Synchronize the values of the first vertical frame (vbox) (title, subtitle, composer, lyricist) with the corresponding metadata fields]"
"*"{-S,--set-field}"[Set value to meta data fields.]:meta_set:"
"*"{--metatag,--metatag-meta}"[Define the metadata in MetaTag elements. Available fields\: arranger, audio_com_url, composer, copyright, creation_date, lyricist, movement_number, movement_title, msc_version, platform, poet, source, source_revision_id, subtitle, translator, work_number, work_title.]:meta_metatag:"
"*"{--vbox,--vbox-meta}"[Define the metadata in VBox elements. Available fields\: composer, lyricist, subtitle, title.]:meta_vbox:"
{-x,--extract,--extract-lyrics}"[Extract each lyrics verse into a separate MuseScore file. Specify \”all\” to extract all lyrics verses. The old verse number is appended to the file name, e. g.\: score_1.mscx.]:lyrics_extract:"
{-r,--remap,--remap-lyrics}"[Remap lyrics. Example\: \"--remap 3\:2,5\:3\". This example remaps lyrics verse 3 to verse 2 and verse 5 to 3. Use commas to specify multiple remap pairs. One remap pair is separated by a colon in this form\: \"old\:new\"\: \"old\" stands for the old verse number. \"new\" stands for the new verse number.]:lyrics_remap:"
{-F,--fix,--fix-lyrics}"[Fix lyrics\: Convert trailing hyphens (\"la- la- la\") to a correct hyphenation (\"la - la - la\")]"
"--rename[Format string.]"
{-f,--format}"[Format string.]:rename_format:"
{-A,--alphanum}"[Use only alphanumeric characters.]"
{-a,--ascii}"[Use only ASCII characters.]"
{-n,--no-whitespace}"[Replace all whitespaces with dashes or sometimes underlines.]"
{-K,--skip-if-empty}"[Skip rename action if FIELDS are empty. Separate FIELDS using commas\: composer,title]:rename_skip:"
{-t,--target}"[Target directory]:rename_target:"
{-L,--list-files}"[Only list files and do nothing else.]"
{-g,--glob}"[Handle only files which matches against Unix style glob patterns (e. g. \"\*.mscx\", \"\* - \*\"). If you omit this option, the standard glob pattern \"\*.msc\[xz\]\" is used.]:selection_glob:"
"--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.]"
"--list-fonts[List all font related styles.]"
"--text-font[Set nearly all fonts except \“romanNumeralFontFace\”, \“figuredBassFontFace\”, \“dynamicsFontFace\“, \“musicalSymbolFont\” and \“musicalTextFont\”.]:style_text_font:"
"--title-font[Set \“titleFontFace\” and \“subTitleFontFace\”.]:style_title_font:"
"--musical-symbol-font[Set \“musicalSymbolFont\”, \“dynamicsFont\” and \“dynamicsFontFace\”.]:style_musical_symbol_font:"
"--musical-text-font[Set \“musicalTextFont\”.]:style_musical_text_font:"
"--staff-space[Set the staff space or spatium. This is the vertical distance between two lines of a music staff.]:style_staff_space:"
"--page-size[Set the page size.]:style_page_size:"
"--margin[Set the top, right, bottom and left margins to the same value.]:style_margin:"
{--header,--no-header}"[Show or hide the header]:style_show_header:"
{--footer,--no-footer}"[Show or hide the footer.]:style_show_footer:"
"(*)::Path to a \"\*.msc\[zx\]\" file or a folder containing \"\*.msc\[zx\]\" files. can be specified several times.:_files"
)


_shtab_musescore_manager() {
local context state line curcontext="$curcontext" one_or_more='(-)*' remainder='(*)'

if ((${_shtab_musescore_manager_options[(I)${(q)one_or_more}*]} + ${_shtab_musescore_manager_options[(I)${(q)remainder}*]} == 0)); then # noqa: E501
_shtab_musescore_manager_options+=(': :_shtab_musescore_manager_commands' '*::: :->musescore-manager')
fi
_arguments -C -s $_shtab_musescore_manager_options

case $state in
musescore-manager)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:_shtab_musescore_manager-$line[1]:"
case $line[1] in

esac
esac
}



typeset -A opt_args
_shtab_musescore_manager "$@"
2 changes: 1 addition & 1 deletion docs/main-module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Main module
:toctree: stubs
:nosignatures:

mscxyz.list_files
mscxyz.list_path
mscxyz.Score

.. automodule:: mscxyz
6 changes: 0 additions & 6 deletions docs/stubs/mscxyz.list_files.rst

This file was deleted.

6 changes: 6 additions & 0 deletions docs/stubs/mscxyz.list_path.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mscxyz.list\_path
=================

.. currentmodule:: mscxyz

.. autofunction:: list_path
2 changes: 1 addition & 1 deletion mscxyz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

Score = mscxyz.score.Score

list_files = utils.list_files
list_path = utils.list_path
2 changes: 1 addition & 1 deletion mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def list_styles(version: int) -> None:
elif args.selection_mscx:
selection_glob = "*.mscx"

for file in utils.list_files(src=args.path, glob=selection_glob):
for file in utils.list_path(src=args.path, glob=selection_glob):
try:
if args.selection_list:
print(file)
Expand Down
8 changes: 4 additions & 4 deletions mscxyz/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _get_checksum(filename: str) -> str:
return hasher.hexdigest()


def rename(score: Score) -> Score:
def rename(score: Score) -> None:
args = get_args()

meta_values = score.fields.export_to_dict()
Expand All @@ -76,7 +76,7 @@ def rename(score: Score) -> Score:
for skip in skips:
if skip not in meta_values:
print(colorize("Field “{}” is empty! Skipping".format(skip), "red"))
return score
return

if args.rename_target:
target_base: str = os.path.abspath(args.rename_target)
Expand All @@ -101,7 +101,7 @@ def rename(score: Score) -> Score:
"red",
)
)
return score
return
if i == 1:
counter_format = ""
else:
Expand All @@ -118,4 +118,4 @@ def rename(score: Score) -> Score:
# os.rename(source, target)
shutil.move(score.path, target)

return score
return
2 changes: 1 addition & 1 deletion mscxyz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
INCH = 25.4


def list_files(
def list_path(
src: PathOrStr | list[PathOrStr],
extension: ListExtension = "both",
glob: Optional[str] = None,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from mscxyz import (
Score,
list_files,
list_path,
)


Expand All @@ -13,4 +13,4 @@ def test_class_score() -> None:


def test_function_list_scores() -> None:
assert list_files.__name__ == "list_files"
assert list_path.__name__ == "list_path"
6 changes: 3 additions & 3 deletions tests/test_how_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from mscxyz import Score, list_files
from mscxyz import Score, list_path
from tests import helper
from tests.helper import Cli, assert_file_type

Expand Down Expand Up @@ -94,9 +94,9 @@ def test_dont_mix_mscx_and_glob(self) -> None:
)


def test_list_files(nested_dir: Path) -> None:
def test_list_path(nested_dir: Path) -> None:
score_paths: list[str] = []
for score_path in list_files(src=str(nested_dir), extension="mscz"):
for score_path in list_path(src=str(nested_dir), extension="mscz"):
score = Score(score_path)
assert score.path.exists()
assert score.extension == "mscz"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _list_scores(
("/a/b", (), ("impsum.mscz", "dolor.mscx", "sit.txt")),
]
scores: list[str] = []
for score in utils.list_files(path, extension, glob):
for score in utils.list_path(path, extension, glob):
scores.append(str(score))
scores.sort()
return scores
Expand Down Expand Up @@ -65,13 +65,13 @@ def test_raises_exception(self) -> None:
def test_isfile(self) -> None:
with mock.patch("pathlib.Path.is_file") as mock_isfile:
mock_isfile.return_value = True
result = list(utils.list_files("/a/b/lorem.mscx"))
result = list(utils.list_path("/a/b/lorem.mscx"))
assert str(result[0]) == "/a/b/lorem.mscx"

def test_isfile_no_match(self) -> None:
with mock.patch("pathlib.Path.is_file") as mock_isfile:
mock_isfile.return_value = True
result = list(utils.list_files("/a/b/lorem.lol"))
result = list(utils.list_path("/a/b/lorem.lol"))
assert result == []

def test_arg_glob_txt(self) -> None:
Expand Down

0 comments on commit ad0a181

Please sign in to comment.