Add black code formatter
This commit is contained in:
parent
749750fbb7
commit
0fd3bbaad9
11
Taskfile.yml
Normal file
11
Taskfile.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# https://taskfile.dev
|
||||||
|
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
vars:
|
||||||
|
GREETING: Hello, World!
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
format:
|
||||||
|
cmds:
|
||||||
|
- docker run --rm --volume $(pwd):/src --workdir /src pyfound/black:25.1.0 black .
|
@ -4,10 +4,10 @@ import sys
|
|||||||
|
|
||||||
def convert_encoding(filepath):
|
def convert_encoding(filepath):
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'r', encoding='cp1251', errors='strict') as f:
|
with open(filepath, "r", encoding="cp1251", errors="strict") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
with open(filepath, 'w', encoding='utf-8', errors='strict') as f:
|
with open(filepath, "w", encoding="utf-8", errors="strict") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
print(f"Success: {filepath}")
|
print(f"Success: {filepath}")
|
||||||
@ -25,9 +25,10 @@ def process_directory(root_dir):
|
|||||||
|
|
||||||
for root, _, files in os.walk(root_dir):
|
for root, _, files in os.walk(root_dir):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith(('.cue', '.log')):
|
if file.endswith((".cue", ".log")):
|
||||||
file_path = os.path.join(root, file)
|
file_path = os.path.join(root, file)
|
||||||
convert_encoding(file_path)
|
convert_encoding(file_path)
|
||||||
|
|
||||||
|
|
||||||
def execute(args):
|
def execute(args):
|
||||||
process_directory(args.directory)
|
process_directory(args.directory)
|
@ -6,14 +6,12 @@ import convert_file_encoding
|
|||||||
|
|
||||||
def create_convert_parser(subparsers):
|
def create_convert_parser(subparsers):
|
||||||
parser = subparsers.add_parser(
|
parser = subparsers.add_parser(
|
||||||
'convert',
|
"convert",
|
||||||
description='Recursively convert .cue and .log files from cp1251 to utf-8',
|
description="Recursively convert .cue and .log files from cp1251 to utf-8",
|
||||||
epilog='Example: python convert_encoding.py /path/to/directory'
|
epilog="Example: python convert_encoding.py /path/to/directory",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'directory',
|
"directory", type=str, help="Path to target directory for conversion"
|
||||||
type=str,
|
|
||||||
help='Path to target directory for conversion'
|
|
||||||
)
|
)
|
||||||
parser.set_defaults(func=convert_file_encoding.execute)
|
parser.set_defaults(func=convert_file_encoding.execute)
|
||||||
|
|
||||||
@ -26,4 +24,3 @@ if __name__ == "__main__":
|
|||||||
args = top_parser.parse_args()
|
args = top_parser.parse_args()
|
||||||
print(args)
|
print(args)
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user