This commit is contained in:
Jamie Hardt
2024-07-01 21:04:50 -07:00
parent 12ad66e327
commit 35480978e4
4 changed files with 55 additions and 62 deletions

View File

@@ -17,6 +17,7 @@ from mfbatch.commands import BatchfileParser
from tqdm import tqdm from tqdm import tqdm
# import readline # import readline
def execute_batch_list(batch_list_path: str, dry_run: bool, interactive: bool): def execute_batch_list(batch_list_path: str, dry_run: bool, interactive: bool):
with open(batch_list_path, mode='r') as f: with open(batch_list_path, mode='r') as f:
parser = BatchfileParser() parser = BatchfileParser()
@@ -127,5 +128,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -21,6 +21,7 @@ class UnrecognizedCommandError(Exception):
self.command = command self.command = command
self.line = line self.line = line
class CommandArgumentError(Exception): class CommandArgumentError(Exception):
command: str command: str
line: int line: int
@@ -110,12 +111,11 @@ they appear in the batchfile.
COMMAND_LEADER = ':' COMMAND_LEADER = ':'
COMMENT_LEADER = '#' COMMENT_LEADER = '#'
def __init__(self): def __init__(self):
self.dry_run = True self.dry_run = True
self.env = CommandEnv() self.env = CommandEnv()
def _handle_line(self, line:str, lineno: int, interactive: bool): def _handle_line(self, line: str, lineno: int, interactive: bool):
if line.startswith(self.COMMAND_LEADER): if line.startswith(self.COMMAND_LEADER):
self._handle_command(line.lstrip(self.COMMAND_LEADER), lineno) self._handle_command(line.lstrip(self.COMMAND_LEADER), lineno)
elif line.startswith(self.COMMENT_LEADER): elif line.startswith(self.COMMENT_LEADER):
@@ -125,7 +125,7 @@ they appear in the batchfile.
def _handle_command(self, line, lineno): def _handle_command(self, line, lineno):
args = shlex.split(line) args = shlex.split(line)
actions = [member for member in dir(self) \ actions = [member for member in dir(self)
if not member.startswith('_')] if not member.startswith('_')]
if args[0] in actions: if args[0] in actions:
@@ -158,8 +158,8 @@ they appear in the batchfile.
value = self.env.metadatums[key] value = self.env.metadatums[key]
LINE_LEN = int(shutil.get_terminal_size()[0]) - 32 LINE_LEN = int(shutil.get_terminal_size()[0]) - 32
value_lines = [value[i:i+LINE_LEN] for i in \ value_lines = [value[i:i+LINE_LEN] for i in
range(0,len(value), LINE_LEN)] range(0, len(value), LINE_LEN)]
for l in value_lines: for l in value_lines:
if key: if key:
@@ -273,7 +273,7 @@ they appear in the batchfile.
inp = args[1] inp = args[1]
pattern = args[2] pattern = args[2]
repl = args[3] repl = args[3]
self.env.set_pattern(key,inp,pattern, repl) self.env.set_pattern(key, inp, pattern, repl)
def d(self, args): def d(self, args):
""" """
@@ -282,7 +282,3 @@ they appear in the batchfile.
""" """
val = args[0] val = args[0]
self.env.set_once('DESCRIPTION', val) self.env.set_once('DESCRIPTION', val)

View File

@@ -34,7 +34,7 @@ def sanatize_value(v: str) -> str:
newlines, which are not supported by this tool. newlines, which are not supported by this tool.
""" """
return v.translate(str.maketrans('\n',' ')) return v.translate(str.maketrans('\n', ' '))
def read_metadata(path: str, metaflac_path=METAFLAC_PATH) -> FlacMetadata: def read_metadata(path: str, metaflac_path=METAFLAC_PATH) -> FlacMetadata:
@@ -69,4 +69,3 @@ def write_metadata(path: str, data: FlacMetadata,
insert_job = run([metaflac_path, "--import-tags-from=-", path], insert_job = run([metaflac_path, "--import-tags-from=-", path],
input=metadatum_f.encode('utf-8')) input=metadatum_f.encode('utf-8'))
insert_job.check_returncode() insert_job.check_returncode()

View File

@@ -19,4 +19,3 @@ def readline_with_escaped_newlines(f):
else: else:
yield line, line_no yield line, line_no
line = '' line = ''