Разработана утилита для многопоточного сжатия файлов WebAssembly
This commit is contained in:
2
config/__init__.py
Normal file
2
config/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .main import Main, Input, Output, Backup
|
||||
from .models import Algorithm
|
13
config/levels.py
Normal file
13
config/levels.py
Normal file
@ -0,0 +1,13 @@
|
||||
from logging import CRITICAL, FATAL, ERROR, WARNING, INFO, DEBUG, NOTSET
|
||||
|
||||
|
||||
levels = {
|
||||
'CRITICAL': CRITICAL,
|
||||
'FATAL': FATAL,
|
||||
'ERROR': ERROR,
|
||||
'WARN': WARNING,
|
||||
'WARNING': WARNING,
|
||||
'INFO': INFO,
|
||||
'DEBUG': DEBUG,
|
||||
'NOTSET': NOTSET,
|
||||
}
|
186
config/main.py
Normal file
186
config/main.py
Normal file
@ -0,0 +1,186 @@
|
||||
import configparser
|
||||
from pathlib import PurePath
|
||||
from typing import Callable
|
||||
|
||||
from .levels import levels
|
||||
from .models import Algorithm
|
||||
|
||||
|
||||
config = configparser.RawConfigParser()
|
||||
config.read(
|
||||
filenames='./config.ini',
|
||||
encoding='utf-8',
|
||||
)
|
||||
|
||||
|
||||
class Main:
|
||||
base_path = PurePath(config.get(
|
||||
section='Main',
|
||||
option='base_path',
|
||||
))
|
||||
max_threads = config.getint(
|
||||
section='Main',
|
||||
option='max_threads',
|
||||
fallback=4,
|
||||
)
|
||||
log_level = levels.get(
|
||||
config.get(
|
||||
section='Main',
|
||||
option='log_level',
|
||||
fallback='info',
|
||||
).upper()
|
||||
)
|
||||
|
||||
|
||||
class Input:
|
||||
path = PurePath(config.get(
|
||||
section='Input',
|
||||
option='path',
|
||||
))
|
||||
|
||||
|
||||
class Output:
|
||||
path = PurePath(config.get(
|
||||
section='Output',
|
||||
option='path',
|
||||
))
|
||||
dir_mode = int(config.get(
|
||||
section='Output',
|
||||
option='dir_mode',
|
||||
fallback='755',
|
||||
), 8)
|
||||
file_mode = int(config.get(
|
||||
section='Output',
|
||||
option='file_mode',
|
||||
fallback='644',
|
||||
), 8)
|
||||
|
||||
class Wasm:
|
||||
class Source:
|
||||
enabled = config.getboolean(
|
||||
section='Output.Wasm.Source',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Output.Wasm.Source',
|
||||
option='path',
|
||||
fallback=PurePath('.', 'wasm', 'src'),
|
||||
))
|
||||
|
||||
class Brotli(Algorithm):
|
||||
compress: Callable
|
||||
|
||||
name = 'Brotli'
|
||||
enabled = config.getboolean(
|
||||
section='Output.Wasm.Brotli',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Output.Wasm.Brotli',
|
||||
option='path',
|
||||
fallback=PurePath('.', 'wasm', 'br'),
|
||||
))
|
||||
level = config.getint(
|
||||
section='Output.Wasm.Brotli',
|
||||
option='level',
|
||||
fallback=11,
|
||||
)
|
||||
|
||||
class Zstandard(Algorithm):
|
||||
compress: Callable
|
||||
|
||||
name = 'Zstandard'
|
||||
enabled = config.getboolean(
|
||||
section='Output.Wasm.Zstandard',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Output.Wasm.Zstandard',
|
||||
option='path',
|
||||
fallback=PurePath('.', 'wasm', 'zstd'),
|
||||
))
|
||||
level = config.getint(
|
||||
section='Output.Wasm.Zstandard',
|
||||
option='level',
|
||||
fallback=22,
|
||||
)
|
||||
|
||||
class Gzip(Algorithm):
|
||||
compress: Callable
|
||||
|
||||
name = 'Gzip'
|
||||
enabled = config.getboolean(
|
||||
section='Output.Wasm.Gzip',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Output.Wasm.Gzip',
|
||||
option='path',
|
||||
fallback=PurePath('.', 'wasm', 'gzip'),
|
||||
))
|
||||
level = config.getint(
|
||||
section='Output.Wasm.Gzip',
|
||||
option='level',
|
||||
fallback=9,
|
||||
)
|
||||
|
||||
class Deflate(Algorithm):
|
||||
compress: Callable
|
||||
|
||||
name = 'Deflate'
|
||||
enabled = config.getboolean(
|
||||
section='Output.Wasm.Deflate',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Output.Wasm.Deflate',
|
||||
option='path',
|
||||
fallback=PurePath('.', 'wasm', 'deflate'),
|
||||
))
|
||||
level = config.getint(
|
||||
section='Output.Wasm.Deflate',
|
||||
option='level',
|
||||
fallback=9,
|
||||
)
|
||||
|
||||
class Other:
|
||||
enabled = config.getboolean(
|
||||
section='Output.Other',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Output.Other',
|
||||
option='path',
|
||||
fallback=PurePath('.'),
|
||||
))
|
||||
|
||||
|
||||
class Backup:
|
||||
enabled = config.getboolean(
|
||||
section='Backup',
|
||||
option='enabled',
|
||||
fallback=True,
|
||||
)
|
||||
path = PurePath(config.get(
|
||||
section='Backup',
|
||||
option='path',
|
||||
fallback=PurePath(Main.base_path, 'backup'),
|
||||
))
|
||||
|
||||
|
||||
Input.path = Main.base_path / Input.path
|
||||
Output.path = Main.base_path / Output.path
|
||||
Backup.path = Main.base_path / Backup.path
|
||||
|
||||
Output.Wasm.Source.path = Output.path / Output.Wasm.Source.path
|
||||
Output.Wasm.Brotli.path = Output.path / Output.Wasm.Brotli.path
|
||||
Output.Wasm.Zstandard.path = Output.path / Output.Wasm.Zstandard.path
|
||||
Output.Wasm.Gzip.path = Output.path / Output.Wasm.Gzip.path
|
||||
Output.Wasm.Deflate.path = Output.path / Output.Wasm.Deflate.path
|
||||
Output.Other.path = Output.path / Output.Other.path
|
13
config/models.py
Normal file
13
config/models.py
Normal file
@ -0,0 +1,13 @@
|
||||
from pathlib import PurePath
|
||||
from typing import Callable, Type
|
||||
|
||||
|
||||
class BaseAlgorithm:
|
||||
compress: Callable
|
||||
name: str
|
||||
enabled: bool
|
||||
path: PurePath
|
||||
level: int
|
||||
|
||||
|
||||
Algorithm = Type[BaseAlgorithm]
|
Reference in New Issue
Block a user