beets/test/rsrc/convert_stub.py
Arav K. 0b10d84862 Explicitly use Python 3 for scripts
While Python 2 is long dead, and a 'bin/env python' shebang is probably
perfectly fine, this is just a bit safer.

See <https://github.com/beetbox/beets/issues/4604>.
2024-06-14 14:44:29 +02:00

31 lines
709 B
Python
Executable file

#!/usr/bin/env python3
"""A tiny tool used to test the `convert` plugin. It copies a file and appends
a specified text tag.
"""
import locale
import sys
# From `beets.util`.
def arg_encoding():
try:
return locale.getdefaultlocale()[1] or "utf-8"
except ValueError:
return "utf-8"
def convert(in_file, out_file, tag):
"""Copy `in_file` to `out_file` and append the string `tag`."""
if not isinstance(tag, bytes):
tag = tag.encode("utf-8")
with open(out_file, "wb") as out_f:
with open(in_file, "rb") as in_f:
out_f.write(in_f.read())
out_f.write(tag)
if __name__ == "__main__":
convert(sys.argv[1], sys.argv[2], sys.argv[3])