From a46cacbf34ea303e511b9a09c83a942d2f7018f0 Mon Sep 17 00:00:00 2001 From: Josef Friedrich Date: Sat, 27 Jan 2024 18:17:03 +0100 Subject: [PATCH] Delete unused functions --- mscxyz/meta.py | 11 ----------- mscxyz/rename.py | 20 ++++++++++---------- mscxyz/utils.py | 11 ----------- tests/test_meta.py | 5 ----- tests/test_rename.py | 6 +++--- 5 files changed, 13 insertions(+), 40 deletions(-) diff --git a/mscxyz/meta.py b/mscxyz/meta.py index e38d0ec..93c9b2c 100644 --- a/mscxyz/meta.py +++ b/mscxyz/meta.py @@ -2,7 +2,6 @@ from __future__ import annotations -import re import typing import tmep @@ -41,16 +40,6 @@ def __init__(self, format_string: str) -> None: Exception.__init__(self, self.msg) -def to_underscore(field: str) -> str: - """ - Convert a camel case string to snake case. - - :param field: The camel case string to be converted. - :return: The snake case representation of the input string. - """ - return re.sub("([A-Z]+)", r"_\1", field).lower() - - def export_to_dict(obj: object, fields: typing.Iterable[str]) -> dict[str, str]: """ Export the specified fields of an object to a dictionary. diff --git a/mscxyz/rename.py b/mscxyz/rename.py index f5bfef3..d85035c 100644 --- a/mscxyz/rename.py +++ b/mscxyz/rename.py @@ -16,7 +16,7 @@ from mscxyz.utils import colorize -def create_dir(path: str) -> None: +def _create_dir(path: str) -> None: try: os.makedirs(os.path.dirname(path)) except OSError as exception: @@ -24,7 +24,7 @@ def create_dir(path: str) -> None: raise -def prepare_fields(fields: FieldsExport) -> dict[str, str]: +def _prepare_fields(fields: FieldsExport) -> dict[str, str]: args = get_args() output: dict[str, str] = {} for field, value in fields.items(): @@ -43,18 +43,18 @@ def prepare_fields(fields: FieldsExport) -> dict[str, str]: return output -def apply_format_string(fields: FieldsExport) -> str: +def _apply_format_string(fields: FieldsExport) -> str: args = get_args() - fields = prepare_fields(fields) + fields = _prepare_fields(fields) name = tmep.parse(args.rename_format, fields) return name -def show(old: str, new: str) -> None: +def _show(old: str, new: str) -> None: print("{} -> {}".format(colorize(old, "yellow"), colorize(new, "green"))) -def get_checksum(filename: str) -> str: +def _get_checksum(filename: str) -> str: BLOCKSIZE = 65536 hasher = hashlib.sha1() with open(filename, "rb") as afile: @@ -69,7 +69,7 @@ def rename(score: Score) -> Score: args = get_args() meta_values = score.fields.export_to_dict() - target_filename: str = apply_format_string(meta_values) + target_filename: str = _apply_format_string(meta_values) if args.rename_skip: skips: list[str] = args.rename_skip.split(",") @@ -91,7 +91,7 @@ def rename(score: Score) -> Score: counter_format: str = "" while os.path.exists(target_format.format(counter_format)): target = target_format.format(counter_format) - if get_checksum(str(score.path)) == get_checksum(target): + if _get_checksum(str(score.path)) == _get_checksum(target): print( colorize( "The file “{}” with the same checksum (sha1) " @@ -110,10 +110,10 @@ def rename(score: Score) -> Score: target = target_format.format(counter_format) - show(str(score.path), target) + _show(str(score.path), target) if not args.general_dry_run: - create_dir(target) + _create_dir(target) # Invalid cross-device link: # os.rename(source, target) shutil.move(score.path, target) diff --git a/mscxyz/utils.py b/mscxyz/utils.py index 0e28acf..76fb495 100644 --- a/mscxyz/utils.py +++ b/mscxyz/utils.py @@ -127,17 +127,6 @@ def re_open(input_file: str) -> None: execute_musescore(["-o", input_file, input_file]) -def convert_mxl(input_file: str) -> None: - """ - Convert a MusicXML file into a MuseScore file. - - :param input_file: The path (relative or absolute) of a MusicXML file. - """ - output_file = input_file.replace(".mxl", ".mscx") - execute_musescore(["-o", output_file, input_file]) - os.remove(input_file) - - def round_float(value: str | int | float) -> float: return float(round(float(value), 4)) diff --git a/tests/test_meta.py b/tests/test_meta.py index 71802f7..feb18c4 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -12,7 +12,6 @@ Metatag, Vbox, export_to_dict, - to_underscore, ) from mscxyz.score import Score from tests import helper @@ -49,10 +48,6 @@ def test_format_string_no_field_error(self) -> None: class TestFunctions: - def test_to_underscore(self) -> None: - assert to_underscore("PascalCase") == "_pascal_case" - assert to_underscore("lowerCamelCase") == "lower_camel_case" - def test_export_to_dict(self) -> None: class Data: a = "a" diff --git a/tests/test_rename.py b/tests/test_rename.py index fbf4616..16c37e3 100644 --- a/tests/test_rename.py +++ b/tests/test_rename.py @@ -18,7 +18,7 @@ def test_function_prepare_fields(self) -> None: "field1": " Subtitle ", "field2": "Title / Composer", } - result: dict[str, str] = rename.prepare_fields(fields) + result: dict[str, str] = rename._prepare_fields(fields) assert result == { "field1": "Subtitle", "field2": "Title - Composer", @@ -28,12 +28,12 @@ def test_function_apply_format_string(self) -> None: reset_args() score = get_score("meta-all-values.mscx") fields = score.fields.export_to_dict() - name: str = rename.apply_format_string(fields) + name: str = rename._apply_format_string(fields) assert name == "vbox_title (vbox_composer)" def test_function_get_checksum(self) -> None: tmp: str = get_file("simple.mscx") - assert rename.get_checksum(tmp) == "dacd912aa0f6a1a67c3b13bb947395509e19dce2" + assert rename._get_checksum(tmp) == "dacd912aa0f6a1a67c3b13bb947395509e19dce2" class TestCli: