Skip to content

Commit

Permalink
Delete unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 27, 2024
1 parent c29c35d commit a46cacb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 40 deletions.
11 changes: 0 additions & 11 deletions mscxyz/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import re
import typing

import tmep
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions mscxyz/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
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:
if exception.errno != errno.EEXIST:
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():
Expand All @@ -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:
Expand All @@ -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(",")
Expand All @@ -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) "
Expand All @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions mscxyz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 0 additions & 5 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Metatag,
Vbox,
export_to_dict,
to_underscore,
)
from mscxyz.score import Score
from tests import helper
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Expand Down

0 comments on commit a46cacb

Please sign in to comment.