Skip to content

Commit

Permalink
Readd some options to the ng-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 17, 2024
1 parent a946415 commit 8a76ffd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 26 deletions.
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ CLI Usage
[-k] [-C GENERAL_CONFIG_FILE] [-d] [-m] [--diff]
[-e FILE_PATH] [-v] [-E <extension>] [-c META_CLEAN]
[-D] [-i <source-fields> <format-string>] [-j]
[-l DESTINATION FORMAT_STRING] [-y]
[-l <log-file> <format-string>] [-y]
[-S DESTINATION_FIELD FORMAT_STRING]
[--metatag <field> <value>] [--vbox <field> <value>]
[--combined <field> <value>] [-x LYRICS_EXTRACT]
Expand Down Expand Up @@ -403,8 +403,10 @@ CLI Usage
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.
-j, --json Additionally write the meta data to a json file.
-l DESTINATION FORMAT_STRING, --log DESTINATION FORMAT_STRING
-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-file> <format-string>, --log <log-file> <format-string>
Write one line per file to a text file. e. g. --log
/tmp/musescore-manager.log '$title $composer'
-y, --synchronize Synchronize the values of the first vertical frame (vbox)
Expand Down
2 changes: 1 addition & 1 deletion autocomplete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _shtab_musescore_manager_options=(
{-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}"[Additionally write the meta data to a json file.]"
{-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:"
Expand Down
8 changes: 5 additions & 3 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Comande line interface
[-k] [-C GENERAL_CONFIG_FILE] [-d] [-m] [--diff]
[-e FILE_PATH] [-v] [-E <extension>] [-c META_CLEAN]
[-D] [-i <source-fields> <format-string>] [-j]
[-l DESTINATION FORMAT_STRING] [-y]
[-l <log-file> <format-string>] [-y]
[-S DESTINATION_FIELD FORMAT_STRING]
[--metatag <field> <value>] [--vbox <field> <value>]
[--combined <field> <value>] [-x LYRICS_EXTRACT]
Expand Down Expand Up @@ -167,8 +167,10 @@ Comande line interface
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.
-j, --json Additionally write the meta data to a json file.
-l DESTINATION FORMAT_STRING, --log DESTINATION FORMAT_STRING
-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-file> <format-string>, --log <log-file> <format-string>
Write one line per file to a text file. e. g. --log
/tmp/musescore-manager.log '$title $composer'
-y, --synchronize Synchronize the values of the first vertical frame (vbox)
Expand Down
19 changes: 10 additions & 9 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,15 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:
"--json",
action="store_true",
dest="meta_json",
help="Additionally write the meta data to a json file.",
help="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”.",
)

group_meta.add_argument(
"-l",
"--log",
nargs=2,
metavar=("DESTINATION", "FORMAT_STRING"),
metavar=("<log-file>", "<format-string>"),
dest="meta_log",
help="Write one line per file to a text file. e. g. --log "
"/tmp/musescore-manager.log '$title $composer'",
Expand Down Expand Up @@ -815,8 +816,9 @@ def list_styles(version: int) -> None:
if args.meta_clean:
score.meta.clean_metadata(fields_spec=args.meta_clean)

# if args.meta_json:
# score.meta.export_json()
if args.meta_json:
score.meta.export_json()

if args.meta_dist:
for a in args.meta_dist:
score.meta.distribute_field(source_fields=a[0], format_string=a[1])
Expand All @@ -826,14 +828,13 @@ def list_styles(version: int) -> None:

if args.meta_sync:
score.meta.sync_fields()
# if args.meta_log:
# score.meta.write_to_log_file(args.meta_log[0], args.meta_log[1])

if args.meta_log:
score.meta.write_to_log_file(args.meta_log[0], args.meta_log[1])

# post: dict[str, str] = score.meta.interface.export_to_dict()
# score.meta.show(pre, post)

# if not args.general_dry_run and not score.errors and pre != post:
# score.save(mscore=args.general_mscore)

if args.rename_rename:
rename(score)

Expand Down
2 changes: 1 addition & 1 deletion mscxyz/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def export_json(self) -> Path:
:return: The path to the exported JSON file.
"""
data: dict[str, str] = {}
result_path: Path = self.score.change_path(extension="json")
result_path: Path = self.score.json_file
for field in self.interface.fields:
data[field] = self.interface.__getattr__(field)
output = open(result_path, "w")
Expand Down
6 changes: 6 additions & 0 deletions mscxyz/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,14 @@ def version_major(self) -> int:

@property
def backup_file(self) -> Path:
"""The path of the backup file."""
return self.change_path(suffix="bak")

@property
def json_file(self) -> Path:
"""The path of the JSON file in which the metadata is saved."""
return self.change_path(extension="json")

@property
def dirname(self) -> str:
"""The name of the containing directory of the MuseScore file, for
Expand Down
41 changes: 32 additions & 9 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import os
import tempfile
from pathlib import Path

import pytest
Expand Down Expand Up @@ -945,14 +944,19 @@ def test_with_templating(self) -> None:
assert c.post.meta.interface.vbox_title == "vbox_title (vbox_composer)"


def test_log() -> None:
tmp = helper.get_score("simple.mscx")
log = tempfile.mktemp()
Cli(
"meta", "--log", log, "$combined_title-$combined_composer", tmp, legacy=True
).execute()
log_file = open(log, "r")
assert log_file.readline() == "Title-Composer\n"
class TestOptionLog:
@pytest.mark.legacy
def test_log_legacy(self, tmp_path: Path) -> None:
log = tmp_path / "log.txt"
Cli(
"meta", "--log", log, "$combined_title-$combined_composer", legacy=True
).execute()
assert open(log, "r").readline() == "Title-Composer\n"

def test_log(self, tmp_path: Path) -> None:
log = tmp_path / "log.txt"
Cli("--log", log, "$combined_title-$combined_composer").execute()
assert open(log, "r").readline() == "Title-Composer\n"


class TestOptionDeleteDuplicates:
Expand Down Expand Up @@ -1058,6 +1062,25 @@ def test_option_synchronize() -> None:
assert post.vbox.lyricist == post.metatag.lyricist == "metatag_lyricist"


class TestOptionJson:
@pytest.mark.legacy
def test_legacy(self):
score = (
Cli("meta", "--json", legacy=True)
.append_score("meta-all-values.mscz")
.execute()
).score()
json = score.json_file
assert json.exists()
assert '"readonly_basename": "meta-all-values"' in helper.read_file(json)

def test_json(self):
score = (Cli("--json").append_score("meta-all-values.mscz").execute()).score()
json = score.json_file
assert json.exists()
assert '"readonly_basename": "meta-all-values"' in helper.read_file(json)


class TestClassMeta:
meta: Meta

Expand Down

0 comments on commit 8a76ffd

Please sign in to comment.